1
0

Added more tests.

This commit is contained in:
Jon Michael Aanes 2017-04-12 15:15:03 +02:00
parent 2a652a4c92
commit 6ac8a2d6de
4 changed files with 29 additions and 13 deletions

View File

@ -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

View File

@ -24,7 +24,7 @@ local function format_test (t)
error(ASSERT_ERROR_APPROX:format(expected_result, actual_result))
end
end
end)
end, { line = debug.getinfo(2).currentline })
end
local function curline (delta)

View File

@ -7,7 +7,7 @@ SUITE:setEnviroment{
local function format_test (t)
SUITE:addTest(t.expect, function ()
assert_equal(t.expect, format(t.input, t.options))
end)
end, { line = debug.getinfo(2).currentline })
end
local function number_test (t)
@ -16,7 +16,7 @@ local function number_test (t)
end)
SUITE:addTest(t.shorthand or (t.expect .. ' shorthand'), function ()
assert_equal(t.shorthand or t.expect, format(t.input, { math_shorthand = true }))
end)
end, { line = debug.getinfo(2).currentline })
end
--------------------------------------------------------------------------------

View File

@ -18,19 +18,16 @@ if not loadstring then loadstring = load end -- Lua 5.3 compa
local function format_test (t)
if t.longterm then return end
if t.adv_getlocal and not HAS_ADV_GETLOCAL then return end
SUITE:addTest(t.expect, function ()
local input_value = t.input
local input_options = t.options
local expected_result = t.expect
local actual_result = format(input_value, input_options)
SUITE:addTest(t.name or t.expect:gsub('[ \n\t]+', ' '), function ()
local actual_result = format(t.input, t.options)
if not t.approx or type(actual_result) ~= 'string' then
assert_equal(expected_result, actual_result)
assert_equal(t.expect, actual_result)
else
if not actual_result:match(expected_result) then
error(ASSERT_ERROR_APPROX:format(expected_result, actual_result))
if not actual_result:match(t.expect) then
error(ASSERT_ERROR_APPROX:format(t.expect, actual_result))
end
end
end)
end, { line = debug.getinfo(2).currentline })
end
--------------------------------------------------------------------------------
@ -322,6 +319,19 @@ do
}
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
@ -371,6 +381,12 @@ format_test {
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.
--------------------------------------------------------------------------------