mirror of
https://github.com/nmap/nmap.git
synced 2025-12-22 07:29:01 +00:00
Fix broken JSON unit tests. Closes #2222
This commit is contained in:
@@ -330,8 +330,16 @@ local TESTS = {
|
||||
test = function(o) return not next(o) end
|
||||
},
|
||||
{'', valid=false},
|
||||
{'null', valid=false}, -- error
|
||||
{'"abc"', valid=false}, -- error
|
||||
{
|
||||
'null',
|
||||
generates = 'null',
|
||||
is = "null"
|
||||
},
|
||||
{
|
||||
'"abc"',
|
||||
generates = '"abc"',
|
||||
is = "string",
|
||||
},
|
||||
{'{a":1}', valid=false}, -- error
|
||||
{'{"a" bad :1}', valid=false}, -- error
|
||||
{
|
||||
@@ -353,12 +361,12 @@ local TESTS = {
|
||||
},
|
||||
{
|
||||
'[5e3]',
|
||||
generates = '[5000]',
|
||||
generates = '[5000.0]',
|
||||
is = "array",
|
||||
},
|
||||
{
|
||||
'[5e+3]',
|
||||
generates = '[5000]',
|
||||
generates = '[5000.0]',
|
||||
is = "array",
|
||||
},
|
||||
{
|
||||
@@ -368,7 +376,7 @@ local TESTS = {
|
||||
},
|
||||
{
|
||||
'[5.5e3]',
|
||||
generates = '[5500]',
|
||||
generates = '[5500.0]',
|
||||
is = "array",
|
||||
},
|
||||
{
|
||||
@@ -388,12 +396,23 @@ local TESTS = {
|
||||
generates = '["A"]',
|
||||
is = "array",
|
||||
}, -- Should become Lua {"A"}
|
||||
{'["\\uD800"]', valid=false}, -- error
|
||||
{
|
||||
'["\\uD800"]',
|
||||
valid=false,
|
||||
test = function(s)
|
||||
return s:find("Bad unicode escape.*missing low surrogate") ~= nil
|
||||
end
|
||||
}, -- error
|
||||
{
|
||||
'["\\uD834\\uDD1EX"]',
|
||||
generates = '["\240\157\132\158X"]',
|
||||
is = "array",
|
||||
}, -- Should become Lua {"\240\157\132\158X"}
|
||||
{
|
||||
'1684119503',
|
||||
generate = '1684119503',
|
||||
is = "number"
|
||||
}
|
||||
}
|
||||
|
||||
test_suite = unittest.TestSuite:new()
|
||||
@@ -406,8 +425,9 @@ for _, test in ipairs(TESTS) do
|
||||
local status, val = parse(test[1])
|
||||
if test.valid == false then
|
||||
test_suite:add_test(is_false(status), "Syntax error status is false")
|
||||
if not test.test then
|
||||
test_suite:add_test(equal(val, "syntax error"), "Syntax error")
|
||||
break
|
||||
end
|
||||
end
|
||||
if test.generates then
|
||||
test_suite:add_test(equal(generate(val), test.generates), "Generate")
|
||||
|
||||
Reference in New Issue
Block a user