aboutsummaryrefslogtreecommitdiff
path: root/test/helpers.lua
diff options
context:
space:
mode:
authorZyX <kp-pav@yandex.ru>2018-02-02 01:23:20 +0300
committerJames McCoy <jamessan@jamessan.com>2018-02-02 07:28:56 -0500
commit2316a38dd117b0bbd3b6ebb04856029c227633f6 (patch)
treeb9c65cfc4fd46e454cdf1706a545b12557210921 /test/helpers.lua
parenta2dfeb8a16117b51744ef3c37392a61396aa3ae5 (diff)
downloadrneovim-2316a38dd117b0bbd3b6ebb04856029c227633f6.tar.gz
rneovim-2316a38dd117b0bbd3b6ebb04856029c227633f6.tar.bz2
rneovim-2316a38dd117b0bbd3b6ebb04856029c227633f6.zip
tests: Make format_string('%q', ...) output more stable
It appears to be different on lua and luajit.
Diffstat (limited to 'test/helpers.lua')
-rw-r--r--test/helpers.lua23
1 files changed, 14 insertions, 9 deletions
diff --git a/test/helpers.lua b/test/helpers.lua
index faf5c8e7f2..3e7e70fe07 100644
--- a/test/helpers.lua
+++ b/test/helpers.lua
@@ -423,11 +423,13 @@ format_luav = function(v, indent, opts)
if opts.literal_strings then
ret = v
else
- ret = tostring(v):gsub('[\'\\]', '\\%0'):gsub(
- '[%z\1-\31]', function(match)
- return SUBTBL[match:byte() + 1]
- end)
- ret = '\'' .. ret .. '\''
+ quote = opts.dquote_strings and '"' or '\''
+ ret = quote .. tostring(v):gsub(
+ opts.dquote_strings and '["\\]' or '[\'\\]',
+ '\\%0'):gsub(
+ '[%z\1-\31]', function(match)
+ return SUBTBL[match:byte() + 1]
+ end) .. quote
end
elseif type(v) == 'table' then
if v == REMOVE_THIS then
@@ -490,11 +492,14 @@ local function format_string(fmt, ...)
if subfmt:sub(-1) ~= '%' then
arg = getarg()
end
- if subfmt:sub(-1) == 'r' then
- -- %r is like %q, but it is supposed to single-quote strings and not
- -- double-quote them, and also work not only for strings.
+ if subfmt:sub(-1) == 'r' or subfmt:sub(-1) == 'q' then
+ -- %r is like built-in %q, but it is supposed to single-quote strings and
+ -- not double-quote them, and also work not only for strings.
+ -- Builtin %q is replaced here as it gives invalid and inconsistent with
+ -- luajit results for e.g. "\e" on lua: luajit transforms that into `\27`,
+ -- lua leaves as-is.
+ arg = format_luav(arg, nil, {dquote_strings = (subfmt:sub(-1) == 'q')})
subfmt = subfmt:sub(1, -2) .. 's'
- arg = format_luav(arg)
end
if subfmt == '%e' then
return format_float(arg)