Hopp til innhold

Modul:Citation/CS1/testcases/anchor

Fra Wikipedia, den frie encyklopedi
Sideversjon per 1. feb. 2021 kl. 02:21 av en>Izno (what will happen with c and n.d.)
Moduldokumentasjon


--[=[
Unit tests for [[Module:Citation/CS1]] anchor and CITEREF creation.

Click talk page to run tests.
]=]

local p = require('Module:UnitTests')

--[[ test_author_mask
Tests to ensure author masks don't corrupt the CITEREF
]]
function p:test_author_mask()
    self:preprocess_equals_preprocess_many(
    	'{{cite book/new |title=T |author=_A1_ |date=2020 |', '}}',
    	'{{cite book |title=T |author=_A1_ |date=2020 |', '}}',
		{
			{'chapter=CH'}, -- no author mask: CITEREF_A1_2020
			{'author-mask=A1'}, -- CITEREF_A1_2020
			{'author-mask1=2'}, -- CITEREF_A1_2020
		},
		{nowiki=false, templatestyles=true}
	)
end

--[[ test_counts
Tests what happens with various counts of contributors, authors, and editors
0 0 0
1 0 0
0 1 0
0 0 1
1 1 0
1 0 1
0 1 1
1 1 1
4 0 0
5 0 0
0 3 0
0 0 2
]]
function p:test_counts()
    self:preprocess_equals_preprocess_many(
    	'{{cite book/new |title=T |year=2020 |', '}}',
    	'{{cite book |title=T |year=2020 |', '}}',
		{
			-- Contributor needs both Contribution and Author to be in the ID
			{'chapter=CH'}, -- no auto CITEREF without people
			{'author=_A1_'}, -- CITEREF_A1_2020
			{'contributor=C1'}, -- no auto CITEREF without contribution and author
			{'contributor=C1 |contribution=CON'}, -- no auto CITEREF without author
			{'editor=_E1_'}, -- CITEREF_E1_2020
			{'author=_A1_ |contributor=_C1_'}, -- CITEREF_A1_2020
			{'author=_A1_ |contributor=_C1_ |contribution=CON'}, -- CITEREF_C1_2020
			{'author=_A1_ |editor=_E1_'}, -- CITEREF_A1_2020
			{'editor=_E1_ |contributor=_C1_'}, -- CITEREF_E1_2020
			{'editor=_E1_ |contributor=_C1_ |contribution=CON'}, -- CITEREF_E1_2020
			{'author=_A1_ |contributor=_C1_ |editor=_E1_'}, -- CITEREF_A1_2020
			{'author=_A1_ |contributor=_C1_ |editor=_E1_ |contribution=CON'}, -- CITEREF_C1_2020
			{'author=_A1_ |author2=A2_ |author3=A3_ |author4=A4_'}, -- CITEREF_A1_A2_A3_A4_2020
			{'author=_A1_ |author2=A2_ |author3=A3_ |author4=A4_ |author5=A5_'}, -- CITEREF_A1_A2_A3_A4_2020
			{'author=_A1_ |contributor=_C1_ |contributor2=C2_ |contributor3=C3_ |contribution=CON'}, -- CITEREF_C1_C2_C3_2020
			{'editor=_E1_ |editor2=E2_'}, -- CITEREF_E1_E2_2020
		},
		{nowiki=false, templatestyles=true}
	)
end
--[[ test_dates
Tests date resolution code, including anchor years.
]]
function p:test_dates()
    self:preprocess_equals_preprocess_many(
    	'{{cite book/new |title=T |author=_A1_ |', '}}',
    	'{{cite book |title=T |author=_A1_ |', '}}',
		{
			{'chapter=CH'}, -- no date: CITEREF_A1 -- UNEXPECTED UNDERSCORE MIA
			{'year=2020'}, -- CITEREF_A1_2020
			{'date=c. 2020'},
			{'date=1 January 2020'}, -- CITEREF_A1_2020
			{'date=1 January 2020a'}, -- CITEREF_A1_2020a -- UNEXPECTED NO TRIM IN DISPLAY
			{'date=1 January 2020 |year=2020'}, -- CITEREF_A1_2020 and maint
			{'date=1 January 2020 |year=2020a'}, -- CITEREF_A1_2020a -- UNEXPECTED MAINT
			{'date=2020-01-01 |year=2020'}, -- CITEREF_A1_2020 and maint
			{'date=2020-01-01 |year=2020a'}, -- CITEREF_A1_2020a
			{'date=n.d.'},
			{'date=nd'},
		},
		{nowiki=false, templatestyles=true}
	)
end

--[[
test_display_names
Tests to ensure display name settings don't corrupt the CITEREF
]]
function p:test_display_names()
    self:preprocess_equals_preprocess_many(
    	'{{cite book/new |title=T |author=_A1_ |author2=_A2_ |date=2020 |', '}}',
    	'{{cite book |title=T |author=_A1_ |author2=_A2_ |date=2020 |', '}}',
		{
			{'chapter=CH'}, -- no display names: CITEREF_A1_A2_2020
			{'display-authors=0'}, -- CITEREF_A1_A2_2020
			{'display-authors=1'}, -- CITEREF_A1_A2_2020
			{'display-authors=etal'}, -- CITEREF_A1_A2_2020
		},
		{nowiki=false, templatestyles=true}
	)
end

--[[ test_ref
Tests what happens for certain values of ref
]]
function p:test_ref()
    self:preprocess_equals_preprocess_many(
    	'{{cite book/new |title=T |author=_A1_ |date=2020 |', '}}',
    	'{{cite book |title=T |author=_A1_ |date=2020 |', '}}',
		{
			{'chapter=CH'}, -- no ref: CITEREF_A1_2020
			{'ref=REF'}, -- REF
			{'ref=harv'}, -- CITEREF_A1_2020 and maint harv
			{'ref=none'}, -- no ID
			{'ref=CITEREF_A1_2020'}, -- CITEREF_A1_2020 and maint default ref
		},
		{nowiki=false, templatestyles=true}
	)
end

return p