summaryrefslogtreecommitdiff
path: root/tests/single.lua
diff options
context:
space:
mode:
authorBenoit Giannangeli <giann008@gmail.com>2017-03-23 15:46:09 +0100
committerBenoit Giannangeli <giann008@gmail.com>2017-03-24 07:05:47 +0100
commitd3530bdc202419c85ec79fdb01197112cab8a788 (patch)
treef83dd6abe1a539a5085320d071ee4934950fb87b /tests/single.lua
parent4dc92d3e554278192c2979dd3d81942ca24f15b6 (diff)
downloadfengari-d3530bdc202419c85ec79fdb01197112cab8a788.tar.gz
fengari-d3530bdc202419c85ec79fdb01197112cab8a788.tar.bz2
fengari-d3530bdc202419c85ec79fdb01197112cab8a788.zip
strings.lua
Diffstat (limited to 'tests/single.lua')
-rw-r--r--tests/single.lua73
1 files changed, 73 insertions, 0 deletions
diff --git a/tests/single.lua b/tests/single.lua
new file mode 100644
index 0000000..616e2a4
--- /dev/null
+++ b/tests/single.lua
@@ -0,0 +1,73 @@
+-- $Id: strings.lua,v 1.86 2016/11/07 13:11:28 roberto Exp roberto $
+-- See Copyright Notice in file all.lua
+
+print('testing strings and string library')
+
+local maxi, mini = math.maxinteger, math.mininteger
+
+
+local function checkerror (msg, f, ...)
+ local s, err = pcall(f, ...)
+ assert(not s and string.find(err, msg))
+end
+
+
+-- testing string comparisons
+assert('alo' < 'alo1')
+assert('' < 'a')
+assert('alo\0alo' < 'alo\0b')
+assert('alo\0alo\0\0' > 'alo\0alo\0')
+assert('alo' < 'alo\0')
+assert('alo\0' > 'alo')
+assert('\0' < '\1')
+assert('\0\0' < '\0\1')
+assert('\1\0a\0a' <= '\1\0a\0a')
+assert(not ('\1\0a\0b' <= '\1\0a\0a'))
+assert('\0\0\0' < '\0\0\0\0')
+assert(not('\0\0\0\0' < '\0\0\0'))
+assert('\0\0\0' <= '\0\0\0\0')
+assert(not('\0\0\0\0' <= '\0\0\0'))
+assert('\0\0\0' <= '\0\0\0')
+assert('\0\0\0' >= '\0\0\0')
+assert(not ('\0\0b' < '\0\0a\0'))
+
+-- testing string.sub
+assert(string.sub("123456789",2,4) == "234")
+assert(string.sub("123456789",7) == "789")
+assert(string.sub("123456789",7,6) == "")
+assert(string.sub("123456789",7,7) == "7")
+assert(string.sub("123456789",0,0) == "")
+assert(string.sub("123456789",-10,10) == "123456789")
+assert(string.sub("123456789",1,9) == "123456789")
+assert(string.sub("123456789",-10,-20) == "")
+assert(string.sub("123456789",-1) == "9")
+assert(string.sub("123456789",-4) == "6789")
+assert(string.sub("123456789",-6, -4) == "456")
+assert(string.sub("123456789", mini, -4) == "123456")
+assert(string.sub("123456789", mini, maxi) == "123456789")
+assert(string.sub("123456789", mini, mini) == "")
+assert(string.sub("\000123456789",3,5) == "234")
+assert(("\000123456789"):sub(8) == "789")
+
+-- testing string.find
+assert(string.find("123456789", "345") == 3)
+a,b = string.find("123456789", "345")
+assert(string.sub("123456789", a, b) == "345")
+assert(string.find("1234567890123456789", "345", 3) == 3)
+assert(string.find("1234567890123456789", "345", 4) == 13)
+assert(string.find("1234567890123456789", "346", 4) == nil)
+assert(string.find("1234567890123456789", ".45", -9) == 13)
+assert(string.find("abcdefg", "\0", 5, 1) == nil)
+assert(string.find("", "") == 1)
+assert(string.find("", "", 1) == 1)
+assert(not string.find("", "", 2))
+assert(string.find('', 'aaa', 1) == nil)
+assert(('alo(.)alo'):find('(.)', 1, 1) == 4)
+
+assert(string.len("") == 0)
+assert(string.len("\0\0\0") == 3)
+assert(string.len("1234567890") == 10)
+
+assert(#"" == 0)
+assert(#"\0\0\0" == 3)
+assert(#"1234567890" == 10)