From Wikipedia, the free encyclopedia

-- 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, "id"),

    	"arg not present")

    

   self:assertEquals(

   	nil, mapframeModule.getParameterValue(args, "id", 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 = "control" .. string.char(0x05) .. "char"

	}

	local expected = {

		foo = "foo",

		spaced = "spaced",

		leadingSpace = "leading space",

		trailingSpace = "trailingSapce",

		number = 42,

		controlChar = "control char"

	}

    self:assertDeepEquals(expected, mapframeModule.trimArgs(args))

end



function suite:testIsAffirmed()

	-- @param {String} val

	-- @returns {Boolean}

	

	local affirmWords = {

		"add",

		"added",

		"affirm",

		"affirmed",

		"include",

		"included",

		"on",

		"true",

		"yes",

		"y"

	}

	local otherWords = {

		"foo",

		"bar",

		"no",

		"n",

		""

	}

	for _, word in pairs(affirmWords) do

		self:assertTrue(mapframeModule.isAffirmed(word))

	end

	for _, word in pairs(otherWords) do

		self:assertFalse(mapframeModule.isAffirmed(word))

	end

end



function suite:testIsDeclined()

	-- @param {String} val

	-- @returns {Boolean}

	

	local declineWords = {

		"decline",

		"declined",

		"exclude",

		"excluded",

		"false",

		"none",

		"not",

		"no",

		"n",

		"off",

		"omit",

		"omitted",

		"remove",

		"removed"

	}

	local otherWords = {

		"foo",

		"bar",

		"yes",

		"y",

		""

	}

	for _, word in pairs(declineWords) do

		self:assertTrue(mapframeModule.isDeclined(word))

	end

	for _, word in pairs(otherWords) do

		self:assertFalse(mapframeModule.isDeclined(word))

	end

end



return suite
From Wikipedia, the free encyclopedia

-- 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, "id"),

    	"arg not present")

    

   self:assertEquals(

   	nil, mapframeModule.getParameterValue(args, "id", 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 = "control" .. string.char(0x05) .. "char"

	}

	local expected = {

		foo = "foo",

		spaced = "spaced",

		leadingSpace = "leading space",

		trailingSpace = "trailingSapce",

		number = 42,

		controlChar = "control char"

	}

    self:assertDeepEquals(expected, mapframeModule.trimArgs(args))

end



function suite:testIsAffirmed()

	-- @param {String} val

	-- @returns {Boolean}

	

	local affirmWords = {

		"add",

		"added",

		"affirm",

		"affirmed",

		"include",

		"included",

		"on",

		"true",

		"yes",

		"y"

	}

	local otherWords = {

		"foo",

		"bar",

		"no",

		"n",

		""

	}

	for _, word in pairs(affirmWords) do

		self:assertTrue(mapframeModule.isAffirmed(word))

	end

	for _, word in pairs(otherWords) do

		self:assertFalse(mapframeModule.isAffirmed(word))

	end

end



function suite:testIsDeclined()

	-- @param {String} val

	-- @returns {Boolean}

	

	local declineWords = {

		"decline",

		"declined",

		"exclude",

		"excluded",

		"false",

		"none",

		"not",

		"no",

		"n",

		"off",

		"omit",

		"omitted",

		"remove",

		"removed"

	}

	local otherWords = {

		"foo",

		"bar",

		"yes",

		"y",

		""

	}

	for _, word in pairs(declineWords) do

		self:assertTrue(mapframeModule.isDeclined(word))

	end

	for _, word in pairs(otherWords) do

		self:assertFalse(mapframeModule.isDeclined(word))

	end

end



return suite

Videos

Youtube | Vimeo | Bing

Websites

Google | Yahoo | Bing

Encyclopedia

Google | Yahoo | Bing

Facebook