Module:Citation/CS1/testcases/errors
Appearance
-- Unit tests for [[Module:Citation/CS1]]. Click talk page to run tests.
local p = require('Module:UnitTests')
function p:test_web()
self:preprocess_equals_preprocess_many(
'{{cite web/new|', '}}',
'{{cite web|', '}}',
{
{ [==[ ]==] },
{ [==[ unrecognized_thing ]==] }, -- finds and then discards unrecognized_thing
{ [==[ unrecognized_thing |unrecognized_thing2 ]==] }, -- finds and then discards unrecognized_things
{ [==[ last = Last |unrecognized_thing ]==] },
{ [==[ last = Last |unrecognized_thing |unrecognized_thing2 ]==] },
{ [==[ unrecognized_parameter = unrecognized ]==] }, -- finds and then discards unrecognized parameter
{ [==[ unrecognized_parameter = unrecognized |unrecognized_parameter2 = unrecognized2 ]==] }, -- finds and then discards unrecognized parameters
{ [==[ last=Last |1=unrecognized1 ]==] },
{ [==[ last=Last |unrecognized_parameter = unrecognized |unrecognized_parameter2 = unrecognized2 ]==] },
},
{nowiki=false, templatestyles=true}
)
end
--[[--------------------------< W I K I L I N K _ I N _ U R L >------------------------------------------------
]]
function p:test_wikilink_in_url()
self:preprocess_equals_preprocess_many(
'{{cite journal/new |journal=Journal |', '}}', '{{cite journal |journal=Journal |', '}}',
{
{''}, -- no pmc, no title, no url, no title-link 0000
{'title-link=Title'}, -- title-link 0001
{'url=//example.com'}, -- url 0010
{'url=//example.com |title-link=Title'}, -- url, title-link 0011
{'title=Title'}, -- title 0100
{'title=Title |title-link=Title'}, -- title, title-link 0101
{'title=Title |url=//example.com'}, -- title, url 0110
{'title=Title |url=//example.com |title-link=Title'}, -- title, url, title-link 0111
{'pmc=12345'}, -- pmc 1000
{'pmc=12345 |title-link=Title'}, -- pmc, title-link 1001
{'pmc=12345 |url=//example.com'}, -- pmc, url 1010
{'pmc=12345 |url=//example.com |title-link=Title'}, -- pmc, url, title-link 1011
{'pmc=12345 |title=Title'}, -- pmc, title 1100
{'pmc=12345 |title=Title |title-link=Title'}, -- pmc, title, title-link 1101
{'pmc=12345 |title=Title |url=//example.com'}, -- pmc, title, url 1110
{'pmc=12345 |title=Title |url=//example.com |title-link=Title'}, -- pmc, title, url, title-link 1111
},
{nowiki=false, templatestyles=true}
)
end
--[[--------------------------< T E S T _ V A U T H O R S >----------------------------------------------------
]]
function p:test_vauthors()
self:preprocess_equals_preprocess_many(
'{{cite book/new |title=Title |', '}}', '{{cite book |title=Title |', '}}',
{
{'vauthors=Black ABC'}, -- too many initials
{'vauthors=Black A-B'}, -- hyphenated initials
{'vauthors=Black AB II'}, -- invalid generational suffix
{'vauthors=Black AB 3d'}, -- invalid generational suffix
{'vauthors=Black, AB, Brown, CD'}, -- improper puncutation
{'vauthors=Black AB; Brown CD'}, -- improper puncutation
{'vauthors=Black AB, Brown CD,'}, -- improper puncutation
{'vauthors=Black AB Brown CD'}, -- missing comma
{'vauthors=Black A B'}, -- spaced initials
},
{nowiki=false, templatestyles=true}
)
end
--[[--------------------------< T E S T _ T R A N S _ M I S S I N G _ T I T L E >------------------------------
]]
function p:test_trans_missing_title()
self:preprocess_equals_preprocess_many(
'{{cite book/new |', '}}', '{{cite book |', '}}',
{
{'trans-title=Trans Title'},
},
{nowiki=false, templatestyles=true}
)
end
--[[--------------------------< T E S T _ T E X T _ I G N O R E D >--------------------------------------------
]]
function p:test_text_ignored()
self:preprocess_equals_preprocess_many(
'{{cite book/new |title=Title |', '}}', '{{cite book |title=Title |', '}}',
{
{'text to be ignored'},
},
{nowiki=false, templatestyles=true}
)
end
--[[--------------------------< T E S T _ S S R N _ M I S S I N G >--------------------------------------------
]]
function p:test_ssrn_missing()
self:preprocess_equals_preprocess_many(
'{{cite ssrn/new |title=Title |', '}}', '{{cite ssrn |title=Title |', '}}',
{
{''},
},
{nowiki=false, templatestyles=true}
)
end
--[[--------------------------< T E S T _ S C R I P T _ P A R A M E T E R >------------------------------------
]]
function p:test_script_parameter()
self:preprocess_equals_preprocess_many(
'{{cite book/new |title=Title |', '}}', '{{cite book |title=Title |', '}}',
{
{'script-title=ja:'}, -- missing title part
{'script-title=ac:script-title'}, -- unknown language code
{'script-title=es:script-title'}, -- invalid language code
{'script-title=script-title'}, -- missing prefix
},
{nowiki=false, templatestyles=true}
)
end
--[[--------------------------< T E S T _ R E D U N D A N T _ P A R A M E T E R S >----------------------------
]]
function p:test_redundant_parameters()
self:preprocess_equals_preprocess_many(
'{{cite book/new |title=Title |', '}}', '{{cite book |title=Title |', '}}',
{
{'type=Type |meduim=Meduim'}, -- argument_wrapper()
{'last=Last |last1=Last1'}, -- extract_names()
{'last=Last |first=First |first1=First1'}, -- extract_names()
{'last=Last |first=First |author-mask=Author-mask |author-mask1=Author-mask1'}, -- extract_names()
{'last=Last |first=First |author-link=Author |author1-link=Author'}, -- extract_names()
{'vauthors=[[Author|Author AA]] |author-link=Author'}, -- parse_vauthors_veditors()
{'vauthors=Black AB |author2=Brown CD'}, -- select_author_editor_source()
{'page=1 |pages=3, 4'}, -- citation0()
},
{nowiki=false, templatestyles=true}
)
end
--[[--------------------------< T E S T _ R E D U N D A N T _ P A R A M E T E R S _ 2 >------------------------
]]
function p:test_redundant_parameters_2()
self:preprocess_equals_preprocess_many(
'{{cite mailinglist/new |title=Title |', '}}', '{{cite mailinglist |title=Title |', '}}',
{
{'mailinglist=Mailinglist |work=work'}, -- argument_wrapper()
},
{nowiki=false, templatestyles=true}
)
end
--[[--------------------------< T E S T _ R E D U N D A N T _ P A R A M E T E R S _ 3 >------------------------
]]
function p:test_redundant_parameters_3()
self:preprocess_equals_preprocess_many(
'{{cite encyclopedia/new |title=Title |', '}}', '{{cite encyclopedia |title=Title |', '}}',
{
{'encyclopedia=Encyclopedia |work=work'}, -- citation0()
},
{nowiki=false, templatestyles=true}
)
end
--[[--------------------------< T E S T _ R E D U N D A N T _ P A R A M E T E R S _ 4 >------------------------
]]
function p:test_redundant_parameters_4()
self:preprocess_equals_preprocess_many(
'{{citation/new |title=Title |', '}}', '{{citation |title=Title |', '}}',
{
{'encyclopedia=Encyclopedia |work=work'}, -- citation0()
},
{nowiki=false, templatestyles=true}
)
end
--[[--------------------------< T E S T _ R E D U N D A N T _ P A R A M E T E R S _ 5 >------------------------
]]
function p:test_redundant_parameters_5()
self:preprocess_equals_preprocess_many(
'{{cite tech report/new |title=Title |', '}}', '{{cite tech report |title=Title |', '}}',
{
{'number=1 |id=ID'}, -- citation0()
},
{nowiki=false, templatestyles=true}
)
end
--[[--------------------------< T E S T _ R E D U N D A N T _ P A R A M E T E R S _ 6 >------------------------
]]
function p:test_redundant_parameters_6()
self:preprocess_equals_preprocess_many(
'{{cite map/new |title=Title |', '}}', '{{cite map |title=Title |', '}}',
{
{'chapter=Chapter |map=Map'}, -- citation0()
{'chapter=Chapter'}, -- citation0()
},
{nowiki=false, templatestyles=true}
)
end
--[[--------------------------< T E S T _ R E D U N D A N T _ P A R A M E T E R S _ 7 >------------------------
]]
function p:test_redundant_parameters_7()
self:preprocess_equals_preprocess_many(
'{{cite episode/new |title=Title |series=Series |', '}}', '{{cite episode |title=Title |series=Series |', '}}',
{
{'season=Season |series-no=Series number'}, -- citation0()
{'minutes=Minutes |time=Time'}, -- citation0()
},
{nowiki=false, templatestyles=true}
)
end
--[[--------------------------< T E S T _ P A R A M E T E R _ I G N O R E D _ S U G G E S T >------------------
]]
function p:test_parameter_ignored_suggest()
self:preprocess_equals_preprocess_many(
'{{cite book/new |title=Title |', '}}', '{{cite book |title=Title |', '}}',
{
{'Chapter=Chapter'}, -- citation() - case
{'pulbisher=Pulbisher'}, -- citation() – misspelled pattern matched
{'pub=Publisher'}, -- citation() – explicit match
},
{nowiki=false, templatestyles=true}
)
end
--[[--------------------------< T E S T _ P A R A M E T E R _ I G N O R E D >----------------------------------
]]
function p:test_parameter_ignored()
self:preprocess_equals_preprocess_many(
'{{cite book/new |title=Title |', '}}', '{{cite book |title=Title |', '}}',
{
{'unknown=unknown'}, -- citation()
{'encyclopedia=Encyclopedia'}, -- citation0() – |encyclopedia= only available in {{cite encyclopdia}} and {{citation}}
},
{nowiki=false, templatestyles=true}
)
end
--[[--------------------------< T E S T _ P A R A M E T E R _ I G N O R E D _ 2 >------------------------------
]]
function p:test_parameter_ignored_2()
self:preprocess_equals_preprocess_many(
'{{cite ssrn/new |title=Title |ssrn=123456 |', '}}', '{{cite ssrn |title=Title |ssrn=123456 |', '}}',
{
{'pulbisher=Pulbisher'}, -- citation() – misspelled pattern matched but suggested param not supported by this template
},
{nowiki=false, templatestyles=true}
)
end
--[[--------------------------< T E S T _ P A R A M E T E R _ I G N O R E D _ 3 >------------------------------
]]
function p:test_parameter_ignored_3()
self:preprocess_equals_preprocess_many(
'{{cite newsgroup/new |title=Title |', '}}', '{{cite newsgroup |title=Title |', '}}',
{
{'newsgroup=sommat.sommat.sommat |publisher=Publisher'}, -- citation0() - |publisher= not supported by {{cite newsgroup}}
},
{nowiki=false, templatestyles=true}
)
end
--[[--------------------------< T E S T _ P A R A M _ H A S _ E X T _ L I N K >--------------------------------
]]
function p:test_param_has_ext_link()
self:preprocess_equals_preprocess_many(
'{{cite book/new |', '}}', '{{cite book |', '}}',
{
{'title=Title //example.com'}, -- check_for_url()
{'title=Title http://example.com'}, -- check_for_url()
{'title=[http://example.com Title]'}, -- check_for_url()
},
{nowiki=false, templatestyles=true}
)
end
--[[--------------------------< T E S T _ P A R A M _ A C C E S S _ R E Q U I R E S _ P A R A M >--------------
]]
function p:test_param_access_requires_param()
self:preprocess_equals_preprocess_many(
'{{cite journal/new |title=Title |journal=Journal |', '}}', '{{cite journal |title=Title |journal=Journal |', '}}',
{
{'url-access=subscription'}, -- citation0()
{'doi-access=free'}, -- extract_id_access_levels() (~/Identifiers)
{'chapter-url-access=subscription'}, -- citation0()
-- {'map-url-access=subscription'}, -- citation0()
},
{nowiki=false, templatestyles=true}
)
end
--[[--------------------------< T E S T _ P A R A M _ A C C E S S _ R E Q U I R E S _ P A R A M _ 2 >----------
]]
function p:test_param_access_requires_param_2()
self:preprocess_equals_preprocess_many(
'{{cite map/new |title=Title |', '}}', '{{cite map |title=Title |', '}}',
{
{'map-url-access=subscription'}, -- citation0()
},
{nowiki=false, templatestyles=true}
)
end
--[[--------------------------< T E S T _ M I S S I N G _ P I P E >--------------------------------------------
]]
function p:test_missing_pipe()
self:preprocess_equals_preprocess_many(
'{{cite book/new |title=Title |url=//example.com |', '}}', '{{cite book |title=Title |url=//example.com |', '}}',
{
{'chapter=Chapter access-date=2020-06-10'}, -- missing_pipe_check()
{'chapter=access-date=2020-06-10'}, -- missing_pipe_check()
},
{nowiki=false, templatestyles=true}
)
end
--[[--------------------------< T E S T _ M I S S I N G _ P E R I O D I C A L >--------------------------------
]]
function p:test_missing_periodical()
self:preprocess_equals_preprocess_many(
'{{cite journal/new |title=Title |', '}}', '{{cite journal |title=Title |', '}}',
{
{''}, -- citation0()
},
{nowiki=false, templatestyles=true}
)
end
--[[--------------------------< T E S T _ M I S S I N G _ P E R I O D I C A L _ 2 >----------------------------
]]
function p:test_missing_periodical_2()
self:preprocess_equals_preprocess_many(
'{{cite magazine/new |title=Title |', '}}', '{{cite magazine |title=Title |', '}}',
{
{''}, -- citation0()
},
{nowiki=false, templatestyles=true}
)
end
--[[--------------------------< T E S T _ M I S S I N G _ N A M E >--------------------------------------------
]]
function p:test_missing_name()
self:preprocess_equals_preprocess_many(
'{{cite book/new |title=Title |', '}}', '{{cite book |title=Title |', '}}',
{
{'author=Black AB |author3=Red EF'}, -- extract_names()
},
{nowiki=false, templatestyles=true}
)
end
return p