Jump to content

Module:Check winner by scores/testcases

From Wikipedia, the free encyclopedia
local mSandbox = require('Module:Check winner by scores/sandbox') -- the module to be tested
local ScribuntoUnit = require('Module:ScribuntoUnit')
local suite = ScribuntoUnit:new()
local frame = mw.getCurrentFrame()

--------------------------------------------------------------------------------
-- Helper functions
--------------------------------------------------------------------------------

local function makeFrameWithArgs(args)
	local frame = frame:newChild{title = 'Template:Check winner by scores', args = args}
	return frame
end

local function execTest(args)
	return mSandbox.main(makeFrameWithArgs(args))
end

function suite:assertEq(expected, actual)
	expected = expected
	self:assertEquals(mw.text.trim(expected), mw.text.trim(actual))
end

function suite:assertErr(actual)
	self:assertEquals(mw.text.trim('Result unknown'), mw.text.trim(actual))
end

--------------------------------------------------------------------------------
-- One unnamed parameter test
--------------------------------------------------------------------------------

function suite:test1up_hWin_WL()
	self:assertEq('W', execTest{ 'W–L' })
end

function suite:test1up_hLoss_LW()
	self:assertEq('L', execTest{ 'L–W' })
end

function suite:test1up_hWin_minusSign()
	self:assertEq('W', execTest{ '100-91' })
end

function suite:test1up_hLoss_minusSign()
	self:assertEq('L', execTest{ '80-84' })
end

function suite:test1up_hWin_enDash()
	self:assertEq('W', execTest{ '100–91' })
end

function suite:test1up_hLoss_enDash()
	self:assertEq('L', execTest{ '80–84' })
end

function suite:test1up_hWin_wikiLink()
	self:assertEq('W', execTest{ '[[Main Page|100–91]]' })
end

function suite:test1up_hLoss_wikiLink()
	self:assertEq('L', execTest{ '[[Main Page|80–84]]' })
end

function suite:test1up_hWin_externalLink()
	self:assertEq('W', execTest{ '[http://en.wikipedia.org 100–91]' })
end

function suite:test1up_hLoss_externalLink()
	self:assertEq('L', execTest{ '[http://en.wikipedia.org 80–84]' })
end

function suite:test1up_noAwayScore()
	self:assertEq("''Result unknown''", execTest{ '10' })
end

function suite:test1up_noAwayScore_negativeHomeScore()
	self:assertEq("''Result unknown''", execTest{ '-10' })
end

function suite:test1up_alphabeticScores()
	self:assertEq("''Result unknown''", execTest{ 'AB–CD' })
end

function suite:test1up_hWin_homeScoreInBoldMarkup()
	self:assertEq("W", execTest{ "'''3'''–0" })
end

function suite:test1up_hWin_awayScoreInBoldMarkup()
	self:assertEq("L", execTest{ "0-'''3'''" })
end

function suite:test1up_hWin_scoresInBoldMarkup()
	self:assertEq("W", execTest{ "'''3-0'''" })
end

function suite:test1up_hWin_homeScoreInItalicMarkup()
	self:assertEq("W", execTest{ "'3'–0" })
end

function suite:test1up_hLoss_awayScoreInItalicMarkup()
	self:assertEq("L", execTest{ "0-'3'" })
end

function suite:test1up_hWin_scoresInItalicMarkup()
	self:assertEq("W", execTest{ "'3-0'" })
end

--------------------------------------------------------------------------------
-- Two unnamed parameters test
--------------------------------------------------------------------------------

function suite:testSc_hWin_WL()
	self:assertEq('W', execTest{ 'W', 'L' })
end

function suite:test2up_hLoss_LW()
	self:assertEq('L', execTest{ 'L', 'W' })
end

function suite:test2up_hWin_minusSign()
	self:assertEq('W', execTest{ '100', '91' })
end

function suite:test2up_hLoss_minusSign()
	self:assertEq('L', execTest{ '80', '84' })
end

function suite:test2up_hWin_enDash()
	self:assertEq('W', execTest{ '100', '91' })
end

function suite:test2up_hLoss_enDash()
	self:assertEq('L', execTest{ '80', '84' })
end

function suite:test2up_noAwayScore()
	self:assertEq("''Result unknown''", execTest{ '10' })
end

function suite:test2up_noAwayScore_negativeHomeScore()
	self:assertEq("''Result unknown''", execTest{ '-10' })
end

function suite:test2up_alphabeticScores()
	self:assertEq("''Result unknown''", execTest{ 'AB', 'CD' })
end

function suite:test2up_hWin_homeScoreInBoldMarkup()
	self:assertEq("W", execTest{ "'''3'''", '0' })
end

function suite:test2up_hWin_awayScoreInBoldMarkup()
	self:assertEq("L", execTest{ '0', "'''3'''" })
end

function suite:test2up_hWin_scoresInBoldMarkup()
	self:assertEq("W", execTest{ "'''3'''", "'''0'''" })
end

function suite:test2up_hWin_homeScoreInItalicMarkup()
	self:assertEq("W", execTest{ "''3''", '0' })
end

function suite:test2up_hLoss_awayScoreInItalicMarkup()
	self:assertEq("L", execTest{ '0', "''3''" })
end

function suite:test2up_hWin_scoresInItalicMarkup()
	self:assertEq("W", execTest{ "''3''", "''0''" })
end

--------------------------------------------------------------------------------
-- 'sc' parameter test
--------------------------------------------------------------------------------

function suite:testSc_hWin_WL()
	self:assertEq('W', execTest{ sc='W–L' })
end

function suite:testSc_hLoss_LW()
	self:assertEq('L', execTest{ sc='L–W' })
end

function suite:testSc_hWin_minusSign()
	self:assertEq('W', execTest{ sc='100-91' })
end

function suite:testSc_hLoss_minusSign()
	self:assertEq('L', execTest{ sc='80-84' })
end

function suite:testSc_hWin_enDash()
	self:assertEq('W', execTest{ sc='100–91' })
end

function suite:testSc_hLoss_enDash()
	self:assertEq('L', execTest{ sc='80–84' })
end

function suite:testSc_hWin_wikiLink()
	self:assertEq('W', execTest{ sc='[[Main Page|100–91]]' })
end

function suite:testSc_hLoss_wikiLink()
	self:assertEq('L', execTest{ sc='[[Main Page|80–84]]' })
end

function suite:testSc_hWin_externalLink()
	self:assertEq('W', execTest{ sc='[http://en.wikipedia.org 100–91]' })
end

function suite:testSc_hLoss_externalLink()
	self:assertEq('L', execTest{ sc='[http://en.wikipedia.org 80–84]' })
end

function suite:testSc_alphabeticScores()
	self:assertEq("''Result unknown''", execTest{ sc='AB–CD' })
end

function suite:testSc_hWin_homeScoreInBoldMarkup()
	self:assertEq("W", execTest{ sc="'''3'''–0" })
end

function suite:testSc_hWin_awayScoreInBoldMarkup()
	self:assertEq("L", execTest{ sc="0-'''3'''" })
end

function suite:testSc_hWin_scoresInBoldMarkup()
	self:assertEq("W", execTest{ sc="'''3-0'''" })
end

function suite:testSc_hWin_homeScoreInItalicMarkup()
	self:assertEq("W", execTest{ sc="'3'–0" })
end

function suite:testSc_hLoss_awayScoreInItalicMarkup()
	self:assertEq("L", execTest{ sc="0-'3'" })
end

function suite:testSc_hWin_scoresInItalicMarkup()
	self:assertEq("W", execTest{ sc="'3-0'" })
end

return suite