diff options
author | ZyX <kp-pav@yandex.ru> | 2017-11-19 21:40:34 +0300 |
---|---|---|
committer | ZyX <kp-pav@yandex.ru> | 2017-11-19 22:00:59 +0300 |
commit | ebb33eddd9ad0e9cec5013be2e37c8f9b0546c77 (patch) | |
tree | a7d71b2d6de9159e16be5abe3b3a43a9bcca9d90 /test/helpers.lua | |
parent | 731dc82f8c04e3019ecc3243b6b512535998635b (diff) | |
download | rneovim-ebb33eddd9ad0e9cec5013be2e37c8f9b0546c77.tar.gz rneovim-ebb33eddd9ad0e9cec5013be2e37c8f9b0546c77.tar.bz2 rneovim-ebb33eddd9ad0e9cec5013be2e37c8f9b0546c77.zip |
tests: Stabilize float format and %e in format_luav and format_string
Diffstat (limited to 'test/helpers.lua')
-rw-r--r-- | test/helpers.lua | 15 |
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 |