Added additional tests for parseability and idempotency.
This commit is contained in:
parent
a8cbe42a05
commit
bfbfe4de56
|
@ -12,9 +12,21 @@ if not loadstring then loadstring = load end -- Lua 5.3
|
|||
|
||||
local function format_test (t)
|
||||
SUITE:addTest(t.name or t.expect, function ()
|
||||
local actual_result = format(t.input, t.options)
|
||||
assert_equal(t.expect, actual_result)
|
||||
assert_equal(t.expect, format(t.input, t.options))
|
||||
end, { line = debug.getinfo(2).currentline })
|
||||
|
||||
if not t.not_idempotent then
|
||||
-- Additional parsable test
|
||||
SUITE:addTest((t.name or t.expect) .. ' (parsable?)', function ()
|
||||
local chunk, error_msg = loadstring('return '..format(t.input, t.options))
|
||||
if not chunk then error(error_msg) end
|
||||
end, { line = debug.getinfo(2).currentline })
|
||||
-- Additional idempotent test
|
||||
SUITE:addTest((t.name or t.expect) .. ' (idempotent?)', function ()
|
||||
local output = loadstring('return '..format(t.input, t.options))()
|
||||
assert_equal(t.input, output)
|
||||
end, { line = debug.getinfo(2).currentline })
|
||||
end
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
@ -90,36 +102,42 @@ format_test {
|
|||
|
||||
format_test {
|
||||
name = 'Cut string basics',
|
||||
not_idempotent = true,
|
||||
input = {'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc vestibulum tempus ligula. Sed ac lobortis mi.'},
|
||||
expect = '{\n \'Lorem ipsum dolor sit amet, consectet\'...\n}',
|
||||
}
|
||||
|
||||
format_test {
|
||||
name = 'Cut strings are cut after escaping',
|
||||
not_idempotent = true,
|
||||
input = {'Lorem\tipsum\tdolor\tsit\tamet,\tconsectetur\tadipiscing\telit.\tNunc\tvestibulum\ttempus\tligula.\tSed\tac\tlobortis\tmi.'},
|
||||
expect = '{\n \'Lorem\\tipsum\\tdolor\\tsit\\tamet,\\tcons\'...\n}',
|
||||
}
|
||||
|
||||
format_test {
|
||||
name = 'Cut strings are cut after escaping 2',
|
||||
not_idempotent = true,
|
||||
input = {'Lorem ipsum dolor sit amet, conse\t\t\tctetur adipiscing elit. Nunc vestibulum tempus ligula. Sed ac lobortis mi.'},
|
||||
expect = '{\n \'Lorem ipsum dolor sit amet, conse\\t\\t\'...\n}',
|
||||
}
|
||||
|
||||
format_test {
|
||||
name = 'Cut strings are not cut in the middle of an escape code',
|
||||
not_idempotent = true,
|
||||
input = {'Lorem ipsum dolor sit amet, consec\t\t\ttetur adipiscing elit. Nunc vestibulum tempus ligula. Sed ac lobortis mi.'},
|
||||
expect = '{\n \'Lorem ipsum dolor sit amet, consec\\t\'...\n}',
|
||||
}
|
||||
|
||||
format_test {
|
||||
name = 'Cut strings are not cut in the middle of escaping \\',
|
||||
not_idempotent = true,
|
||||
input = {'Lorem ipsum dolor sit amet, conse\\\\\\\\ctetur adipiscing elit. Nunc vestibulum tempus ligula. Sed ac lobortis mi.'},
|
||||
expect = '{\n \'Lorem ipsum dolor sit amet, conse\\\\\\\\\'...\n}',
|
||||
}
|
||||
|
||||
format_test {
|
||||
name = 'Cut strings are not cut in the middle of decimal escape codes',
|
||||
not_idempotent = true,
|
||||
input = {'Lorem ipsum dolor sit amet, consect\014etur adipiscing elit. Nunc vestibulum tempus ligula. Sed ac lobortis mi.'},
|
||||
expect = '{\n \'Lorem ipsum dolor sit amet, consect\'...\n}',
|
||||
}
|
||||
|
@ -127,6 +145,7 @@ format_test {
|
|||
format_test {
|
||||
-- NOTE: Not priority functionallity.
|
||||
name = 'Cut strings can shorten decimal escape codes, if nessesary and possible',
|
||||
not_idempotent = true,
|
||||
input = {'Lorem ipsum dolor sit amet, consec\014tetur adipiscing elit. Nunc vestibulum tempus ligula. Sed ac lobortis mi.'},
|
||||
expect = '{\n \'Lorem ipsum dolor sit amet, consec\\14\'...\n}',
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user