aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBenoit Giannangeli <giann008@gmail.com>2017-03-31 11:15:46 +0200
committerBenoit Giannangeli <giann008@gmail.com>2017-03-31 11:23:06 +0200
commitdbcb965525833d167370fdade4ff8da7126be8a6 (patch)
tree19c530db542e2e62907958a843da10ec604ca300 /tests
parentfedcb75c0fa087abcaa53a1df3304a97c4516faa (diff)
downloadfengari-dbcb965525833d167370fdade4ff8da7126be8a6.tar.gz
fengari-dbcb965525833d167370fdade4ff8da7126be8a6.tar.bz2
fengari-dbcb965525833d167370fdade4ff8da7126be8a6.zip
Use correct sprintf package
Diffstat (limited to 'tests')
-rw-r--r--tests/single.lua19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/single.lua b/tests/single.lua
index c1241de..9e7d0cf 100644
--- a/tests/single.lua
+++ b/tests/single.lua
@@ -190,3 +190,22 @@ end
assert(string.format("\0%s\0", "\0\0\1") == "\0\0\0\1\0")
checkerror("contains zeros", string.format, "%10s", "\0")
+
+-- format x tostring
+assert(string.format("%s %s", nil, true) == "nil true")
+assert(string.format("%s %.4s", false, true) == "false true")
+assert(string.format("%.3s %.3s", false, true) == "fal tru")
+local m = setmetatable({}, {__tostring = function () return "hello" end,
+ __name = "hi"})
+assert(string.format("%s %.10s", m, m) == "hello hello")
+getmetatable(m).__tostring = nil -- will use '__name' from now on
+assert(string.format("%.4s", m) == "hi: ")
+
+getmetatable(m).__tostring = function () return {} end
+checkerror("'__tostring' must return a string", tostring, m)
+
+assert(string.format("%x", 0.0) == "0")
+assert(string.format("%02x", 0.0) == "00")
+assert(string.format("%08X", 0xFFFFFFFF) == "FFFFFFFF")
+assert(string.format("%+08d", 31501) == "+0031501")
+assert(string.format("%+08d", -30927) == "-0030927")