mirror of
https://github.com/neovim/neovim.git
synced 2025-09-10 05:18:16 +00:00
tests: Stabilize float format and %e in format_luav and format_string
This commit is contained in:
@@ -750,7 +750,7 @@ describe('api', function()
|
|||||||
typ = typ .. ('(val=%u)'):format(east_api_node.ivalue)
|
typ = typ .. ('(val=%u)'):format(east_api_node.ivalue)
|
||||||
east_api_node.ivalue = nil
|
east_api_node.ivalue = nil
|
||||||
elseif typ == 'Float' then
|
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
|
east_api_node.fvalue = nil
|
||||||
elseif typ == 'SingleQuotedString' or typ == 'DoubleQuotedString' then
|
elseif typ == 'SingleQuotedString' or typ == 'DoubleQuotedString' then
|
||||||
typ = format_string('%s(val=%q)', typ, east_api_node.svalue)
|
typ = format_string('%s(val=%q)', typ, east_api_node.svalue)
|
||||||
|
@@ -395,6 +395,13 @@ local function dedent(str, leave_indent)
|
|||||||
return str
|
return str
|
||||||
end
|
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 = {
|
local SUBTBL = {
|
||||||
'\\000', '\\001', '\\002', '\\003', '\\004',
|
'\\000', '\\001', '\\002', '\\003', '\\004',
|
||||||
'\\005', '\\006', '\\007', '\\008', '\\t',
|
'\\005', '\\006', '\\007', '\\008', '\\t',
|
||||||
@@ -468,7 +475,7 @@ format_luav = function(v, indent, opts)
|
|||||||
if v % 1 == 0 then
|
if v % 1 == 0 then
|
||||||
ret = ('%d'):format(v)
|
ret = ('%d'):format(v)
|
||||||
else
|
else
|
||||||
ret = ('%e'):format(v)
|
ret = format_float(v)
|
||||||
end
|
end
|
||||||
elseif type(v) == 'nil' then
|
elseif type(v) == 'nil' then
|
||||||
ret = 'nil'
|
ret = 'nil'
|
||||||
@@ -501,7 +508,11 @@ local function format_string(fmt, ...)
|
|||||||
subfmt = subfmt:sub(1, -2) .. 's'
|
subfmt = subfmt:sub(1, -2) .. 's'
|
||||||
arg = format_luav(arg)
|
arg = format_luav(arg)
|
||||||
end
|
end
|
||||||
return subfmt:format(arg)
|
if subfmt == '%e' then
|
||||||
|
return format_float(arg)
|
||||||
|
else
|
||||||
|
return subfmt:format(arg)
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
return ret
|
return ret
|
||||||
end
|
end
|
||||||
|
@@ -375,7 +375,7 @@ local function eastnode2lua(pstate, eastnode, checked_nodes)
|
|||||||
elseif typ == 'Integer' then
|
elseif typ == 'Integer' then
|
||||||
typ = typ .. ('(val=%u)'):format(tonumber(eastnode.data.num.value))
|
typ = typ .. ('(val=%u)'):format(tonumber(eastnode.data.num.value))
|
||||||
elseif typ == 'Float' then
|
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
|
elseif typ == 'SingleQuotedString' or typ == 'DoubleQuotedString' then
|
||||||
if eastnode.data.str.value == nil then
|
if eastnode.data.str.value == nil then
|
||||||
typ = typ .. '(val=NULL)'
|
typ = typ .. '(val=NULL)'
|
||||||
|
Reference in New Issue
Block a user