aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZyX <kp-pav@yandex.ru>2017-11-19 21:40:34 +0300
committerZyX <kp-pav@yandex.ru>2017-11-19 22:00:59 +0300
commitebb33eddd9ad0e9cec5013be2e37c8f9b0546c77 (patch)
treea7d71b2d6de9159e16be5abe3b3a43a9bcca9d90
parent731dc82f8c04e3019ecc3243b6b512535998635b (diff)
downloadrneovim-ebb33eddd9ad0e9cec5013be2e37c8f9b0546c77.tar.gz
rneovim-ebb33eddd9ad0e9cec5013be2e37c8f9b0546c77.tar.bz2
rneovim-ebb33eddd9ad0e9cec5013be2e37c8f9b0546c77.zip
tests: Stabilize float format and %e in format_luav and format_string
-rw-r--r--test/functional/api/vim_spec.lua2
-rw-r--r--test/helpers.lua15
-rw-r--r--test/unit/viml/expressions/parser_spec.lua2
3 files changed, 15 insertions, 4 deletions
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua
index 2572675a58..5b5340d9e2 100644
--- a/test/functional/api/vim_spec.lua
+++ b/test/functional/api/vim_spec.lua
@@ -750,7 +750,7 @@ describe('api', function()
typ = typ .. ('(val=%u)'):format(east_api_node.ivalue)
east_api_node.ivalue = nil
elseif typ == 'Float' then
- typ = typ .. ('(val=%e)'):format(east_api_node.fvalue)
+ typ = typ .. format_string('(val=%e)', east_api_node.fvalue)
east_api_node.fvalue = nil
elseif typ == 'SingleQuotedString' or typ == 'DoubleQuotedString' then
typ = format_string('%s(val=%q)', typ, east_api_node.svalue)
diff --git a/test/helpers.lua b/test/helpers.lua
index fc3936a4ce..cef05046d8 100644
--- a/test/helpers.lua
+++ b/test/helpers.lua
@@ -395,6 +395,13 @@ local function dedent(str, leave_indent)
return str
end
+local function format_float(v)
+ -- On windows exponent appears to have three digits and not two
+ local ret = ('%.6e'):format(v)
+ local l, f, es, e = ret:match('^(%-?%d)%.(%d+)e([+%-])0*(%d%d+)$')
+ return l .. '.' .. f .. 'e' .. es .. e
+end
+
local SUBTBL = {
'\\000', '\\001', '\\002', '\\003', '\\004',
'\\005', '\\006', '\\007', '\\008', '\\t',
@@ -468,7 +475,7 @@ format_luav = function(v, indent, opts)
if v % 1 == 0 then
ret = ('%d'):format(v)
else
- ret = ('%e'):format(v)
+ ret = format_float(v)
end
elseif type(v) == 'nil' then
ret = 'nil'
@@ -501,7 +508,11 @@ local function format_string(fmt, ...)
subfmt = subfmt:sub(1, -2) .. 's'
arg = format_luav(arg)
end
- return subfmt:format(arg)
+ if subfmt == '%e' then
+ return format_float(arg)
+ else
+ return subfmt:format(arg)
+ end
end)
return ret
end
diff --git a/test/unit/viml/expressions/parser_spec.lua b/test/unit/viml/expressions/parser_spec.lua
index 2ae235ca86..79b19de833 100644
--- a/test/unit/viml/expressions/parser_spec.lua
+++ b/test/unit/viml/expressions/parser_spec.lua
@@ -375,7 +375,7 @@ local function eastnode2lua(pstate, eastnode, checked_nodes)
elseif typ == 'Integer' then
typ = typ .. ('(val=%u)'):format(tonumber(eastnode.data.num.value))
elseif typ == 'Float' then
- typ = typ .. ('(val=%e)'):format(tonumber(eastnode.data.flt.value))
+ typ = typ .. format_string('(val=%e)', tonumber(eastnode.data.flt.value))
elseif typ == 'SingleQuotedString' or typ == 'DoubleQuotedString' then
if eastnode.data.str.value == nil then
typ = typ .. '(val=NULL)'