Module:Sandbox/Izno/citationTests
Appearance
< Module:Sandbox | Izno
local myModule = require('Module:Citation/CS1') -- the module to be tested
local ScribuntoUnit = require('Module:ScribuntoUnit')
local suite = ScribuntoUnit:new()
--[=[
self:assertTemplateEquals(
'',
'cite web',
{
'website=Website',
'last=Last',
'first=First',
'url=https://en.wikipedia.org/',
'date=1 January 2010'
}
)
]=]
local function copy(t1, t2)
for k, v in ipairs(t2) do
t1[k] = v
end
end
local function citeref2(frame, template, base_args, args)
local merged_args = copy(base_args, args)
return frame:expandTemplate{ title = template, args = merged_args}
end
local function citeref1(frame, template, base_args, args)
local merged_args = copy(base_args, args)
local expansion = frame:expandTemplate{ title = template, args = merged_args}
local citeref_pattern = '(CITEREF%s)\"'
local _, _, citeref_value = mw.ustring.find(expansion, citeref_pattern)
if not citeref_value then
citeref_value = ''
end
return citeref_value
end
function suite:testCounts()
local citeref_p = '(CITEREF%s)\"'
local frame = mw.getCurrentFrame()
local template = 'cite book/new'
local base_args = { title = 'T', year = '2020' }
local tests = {
{{chapter = 'CH'}, ''},
{{author = '_A1_'}, 'CITEREF_A1_2020'},
}
self:assertNotStringContains(citeref2(frame, template, base_args, {chapter = 'CH'}), citeref_p)
self:assertTrue(citeref1(frame, template, base_args, {chapter = 'CH'}), '')
self:assertTrue(citeref1(frame, template, base_args, {author = '_A1_'}), 'CITEREF_A1_2020')
self:assertTrue(citeref1(frame, template, base_args, {contributor = 'C1'}), '')
self:assertTrue(citeref1(frame, template, base_args, {contributor = 'C1', contribution = 'CON'}), '')
-- self:assertTrue()
end
return suite