Module:Repr/testcases
Appearance
![]() | This is the test cases page for the module Module:Repr. Results of the test cases. |
-- Load necessary modules
local mRepr = require('Module:Repr')
local ScribuntoUnit = require('Module:ScribuntoUnit')
-- Initialise test suite
local suite = ScribuntoUnit:new()
local reprTestData = {
{
testName = "testRepr_nil",
args = {nil, {}},
expected = 'nil',
},
{
testName = "testRepr_true",
args = {true, {}},
expected = 'true',
},
{
testName = "testRepr_false",
args = {false, {}},
expected = 'false',
},
{
testName = "testRepr_integer",
args = {7, {}},
expected = '7',
},
{
testName = "testRepr_float",
args = {3.14159, {}},
expected = '3.14159',
},
{
testName = "testRepr_largeInt",
args = {12345678901234567890, {}},
expected = '1.2345678901235e+19',
},
{
testName = "testRepr_positiveInfinity",
args = {math.huge, {}},
expected = 'math.huge',
},
{
testName = "testRepr_negativeInfinity",
args = {-math.huge, {}},
expected = '-math.huge',
},
{
testName = "testRepr_NaN",
args = {0/0, {}},
expected = '-nan',
},
{
testName = "testRepr_emptyString",
args = {"", {}},
expected = '""',
},
{
testName = "testRepr_normalString",
args = {"foo", {}},
expected = '"foo"',
},
{
testName = "testRepr_stringWithQuotes",
args = {'"foo"', {}},
expected = '"\\"foo\\""',
},
{
testName = "testRepr_stringWithNewline",
args = {'foo\nbar', {}},
expected = '"foo\\nbar"',
},
{
testName = "testRepr_emptyTable",
args = {{}, {}},
expected = '{}',
},
{
testName = "testRepr_sequenceWithSimpleValues",
args = {{1, "foo", true}, {}},
expected = '{1, "foo", true}',
},
{
testName = "testRepr_sequenceWithSimpleValues",
args = {{1, "foo", true}, {}},
expected = '{1, "foo", true}',
},
{
testName = "testRepr_sparseSequence",
args = {{1, nil, 3, nil, 5}, {}},
expected = '{1, nil, 3, nil, 5}',
},
{
testName = "testRepr_tableWithZeroKey",
args = {{[0] = 0}, {}},
expected = '{[0] = 0}',
},
{
testName = "testRepr_tableWithNegativeIntegerKeys",
args = {{[-2] = -2, [-1] = -1}, {}},
expected = '{[-2] = -2, [-1] = -1}',
},
{
testName = "testRepr_tableWithFloatKeys",
args = {{[3.14159] = "pi"}, {}},
expected = '{[3.14159] = "pi"}',
},
{
testName = "testRepr_tableWithHugeKey",
args = {{[math.huge] = "huge"}, {}},
expected = '{[math.huge] = "huge"}',
},
{
testName = "testRepr_tableWithIdentifierKeys",
args = {{a = "b", c = "d"}, {}},
expected = '{a = "b", c = "d"}',
},
{
testName = "testRepr_nestedSequence",
args = {{1, 2, {3, 4, {5}}}, {}},
expected = '{1, 2, {3, 4, {5}}}',
},
{
testName = "testRepr_tableWithIdentifierKeys",
args = {{a = {b = {c = "d"}}}, {}},
expected = '{a = {b = {c = "d"}}}',
},
{
testName = "testRepr_tableKeySorting",
args = {{c = "ccc", a = "aaa", b = "bbb"}, {}},
expected = '{a = "aaa", b = "bbb", c = "ccc"}',
},
}
for _, testData in ipairs(reprTestData) do
suite[testData.testName] = function(self)
local result = mRepr.repr(unpack(testData.args))
self:assertEquals(testData.expected, result)
end
end
return suite