Difference between revisions of "Module:Int/testcases"

From Northumberland Climbing
Jump to navigation Jump to search
module>Tacsipacsi
(Created page with "local p = require('Module:ScribuntoUnit'):new() local m = require('Module:Int') local function callWithArgs(msg, lang, args) local templateArgs = { msg } if args then for...")
 
m (1 revision imported)
 
(No difference)

Latest revision as of 05:50, 31 July 2020

Yes All tests passed.

Name Expected Actual
Yes testRenderIntMessage
Yes testRenderIntMessageWithLang

local p = require('Module:ScribuntoUnit'):new()
local m = require('Module:Int')

local function callWithArgs(msg, lang, args)
	local templateArgs = { msg }
	if args then
		for n, v in ipairs(args) do
			templateArgs[n+1] = v
		end
	end
	local frame = (mw.getCurrentFrame()
		:newChild{ args = templateArgs }
		:newChild{ args = { [1] = msg, lang = lang } })
	return m.renderIntMessage(frame)
end

function p:testRenderIntMessage()
	self:assertEquals('View history', callWithArgs('vector-view-history'))
	self:assertEquals('View history', callWithArgs('vector-view-history', nil, {'unused', 'data', 2.71}))
	self:assertEquals('View $1 notices', callWithArgs('notification-link-text-expand-notice-count'))
	self:assertEquals('View 1 notice', callWithArgs('notification-link-text-expand-notice-count', nil, {'1'}))
	self:assertEquals('View 1 notice', callWithArgs('notification-link-text-expand-notice-count', nil, {1}))
end

function p:testRenderIntMessageWithLang()
	self:assertEquals('View history', callWithArgs('vector-view-history', ''))
	self:assertEquals('View history', callWithArgs('vector-view-history', 'en'))
	-- Apostrophes are invalid in language codes; they should be ignored rather than throwing an error
	self:assertEquals('View history', callWithArgs('vector-view-history', '"de"'))
	self:assertEquals('Versionsgeschichte', callWithArgs('vector-view-history', 'de'))
end

return p