Jump to content

Module:Mapframe/sandbox/testcases: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
exported in p.test
have to use args which are in the L10n.para table
Line 8: Line 8:
-- @returns {String|nil}
-- @returns {String|nil}
local args = {
local args = {
foo = "foo",
display = "foo",
bar = "bar",
type = "bar",
bar2 = "bar2",
type2 = "bar2",
}
}
self:assertEquals(
self:assertEquals(
"foo", mapframeModule.getParameterValue(args, "foo"),
"foo", mapframeModule.getParameterValue(args, "display"),
"arg without suffix")
"arg without suffix")
self:assertEquals(
self:assertEquals(
"bar", mapframeModule.getParameterValue(args, "bar"),
"bar", mapframeModule.getParameterValue(args, "type"),
"arg without suffix (where there is also a same-named arg with a suffix)")
"arg without suffix (where there is also a same-named arg with a suffix)")
self:assertEquals(
self:assertEquals(
"bar2", mapframeModule.getParameterValue(args, "bar", 2),
"bar2", mapframeModule.getParameterValue(args, "type", 2),
"arg with suffix")
"arg with suffix")
self:assertEquals(
self:assertEquals(
nil, mapframeModule.getParameterValue(args, "bar", 3),
nil, mapframeModule.getParameterValue(args, "type", 3),
"arg with suffix not present (same-named arg with different suffix is present)")
"arg with suffix not present (same-named arg with different suffix is present)")
self:assertEquals(
self:assertEquals(
"foo", mapframeModule.getParameterValue(args, "foo", 3)
nil, mapframeModule.getParameterValue(args, "display", 3)
"arg with suffix not present (same-named arg without any suffix is present)")
"arg with suffix not present (same-named arg without any suffix is present)")

Revision as of 04:21, 25 March 2020

-- Unit tests for [[Module:Example]]. Click talk page to run tests.
local mapframeModule = require('Module:Mapframe/sandbox').test -- the module to be tested
local ScribuntoUnit = require('Module:ScribuntoUnit')
local suite = ScribuntoUnit:new()

function suite:testGetParameterValue()
	-- @params {Table}args, {String}param_id, [{Number}suffix]
	-- @returns {String|nil}
	local args = {
		display = "foo",
		type = "bar",
		type2 = "bar2",
	}
	
    self:assertEquals(
    	"foo",  mapframeModule.getParameterValue(args, "display"),
    	"arg without suffix")
    
    self:assertEquals(
    	"bar",  mapframeModule.getParameterValue(args, "type"),
    	"arg without suffix (where there is also a same-named arg with a suffix)")
    
    self:assertEquals(
    	"bar2", mapframeModule.getParameterValue(args, "type", 2),
    	"arg with suffix")
    
    self:assertEquals(
    	nil, mapframeModule.getParameterValue(args, "type", 3),
    	"arg with suffix not present (same-named arg with different suffix is present)")
    
    self:assertEquals(
    	nil, mapframeModule.getParameterValue(args, "display", 3)
    	"arg with suffix not present (same-named arg without any suffix is present)")
    
    self:assertEquals(
    	nil, mapframeModule.getParameterValue(args, "qux"),
    	"arg not present")
    
   self:assertEquals(
   	nil, mapframeModule.getParameterValue(args, "qux", 3),
   	"-- arg with suffix not present (no same-named arg with or without any suffix)")
end

function suite:testTrimArgs()
	-- @param {Table<String, String|Number>}argsTable
	-- @returns {Table<String, String|Number>}
	local args = {
		foo = "foo",
		spaced = " spaced ",
		leadingSpace = "   leading space",
		trailingSpace = "trailingSapce    ",
		empty = "",
		number = 42,
		controlChar = "controlChar" .. string.char(0x05)
	}
	local expected = {
		foo = "foo",
		spaced = "spaced",
		leadingSpace = "leading space",
		trailingSpace = "trailingSapce",
		number = 42,
		controlChar = "controlChar"
	}
    self:assertDeepEquals(expected, mapframeModule.trimArgs(args))
end

return suite