aboutsummaryrefslogtreecommitdiff
path: root/tests/single.lua
diff options
context:
space:
mode:
authorBenoit Giannangeli <giann008@gmail.com>2017-04-11 08:05:25 +0200
committerBenoit Giannangeli <giann008@gmail.com>2017-04-11 08:10:42 +0200
commit72e49b26d32423d66b68fb45e9aace9c503a1a5c (patch)
tree76354fc4cef276306ff355208e317b5166ccf24f /tests/single.lua
parentc8cb77ea06cb2f1ca10cf63042a7cbea8d1c5e7a (diff)
downloadfengari-72e49b26d32423d66b68fb45e9aace9c503a1a5c.tar.gz
fengari-72e49b26d32423d66b68fb45e9aace9c503a1a5c.tar.bz2
fengari-72e49b26d32423d66b68fb45e9aace9c503a1a5c.zip
Array.prototype.sort sort by Unicode code points by default
WTF JS !
Diffstat (limited to 'tests/single.lua')
-rw-r--r--tests/single.lua87
1 files changed, 87 insertions, 0 deletions
diff --git a/tests/single.lua b/tests/single.lua
index c167196..fd06c3a 100644
--- a/tests/single.lua
+++ b/tests/single.lua
@@ -285,3 +285,90 @@ do print("testing 'format %a %A'")
assert(string.find(string.format("%.4A", -12), "^%-0X%x%.%x000P%+?%d$"))
end
end
+
+-- errors in format
+
+local function check (fmt, msg)
+ checkerror(msg, string.format, fmt, 10)
+end
+
+local aux = string.rep('0', 600)
+check("%100.3d", "too long")
+check("%1"..aux..".3d", "too long")
+check("%1.100d", "too long")
+check("%10.1"..aux.."004d", "too long")
+check("%t", "invalid option")
+check("%"..aux.."d", "repeated flags")
+check("%d %d", "no value")
+
+assert(load("return 1\n--comment without ending EOL")() == 1)
+
+checkerror("table expected", table.concat, 3)
+assert(table.concat{} == "")
+assert(table.concat({}, 'x') == "")
+assert(table.concat({'\0', '\0\1', '\0\1\2'}, '.\0.') == "\0.\0.\0\1.\0.\0\1\2")
+local a = {}; for i=1,300 do a[i] = "xuxu" end
+assert(table.concat(a, "123").."123" == string.rep("xuxu123", 300))
+assert(table.concat(a, "b", 20, 20) == "xuxu")
+assert(table.concat(a, "", 20, 21) == "xuxuxuxu")
+assert(table.concat(a, "x", 22, 21) == "")
+assert(table.concat(a, "3", 299) == "xuxu3xuxu")
+assert(table.concat({}, "x", maxi, maxi - 1) == "")
+assert(table.concat({}, "x", mini + 1, mini) == "")
+assert(table.concat({}, "x", maxi, mini) == "")
+assert(table.concat({[maxi] = "alo"}, "x", maxi, maxi) == "alo")
+assert(table.concat({[maxi] = "alo", [maxi - 1] = "y"}, "-", maxi - 1, maxi) == "y-alo")
+
+assert(not pcall(table.concat, {"a", "b", {}}))
+
+a = {"a","b","c"}
+assert(table.concat(a, ",", 1, 0) == "")
+assert(table.concat(a, ",", 1, 1) == "a")
+assert(table.concat(a, ",", 1, 2) == "a,b")
+assert(table.concat(a, ",", 2) == "b,c")
+assert(table.concat(a, ",", 3) == "c")
+assert(table.concat(a, ",", 4) == "")
+
+-- TODO: when os.setlocale is implemented
+if false and not _port then
+
+ local locales = { "ptb", "pt_BR.iso88591", "ISO-8859-1" }
+ local function trylocale (w)
+ for i = 1, #locales do
+ if os.setlocale(locales[i], w) then
+ print(string.format("'%s' locale set to '%s'", w, locales[i]))
+ return locales[i]
+ end
+ end
+ print(string.format("'%s' locale not found", w))
+ return false
+ end
+
+ if trylocale("collate") then
+ assert("alo" < "álo" and "álo" < "amo")
+ end
+
+ if trylocale("ctype") then
+ assert(string.gsub("áéíóú", "%a", "x") == "xxxxx")
+ assert(string.gsub("áÁéÉ", "%l", "x") == "xÁxÉ")
+ assert(string.gsub("áÁéÉ", "%u", "x") == "áxéx")
+ assert(string.upper"áÁé{xuxu}ção" == "ÁÁÉ{XUXU}ÇÃO")
+ end
+
+ os.setlocale("C")
+ assert(os.setlocale() == 'C')
+ assert(os.setlocale(nil, "numeric") == 'C')
+
+end
+
+
+-- bug in Lua 5.3.2
+-- 'gmatch' iterator does not work across coroutines
+do
+ local f = string.gmatch("1 2 3 4 5", "%d+")
+ assert(f() == "1")
+ co = coroutine.wrap(f)
+ assert(co() == "2")
+end
+
+print('OK')