-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix read/writeString and add test (#243)
- Loading branch information
Showing
6 changed files
with
83 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
local ffi = require("@lune/ffi") | ||
local ok | ||
|
||
local str = "hello world" | ||
local strbox = ffi.box(#str):writeString(str) | ||
assert(strbox:readString(#str) == str, "String read write assersion failed") | ||
|
||
-- Case1: Fail | ||
ok = pcall(function() | ||
local box = ffi.box(2) | ||
box:readString(10) | ||
end) | ||
assert(not ok, "assersion failed, Case1 should fail") | ||
|
||
-- Case2: Fail | ||
ok = pcall(function() | ||
local box = ffi.box(2) | ||
box:writeString("hello world") | ||
end) | ||
assert(not ok, "assersion failed, Case2 should fail") | ||
|
||
-- Case3: Fail | ||
ok = pcall(function() | ||
local box = ffi.box(2):ref() | ||
box:readString(10) | ||
end) | ||
assert(not ok, "assersion failed, Case3 should fail") | ||
|
||
-- Case4: Fail | ||
ok = pcall(function() | ||
local box = ffi.box(2):ref() | ||
box:writeString("hello world") | ||
end) | ||
assert(not ok, "assersion failed, Case4 should fail") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters