Module:ObjectArg/testcases

From Fire Emblem Heroes Wiki
Jump to: navigation, search
Template-info.svg Documentation

☑ All tests passed.

Name Expected Actual
☑ testHash
☑ testList
☑ testNumber
☑ testString
local parse = require 'Module:ObjectArg'.parse
local suite = require 'Module:ScribuntoUnit':new()

function suite:testNumber ()
	suite:assertEquals(1, parse '1')
	suite:assertEquals(1, parse ' \t\r\n 1 \n\t\r ')
	suite:assertEquals(0, parse '0.0')
	suite:assertEquals(-0x123, parse '-0x123')
end

function suite:testString ()
	suite:assertEquals('a', parse 'a')
	suite:assertEquals('a b c', parse ' \t\r\n a b c \n\t\r ')
	suite:assertEquals('a"\'', parse 'a"\'')
end

function suite:testList ()
	suite:assertDeepEquals({}, parse '[]')
	suite:assertDeepEquals({3}, parse ' [ 3 ] ')
	suite:assertDeepEquals({}, parse '[;]')
	suite:assertDeepEquals({[2] = 3}, parse '[;3]')
	suite:assertDeepEquals({5, 6, 7, [5] = 'a'}, parse '[5;6;7;;a]')
	suite:assertDeepEquals({{}, {[2] = {}}}, parse '[[];[;[]]]')
	suite:assertDeepEquals({{}, {{}, {}}}, parse '[{};[{};{}]]')
end

function suite:testHash ()
	suite:assertDeepEquals({}, parse '{}')
	suite:assertDeepEquals({a = 'b'}, parse ' { a = b } ')
	suite:assertDeepEquals({y = 3}, parse '{x=;y=3;z=}')
	suite:assertDeepEquals({[4] = 'x'}, parse '{4=x}')
	suite:assertDeepEquals({a = {b = {c = {'d'}}}}, parse '{a={b={c=[d]}}}')
end

return suite