summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBenoit Giannangeli <giann008@gmail.com>2017-03-24 10:57:49 +0100
committerBenoit Giannangeli <giann008@gmail.com>2017-03-24 10:59:27 +0100
commita6fa99b44b6d536a1fb23f9ffd7a84786c63edab (patch)
tree6e44f116dc2e072a4a54cc5a8af9cc194d5e0d08 /tests
parenteafdbc018fbeeec088b82172ff59a413558e92e7 (diff)
downloadfengari-a6fa99b44b6d536a1fb23f9ffd7a84786c63edab.tar.gz
fengari-a6fa99b44b6d536a1fb23f9ffd7a84786c63edab.tar.bz2
fengari-a6fa99b44b6d536a1fb23f9ffd7a84786c63edab.zip
string.char bypass to_luastring conversion
Diffstat (limited to 'tests')
-rw-r--r--tests/single.lua22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/single.lua b/tests/single.lua
index 616e2a4..c52a6fb 100644
--- a/tests/single.lua
+++ b/tests/single.lua
@@ -71,3 +71,25 @@ assert(string.len("1234567890") == 10)
assert(#"" == 0)
assert(#"\0\0\0" == 3)
assert(#"1234567890" == 10)
+
+-- testing string.byte/string.char
+assert(string.byte("a") == 97)
+assert(string.byte("\xe4") > 127)
+assert(string.byte(string.char(255)) == 255)
+assert(string.byte(string.char(0)) == 0)
+assert(string.byte("\0") == 0)
+assert(string.byte("\0\0alo\0x", -1) == string.byte('x'))
+assert(string.byte("ba", 2) == 97)
+assert(string.byte("\n\n", 2, -1) == 10)
+assert(string.byte("\n\n", 2, 2) == 10)
+assert(string.byte("") == nil)
+assert(string.byte("hi", -3) == nil)
+assert(string.byte("hi", 3) == nil)
+assert(string.byte("hi", 9, 10) == nil)
+assert(string.byte("hi", 2, 1) == nil)
+assert(string.char() == "")
+assert(string.char(0, 255, 0) == "\0\255\0")
+assert(string.char(0, string.byte("\xe4"), 0) == "\0\xe4\0")
+assert(string.char(string.byte("\xe4l\0óu", 1, -1)) == "\xe4l\0óu")
+assert(string.char(string.byte("\xe4l\0óu", 1, 0)) == "")
+assert(string.char(string.byte("\xe4l\0óu", -10, 100)) == "\xe4l\0óu")