Jump to content

Module:Citation/CS1/testcases/errors

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Trappist the monk (talk | contribs) at 23:51, 10 June 2020. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
-- 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



--[[--------------------------< T E S T _ I N V I S I B L E _ C H A R >----------------------------------------
]]

function p:test_invisible_char()
    self:preprocess_equals_preprocess_many(
    	'{{cite book/new |', '}}', '{{cite book |', '}}',
		{
			{'title=Title\239\191\189'},										-- replacement char - has_invisible_chars()
			{'title=Title\127UNIQ--spoof-000000-QINU\127'},						-- spoof a stripmarker so that comparison compares the same thing; <spoof></spoof> does not exist so not replaced with content
		},
		{nowiki=false, templatestyles=true}
	)
end


--[[--------------------------< T E S T _ I N V A L I D _ P A R A M _ V A L >----------------------------------
]]

function p:test_invalid_param_val()
    self:preprocess_equals_preprocess_many(
    	'{{cite book/new |title=Title |', '}}', '{{cite book |title=Title |', '}}',
		{
			{'author=Black AB |display-authors=etalia'},						-- get_display_names()
			{'mode=cs3'},														-- is_valid_parameter_value()
		},
		{nowiki=false, templatestyles=true}
	)
end


--[[--------------------------< T E S T _ F O R M A T _ M I S S I N G _ U R L >--------------------------------
]]

function p:test_format_missing_url()
    self:preprocess_equals_preprocess_many(
    	'{{cite book/new |title=Title |', '}}', '{{cite book |title=Title |', '}}',
		{
			{'format=abc'},														-- style_format()
			{'archive-format=def'},
			{'chapter-format=ghi'},
		},
		{nowiki=false, templatestyles=true}
	)
end


--[[--------------------------< T E S T _ F I R S T _ M I S S I N G _ L A S T >--------------------------------
]]

function p:test_first_missing_last()
    self:preprocess_equals_preprocess_many(
    	'{{cite book/new |title=Title |', '}}', '{{cite book |title=Title |', '}}',
		{
			{'editor-first=AB'},												-- extract_names()
		},
		{nowiki=false, templatestyles=true}
	)
end


--[[--------------------------< T E S T _ E T A L >------------------------------------------------------------
]]

function p:test_etal()
    self:preprocess_equals_preprocess_many(
    	'{{cite book/new |title=Title |', '}}', '{{cite book |title=Title |', '}}',
		{
			{'editor=Black AB; et al'},											-- name_has_etal()
			{'editor=Black AB, et al'},
			{'editor=Black AB et al'},
			{'editor=Black AB "et al"'},
			{'editor=Black AB \'et al\''},
			{'editor=Black AB et. al.'},
			{'editor=Black AB ET AL'},
			{'editor=Black AB EtAl'},
			{'editor=Black AB, \'\'et alia.\'\''},
			{'editor=Black AB; and others'},
			{'editor=Black AB; [[et al]]'},
			{'editor=Black AB; [et al]'},
			{'editor=Black AB; (et al)'},
		},
		{nowiki=false, templatestyles=true}
	)
end


--[[--------------------------< T E S T _ E M P T Y _ C I T A T I O N >----------------------------------------
]]

function p:test_empty_citation()
    self:preprocess_equals_preprocess_many(
    	'{{cite book/new', '}}', '{{cite book', '}}',
		{
			{''},																-- citation()
		},
		{nowiki=false, templatestyles=true}
	)
end


--[[--------------------------< T E S T _ D O I B R O K E N _ M I S S I N G _ D O I >--------------------------
]]

function p:test_doibroken_missing_doi()
    self:preprocess_equals_preprocess_many(
    	'{{cite book/new |title=Title |', '}}', '{{cite book |title=Title |', '}}',
		{
			{'doi-broken=June 2020'},																-- citation()
		},
		{nowiki=false, templatestyles=true}
	)
end


--[[--------------------------< T E S T _ D E P R E C A T E D _ P A R A M S >----------------------------------

this here for completeness; can't test deprecated param error messaging without actual deprecated parameters; at
this writing, 2020-06-10 there are no deprecated parameters

]]

function p:test_deprecated_params()
    self:preprocess_equals_preprocess_many(
    	'{{cite book/new |title=Title |', '}}', '{{cite book |title=Title |', '}}',
		{
			{''},																-- citation()
		},
		{nowiki=false, templatestyles=true}
	)
end


--[[--------------------------< T E S T _ C O N T R I B U T O R _ M I S S I N G _ R E Q U I R E D _ P A R A M >
]]

function p:test_contributor_missing_required_param()
    self:preprocess_equals_preprocess_many(
    	'{{cite book/new |title=Title |contributor=Contributor |', '}}', '{{cite book |title=Title |contributor=Contributor |', '}}',
		{
			{'contribution=Contribution'},										-- citation0()
			{'author=Author'},													-- citation0()
		},
		{nowiki=false, templatestyles=true}
	)
end


--[[--------------------------< T E S T _ C O N T R I B U T O R _ I G N O R E D >------------------------------
]]

function p:test_contributor_ignored()
    self:preprocess_equals_preprocess_many(
    	'{{cite journal/new |title=Title |contributor=Contributor |journal= Journal |', '}}', '{{cite journal |title=Title |contributor=Contributor |journal= Journal |', '}}',
		{
			{''},																-- citation0()
		},
		{nowiki=false, templatestyles=true}
	)
end


--[[--------------------------< T E S T _ C L A S S _ I G N O R E D >------------------------------------------
]]

function p:test_class_ignored()
    self:preprocess_equals_preprocess_many(
    	'{{cite arxiv/new |title=Title |author=Author |', '}}', '{{cite arxiv |title=Title |author=Author |', '}}',
		{
			{'arxiv=abc.de/9901333 |class=abc'},								-- arxiv() (~/Identifiers)
		},
		{nowiki=false, templatestyles=true}
	)
end


--[[--------------------------< T E S T _ C I T E _ W E B _ U R L >--------------------------------------------
]]

function p:test_cite_web_url()
    self:preprocess_equals_preprocess_many(
    	'{{cite web/new |', '}}', '{{cite web |', '}}',
		{
			{'title=Title'},													-- citation0()
		},
		{nowiki=false, templatestyles=true}
	)
end


--[[--------------------------< T E S T _ C I T E _ W E B _ U R L _ 2 >----------------------------------------
]]

function p:test_cite_web_url_2()
    self:preprocess_equals_preprocess_many(
    	'{{citation/new |', '}}', '{{citation |', '}}',
		{
			{'title=Title |website=Website'},									-- citation0()
			{'title=Title |script-website=ja:Website'},							-- citation0()
		},
		{nowiki=false, templatestyles=true}
	)
end



return p
--{{cite arXiv |last=Leinster |first=Tom |date=2007 |title=The Euler characteristic of a category as the sum of a divergent series |eprint=0707.0835 |class=math.CT}}