Skip to content

Commit

Permalink
Fix #13: Pass byte count to make_string
Browse files Browse the repository at this point in the history
  • Loading branch information
leoliu authored and SavchenkoValeriy committed May 30, 2023
1 parent 1ad55f2 commit c776706
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Source/Swift/Conversion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ extension Environment {
//
func make(_ from: String) throws -> EmacsValue {
EmacsValue(
from: try check(pointee.make_string(raw, from, from.count)))
from: try check(pointee.make_string(raw, from, from.utf8.count)))
}
func make(_ from: Int) throws -> EmacsValue {
EmacsValue(from: try check(pointee.make_integer(raw, from)))
Expand Down
7 changes: 4 additions & 3 deletions test/TestModule/Test.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class TestModule: Module {
try env.defun("swift-int") { (arg: Int) in arg * 2 }
try env.defun("swift-float") { (arg: Double) in arg * 2 }
try env.defun("swift-bool") { (arg: Bool) in !arg }
try env.defun("swift-string") { (arg: String) in arg }
try env.defun("swift-call") {
(env: Environment, arg: String) throws in
return try env.funcall("format", with: "'%s'", arg)
Expand Down Expand Up @@ -183,9 +184,9 @@ class TestModule: Module {
async let a: Int = channel.withAsyncEnvironment {
env in try env.funcall("+", with: x, 42)
}
async let b: Int = channel.withAsyncEnvironment {
env in try env.funcall("*", with: x, 2)
}
async let b: Int = channel.withAsyncEnvironment {
env in try env.funcall("*", with: x, 2)
}
let result = try await a - b
channel.withEnvironment {
env in try env.funcall(callback, with: result)
Expand Down
6 changes: 5 additions & 1 deletion test/swift-module-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
(should (eq (swift-int 10) 20))
(should (< (abs (- 21.0 (swift-float 10.5))) 1e-6))
(should (swift-bool nil))
(should (not (swift-bool t))))
(should (not (swift-bool t)))
(let ((s1 "I uncover the soul-destroying abhorrence")
(s2 "Ξεσκεπάζω τὴν ψυχοφθόρα βδελυγμία"))
(should (string= s1 (swift-string s1)))
(should (string= s2 (swift-string s2)))))

(ert-deftest swift-module:check-incorrect-num-of-args ()
:tags '(emacs-all)
Expand Down

0 comments on commit c776706

Please sign in to comment.