aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-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')