aboutsummaryrefslogtreecommitdiff
path: root/test/helpers.lua
diff options
context:
space:
mode:
Diffstat (limited to 'test/helpers.lua')
-rw-r--r--test/helpers.lua15
1 files changed, 13 insertions, 2 deletions
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