Jump to content

Module:Sandbox/Izno/citationTests

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Izno (talk | contribs) at 03:46, 20 February 2021 (ok). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
local myModule = require('Module:Citation/CS1') -- the module to be tested
local ScribuntoUnit = require('Module:ScribuntoUnit')
local suite = ScribuntoUnit:new()

local function copy(t1, t2)
	for k, v in ipairs(t2) do
		t1[k] = v
	end
end

local function citeref(test_parameters, args)
	local merged_args = copy(test_parameters.base_args, args)
	local expansion = test_parameters.frame:expandTemplate{
		title = test_parameters.template, args = merged_args
	}
	local _, _, citeref_value = mw.ustring.find(expansion, test_parameters.pattern)
	if not citeref_value then
		citeref_value = ''
	end
	return citeref_value
end

function suite:testBasic()
	local env = {
		frame = mw.getCurrentFrame(),
		pattern = '(CITEREF%s)\"',
		template = 'cite book/new',
		base_args = { title = 'T', year = '2020' }
	}
	
	self:assertTrue(citeref(env, {chapter = 'CH'}), '')
	self:assertTrue(citeref(env, {author = '_A1_'}), 'CITEREF_A1_2020')
	self:assertTrue(citeref(env, {contributor = 'C1'}), '')
	self:assertTrue(citeref(env, {contributor = 'C1', contribution = 'CON'}), '')

end

return suite