Jump to content

Module:Repr/testcases

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Mr. Stradivarius (talk | contribs) at 13:52, 21 February 2021 (add some string tests). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
-- 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_emptyString",
		args = {"", {}},
		expected = '""',
	},
	{
		testName = "testRepr_normalString",
		args = {"foo", {}},
		expected = '"foo"',
	},
	{
		testName = "testRepr_stringWithQuotes",
		args = {'"foo"', {}},
		expected = '\\"foo\\"',
	},
}

for _, testData in ipairs(reprTestData) do
	suite[testData.testName] = function(self)
		local result = mRepr.repr(unpack(testData.args))
		self:assertEquals(result, testData.expected)
	end
end

return suite