[Tarantool-patches] [PATCH v2 luajit 16/30] test: adapt PUC Lua test for %q in fmt for LuaJIT

Sergey Kaplun skaplun at tarantool.org
Fri Mar 26 10:42:59 MSK 2021


LuaJIT: LuaJIT since v2.0.0-beta6 has extension from Lua 5.2:
string.format(): %q reversible.
See also https://luajit.org/extensions.html#lua52.

In Lua 5.1 string.format() does not accept string values containing
embedded zeros, except as arguments to the '%q' option.
In Lua 5.2 '\0' is not handled differently from other
control chars in string.format('%q', ...).
See commit 7cc981c14067d4b0e774a6bfb0acfc2f5c911f0d
(string.format("%q", str) is now fully reversible
(from Lua 5.2).).

This patch adapts test for LuaJIT and Lua 5.2 behaviour considering
test from Lua 5.2 test suite taken from
https://www.lua.org/tests/lua-5.2.0-tests.tar.gz.

Closes tarantool/tarantool#5710
Part of tarantool/tarantool#5845
Part of tarantool/tarantool#4473
---
 test/PUC-Lua-5.1-tests/strings.lua | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/test/PUC-Lua-5.1-tests/strings.lua b/test/PUC-Lua-5.1-tests/strings.lua
index 237dbad..7c1dfb8 100644
--- a/test/PUC-Lua-5.1-tests/strings.lua
+++ b/test/PUC-Lua-5.1-tests/strings.lua
@@ -102,7 +102,17 @@ print('+')
 
 x = '"ílo"\n\\'
 assert(string.format('%q%s', x, x) == '"\\"ílo\\"\\\n\\\\""ílo"\n\\')
-assert(string.format('%q', "\0") == [["\000"]])
+-- LuaJIT: LuaJIT since v2.0.0-beta6 has extension from Lua 5.2:
+-- string.format(): %q reversible.
+-- In Lua 5.1 string.format() does not accept string values
+-- containing embedded zeros, except as arguments to the q option.
+-- In Lua 5.2 '\0' is not handled differently from other
+-- control chars in string.format('%q', ...).
+-- See commit 7cc981c14067d4b0e774a6bfb0acfc2f5c911f0d
+-- (string.format("%q", str) is now fully reversible
+-- (from Lua 5.2).).
+-- Test is adapted from PUC-Rio Lua 5.2 test suite.
+assert(string.format('%q', "\0") == [["\0"]])
 assert(string.format("\0%c\0%c%x\0", string.byte("á"), string.byte("b"), 140) ==
               "\0á\0b8c\0")
 assert(string.format('') == "")
-- 
2.31.0



More information about the Tarantool-patches mailing list