Content deleted Content added
mNo edit summary |
No edit summary |
||
Line 25:
makeOnOffAsserts('StringContains')
makeOnOffAsserts('NotStringContains')
function suite:assertErrorContains(pattern, func, plain)
local success, msg = pcall(func)
self:assertFalse(success)
self:assertStringContains(pattern, msg, plain)
end
function suite:assertParsedNumberEquals(expected,aString)
local ntsObj = Nts.new({aString})
ntsObj:parseNumber(aString)
self:assertEquals(expected, ntsObj.number)
end
function suite:assertSortKeyEquals(expected, args)
Line 34 ⟶ 46:
local ntsObj = Nts.new(args)
self:assertEquals(expected, ntsObj:makeDisplay())
end
-------------------------------------------------------------------------------
-- parseNumber tests
-------------------------------------------------------------------------------
function suite:testParseNumbers()
suite:assertParsedNumberEquals(1, ' 1 ')
suite:assertParsedNumberEquals(1, '1')
suite:assertParsedNumberEquals(-1, '-1')
suite:assertParsedNumberEquals(0.1, '0.1')
suite:assertParsedNumberEquals(0.1, '.1')
suite:assertParsedNumberEquals(-0.1, '-0.1')
suite:assertParsedNumberEquals(-0.1, '-.1')
suite:assertParsedNumberEquals(1000,'1000')
suite:assertParsedNumberEquals(1000,'1,000')
suite:assertParsedNumberEquals(12345678901234567890, '12345678901234567890')
suite:assertParsedNumberEquals(12345678901234567890, '12,345,678,901,234,567,890')
suite:assertParsedNumberEquals(10345678901234567.12345678, '10345678901234567.12345678')
suite:assertParsedNumberEquals(-10345678901234567.12345678, '-10345678901234567.12345678')
end
function suite:testParseMinusSigns()
suite:assertParsedNumberEquals(-1, '−1')
suite:assertParsedNumberEquals(-1, '−1')
suite:assertParsedNumberEquals(1e-1, '1e−1')
suite:assertParsedNumberEquals(1e-1, '1e−1')
end
function suite:testInvalidNumbers()
suite:assertErrorContains("'a1' is not a valid number", function ()
Nts.new{'a1'}
end)
end
|