Added more tests.
This commit is contained in:
parent
2a652a4c92
commit
6ac8a2d6de
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
local utf8 = require "utf8"
|
local utf8 = require "utf8" -- FIXME: I don't really like this. Either have a local copy of the files, or remove the functionallity requiring it.
|
||||||
|
|
||||||
-- Constants
|
-- Constants
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ local function format_test (t)
|
||||||
error(ASSERT_ERROR_APPROX:format(expected_result, actual_result))
|
error(ASSERT_ERROR_APPROX:format(expected_result, actual_result))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end, { line = debug.getinfo(2).currentline })
|
||||||
end
|
end
|
||||||
|
|
||||||
local function curline (delta)
|
local function curline (delta)
|
||||||
|
|
|
@ -7,7 +7,7 @@ SUITE:setEnviroment{
|
||||||
local function format_test (t)
|
local function format_test (t)
|
||||||
SUITE:addTest(t.expect, function ()
|
SUITE:addTest(t.expect, function ()
|
||||||
assert_equal(t.expect, format(t.input, t.options))
|
assert_equal(t.expect, format(t.input, t.options))
|
||||||
end)
|
end, { line = debug.getinfo(2).currentline })
|
||||||
end
|
end
|
||||||
|
|
||||||
local function number_test (t)
|
local function number_test (t)
|
||||||
|
@ -16,7 +16,7 @@ local function number_test (t)
|
||||||
end)
|
end)
|
||||||
SUITE:addTest(t.shorthand or (t.expect .. ' shorthand'), function ()
|
SUITE:addTest(t.shorthand or (t.expect .. ' shorthand'), function ()
|
||||||
assert_equal(t.shorthand or t.expect, format(t.input, { math_shorthand = true }))
|
assert_equal(t.shorthand or t.expect, format(t.input, { math_shorthand = true }))
|
||||||
end)
|
end, { line = debug.getinfo(2).currentline })
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
|
@ -18,19 +18,16 @@ if not loadstring then loadstring = load end -- Lua 5.3 compa
|
||||||
local function format_test (t)
|
local function format_test (t)
|
||||||
if t.longterm then return end
|
if t.longterm then return end
|
||||||
if t.adv_getlocal and not HAS_ADV_GETLOCAL then return end
|
if t.adv_getlocal and not HAS_ADV_GETLOCAL then return end
|
||||||
SUITE:addTest(t.expect, function ()
|
SUITE:addTest(t.name or t.expect:gsub('[ \n\t]+', ' '), function ()
|
||||||
local input_value = t.input
|
local actual_result = format(t.input, t.options)
|
||||||
local input_options = t.options
|
|
||||||
local expected_result = t.expect
|
|
||||||
local actual_result = format(input_value, input_options)
|
|
||||||
if not t.approx or type(actual_result) ~= 'string' then
|
if not t.approx or type(actual_result) ~= 'string' then
|
||||||
assert_equal(expected_result, actual_result)
|
assert_equal(t.expect, actual_result)
|
||||||
else
|
else
|
||||||
if not actual_result:match(expected_result) then
|
if not actual_result:match(t.expect) then
|
||||||
error(ASSERT_ERROR_APPROX:format(expected_result, actual_result))
|
error(ASSERT_ERROR_APPROX:format(t.expect, actual_result))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end, { line = debug.getinfo(2).currentline })
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
@ -322,6 +319,19 @@ do
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
do
|
||||||
|
local a = {}
|
||||||
|
local b = { a }
|
||||||
|
a[1] = b
|
||||||
|
local rec = { a = a, b = b }
|
||||||
|
format_test {
|
||||||
|
name = 'Top layers should be expanded, rather than lower layers.',
|
||||||
|
input = rec,
|
||||||
|
options = { max_depth = 5 },
|
||||||
|
expect = '{\n\ta = { {...} },\n\tb = { {...} }\n}',
|
||||||
|
}
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
-- Table Sorting
|
-- Table Sorting
|
||||||
|
@ -371,6 +381,12 @@ format_test {
|
||||||
expect = '{ \'hello\', 123, {}, true }',
|
expect = '{ \'hello\', 123, {}, true }',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
format_test {
|
||||||
|
name = 'Small sequence holes should be filled with nil',
|
||||||
|
input = { 1, nil, 3 },
|
||||||
|
expect = '{ 1, nil, 3 }',
|
||||||
|
}
|
||||||
|
|
||||||
-- TODO: Add more tests for sorting.
|
-- TODO: Add more tests for sorting.
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue
Block a user