Hopp til innhold

Modul:Citation/CS1/testcases/anchor

Fra Wikipedia, den frie encyklopedi
Sideversjon per 30. jan. 2021 kl. 08:42 av en>Izno (add 2020a)
Moduldokumentasjon


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

Click talk page to run tests.
]=]

local p = require('Module:UnitTests')

--[[ 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!)
			{'year=2020'}, -- CITEREF_A1_2020
			{'date=1 January 2020'}, -- CITEREF_A1_2020
			{'date=1 January 2020a'}, -- CITEREF_A1_2020
			{'date=1 January 2020 |year=2020'}, -- CITEREF_A1_2020
			{'date=1 January 2020 |year=2020a'}, -- CITEREF_A1_2020a (and maint)
			{'date=2020-01-01 |year=2020'}, -- CITEREF_A1_2020
			{'date=2020-01-01 |year=2020a'}, -- CITEREF_A1_2020a
		},
		{nowiki=false, templatestyles=true}
	)
end

return p