Jump to content

Module:Citation/CS1/testcases/identifiers

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Trappist the monk (talk | contribs) at 15:33, 7 September 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/Identifiers]].

Click talk page to run tests.

]=]

local p = require('Module:UnitTests')


--[[--------------------------< T O D A Y _ P L U S _ O F F S E T _ G E T >------------------------------------

returns date offset from today by <offset> in <format> (#time parser function formatting)
	Y - four digit year
	m - two digit month
	d - two digit day

<offset> must include units: days, months, years

]]

local function today_plus_offset_get (format, offset)
	return mw.getContentLanguage():formatDate(format, 'today ' .. offset and ('+ ' .. offset) or '');
end


--[[--------------------------< A R X I V _ 9 1 0 7 _ 0 7 0 3 >------------------------------------------------
]]

function p:test_arxiv_9107_0703()
    self:preprocess_equals_preprocess_many(
    	'{{cite book/new |title=Title |', '}}', '{{cite book |title=Title |', '}}',
		{
																				-- legitimate date range
			{'arxiv=a.a/9007333'},												-- invalid yymm (fail)
			{'arxiv=a.a/9106333'},												-- invalid yymm (fail)
			{'arxiv=a.a/9107333'},												-- valid yymm (pass)
			{'arxiv=a.a/0703333'},												-- valid yymm (pass)
			{'arxiv=a.a/0704333'},												-- invalid yymm (fail)
			{'arxiv=a.a/0803333'},												-- valid yymm (pass)
																				-- archive & class
			{'arxiv=.a/9107333'},												-- without archive (fail)
			{'arxiv=aa/9107333'},												-- without class (pass)
			
																				-- number
			{'arxiv=aa/910722'},												-- not enough digits (fail)
			{'arxiv=aa/91074444'},												-- too many digits (fail)

																				-- version
			{'arxiv=a.a/9107333v'},												-- missing version number (fail)
			{'arxiv=a.a/9107333v1'},											-- with version number (pass)
		},
		{nowiki=false, templatestyles=true}
	)
end


--[[--------------------------< A R X I V _ 0 7 0 4 _ 1 4 1 2 >------------------------------------------------
]]

function p:test_arxiv_0704_1412()
    self:preprocess_equals_preprocess_many(
    	'{{cite book/new |title=Title |', '}}', '{{cite book |title=Title |', '}}',
		{
																				-- date range
			{'arxiv=0612.4444'},												-- invalid yymm (fail)
			{'arxiv=0703.4444'},												-- invalid yymm (fail)
			{'arxiv=0704.4444'},												-- valid yymm (pass)
			{'arxiv=1412.4444'},												-- valid yymm (pass)
			{'arxiv=1413.4444'},												-- invalid yymm (fail)
			{'arxiv=1501.4444'},												-- invalid yymm (fail)

																				-- number
			{'arxiv=0704.333'},													-- not enough digits (fail)
			{'arxiv=0704.55555'},												-- too many digits (fail)

																				-- version
			{'arxiv=0704.4444v'},												-- missing version number (fail)
			{'arxiv=0704.4444v1'},												-- with version number (pass)
		},
		{nowiki=false, templatestyles=true}
	)
end


--[[--------------------------< A R X I V _ 1 5 0 1 >----------------------------------------------------------
]]

function p:test_arxiv_1501()
    self:preprocess_equals_preprocess_many(
    	'{{cite book/new |title=Title |', '}}', '{{cite book |title=Title |', '}}',
		{
																				-- date range
			{'arxiv=1412.55555'},												-- invalid yymm (fail)
			{'arxiv=1500.55555'},												-- invalid yymm (fail)
			{'arxiv=1501.55555'},												-- valid yymm (pass)
			{'arxiv=1513.55555'},												-- invalid yymm (fail)

																				-- number
			{'arxiv=1501.4444'},												-- not enough digits (fail)
			{'arxiv=1501.666666'},												-- too many digits (fail)

																				-- version
			{'arxiv=1501.4444v'},												-- missing version number (fail)
			{'arxiv=1501.4444v1'},												-- with version number (pass)
		},
		{nowiki=false, templatestyles=true}
	)
end


--[[--------------------------< B I B C O D E >----------------------------------------------------------------
]]

function p:test_bibcode()
	local this_year = today_plus_offset_get ('Y', '0 year');					-- get this year
	
    self:preprocess_equals_preprocess_many(
    	'{{cite book/new |title=Title |', '}}', '{{cite book |title=Title |', '}}',
		{
																				-- years
			{'bibcode=0999a&1.b2.c3.d4..e'},									-- invalid yyyy (fail)
			{'bibcode=1000a&1.b2.c3.d4..e'},									-- valid yyyy (pass)
			{'bibcode=' .. this_year .. 'a&1.b2.c3.d4..e'},						-- valid yyyy (pass)
			{'bibcode=' .. today_plus_offset_get ('Y', '1 year') .. 'a&1.b2.c3.d4..e'},	-- valid yyyy (pass)
			{'bibcode=' .. today_plus_offset_get ('Y', '2 year') .. 'a&1.b2.c3.d4..e'},	-- invalid yyyy (fail)

			{'bibcode=' .. this_year .. '#&1.b2.c3.d4..e'},						-- invalid [5] (fail)
			{'bibcode=' .. this_year .. 'a#1.b2.c3.d4..e'},						-- invalid [6] (fail)
			{'bibcode=' .. this_year .. 'a&#.b2.c3.d4..e'},						-- invalid [7] (fail)
			{'bibcode=' .. this_year .. 'a&1#b2.c3.d4..e'},						-- invalid [8] (fail)
			
			{'bibcode=' .. this_year .. 'a&..b2.c3.d4..e'},						-- ampersand preceeds dot (fail)

			{'bibcode=' .. this_year .. 'a&1.#2.c3.d4..e'},						-- invalid [9] (fail)
			{'bibcode=' .. this_year .. 'a&1.b#.c3.d4..e'},						-- invalid [10] (fail)
			{'bibcode=' .. this_year .. 'a&1.b2#c3.d4..e'},						-- invalid [11] (fail)
			{'bibcode=' .. this_year .. 'a&1.b2.#3.d4..e'},						-- invalid [12] (fail)
			{'bibcode=' .. this_year .. 'a&1.b2.c#.d4..e'},						-- invalid [13] (fail)
			{'bibcode=' .. this_year .. 'a&1.b2.c3#d4..e'},						-- invalid [14] (fail)
			{'bibcode=' .. this_year .. 'a&1.b2.c3.#4..e'},						-- invalid [15] (fail)
			{'bibcode=' .. this_year .. 'a&1.b2.c3.d#..e'},						-- invalid [16] (fail)
			{'bibcode=' .. this_year .. 'a&1.b2.c3.d4#.e'},						-- invalid [17] (fail)
			{'bibcode=' .. this_year .. 'a&1.b2.c3.d4.#e'},						-- invalid [18] (fail)
			{'bibcode=' .. this_year .. 'a&1.b2.c3.d4..#'},						-- invalid [19] (fail)
		},
		{nowiki=false, templatestyles=true}
	)
end


--[[--------------------------< B I O R X I V >----------------------------------------------------------------
]]

function p:test_biorxiv()
	local today = today_plus_offset_get ('Y.m.d', '0 year');					
    self:preprocess_equals_preprocess_many(
    	'{{cite book/new |title=Title |', '}}', '{{cite book |title=Title |', '}}',
		{
																				-- years
			{'biorxiv=10.1100/666666'},											-- invalid prefix (fail)
			{'biorxiv=10.1101/666666'},											-- valid prefix (pass)
			{'biorxiv=11.1101/666666'},											-- invalid prefix (fail)

			{'biorxiv=10.1101/55555'},											-- invalid identifier (fail)
			{'biorxiv=10.1101/7777777'},										-- invalid identifier (fail)
----			
			{'biorxiv=10.1100/2019.12.10.666666'},								-- invalid date (fail)
			{'biorxiv=10.1101/2019.12.11.666666'},								-- valid date (pass)
			{'biorxiv=10.1101/2019.00.11.666666'},								-- invalid date (fail)
			{'biorxiv=10.1101/2019.13.11.666666'},								-- invalid date (fail)
			{'biorxiv=10.1101/2019.12.00.666666'},								-- invalid date (fail)
			{'biorxiv=10.1101/2019.12.32.666666'},								-- invalid date (fail)
			
			{'biorxiv=10.1101/' .. today .. '.666666'},							-- valid date (pass)
			{'biorxiv=10.1101/' .. today_plus_offset_get ('Y.m.d', '1 year') .. '.666666'},	-- valid date (pass)

			{'biorxiv=10.1101/' .. today .. '55555'},							-- invalid identifier (fail)
			{'biorxiv=10.1101/' .. today .. '7777777'},							-- invalid identifier (fail)

			{'biorxiv=10.1101/' .. today .. '.666666v'},							-- valid date (pass)
			{'biorxiv=10.1101/' .. today .. '.666666v1'},							-- valid date (pass)
		},
		{nowiki=false, templatestyles=true}
	)
end


--[[--------------------------< C I T E S E E R X >------------------------------------------------------------
]]

function p:test_citeseerx()
    self:preprocess_equals_preprocess_many(
    	'{{cite book/new |title=Title |', '}}', '{{cite book |title=Title |', '}}',
		{
			{'citeseerx=11.1.1.1234.1234'},										-- invalid site id (fail)
			{'citeseerx=10.0.1.1234.1234'},										-- invalid deployment id (fail)
			{'citeseerx=10.1.0.1234.1234'},										-- invalid type (fail)
			{'citeseerx=10.1.1.0234.1234'},										-- invalid bin (fail)
			{'citeseerx=10.1.1.1234.0234'},										-- invalid record (fail)
			{'citeseerx=10.1.1.1234.1234'},										-- invalid record (fail)
		},
		{nowiki=false, templatestyles=true}
	)
end


--[[--------------------------< D O I >------------------------------------------------------------------------
]]

function p:test_doi()
    self:preprocess_equals_preprocess_many(
    	'{{cite book/new |title=Title |', '}}', '{{cite book |title=Title |', '}}',
		{
			{'doi=10.1000/something'},											-- valid directory indicator (pass)
			{'doi=11.1000/something'},											-- invalid directory indicator (fail)
			{'doi=10.10 00/something'},											-- invalid registrant (fail)
			{'doi=10.5555/something'},											-- invalid registrant (fail)
			{'doi=10.666666/something'},										-- invalid registrant (fail)


	-- < four digit registrant w/o subcode
			{'doi=10.1/something'},												-- invalid registrant (fail)
			{'doi=10.22/something'},											-- invalid registrant (fail)
			{'doi=10.333/something'},											-- invalid registrant (fail)

	-- < four digit registrant w/ subcode
			{'doi=10.1.1/something'},											-- valid registrant (pass)
			{'doi=10.22.1/something'},											-- valid registrant (pass)
			{'doi=10.333.1/something'},											-- valid registrant (pass)

	-- four digit registrant w/o subcode
			{'doi=10.0999/something'},											-- invalid registrant (fail)
			{'doi=10.1000/something'},											-- valid registrant (pass)
			{'doi=10.9999/something'},											-- valid registrant (pass)

	-- four digit registrant w/ subcode
			{'doi=10.0999.1/something'},										-- invalid registrant (fail)
			{'doi=10.1000.1/something'},										-- valid registrant (pass)
			{'doi=10.9999.1/something'},										-- valid registrant (pass)

	-- five digit registrant w/o subcode
			{'doi=10.09999/something'},											-- invalid registrant (fail)
			{'doi=10.10000/something'},											-- valid registrant (pass)
			{'doi=10.49999/something'},											-- valid registrant (pass)
			{'doi=10.50000/something'},											-- invalid registrant (fail)

	-- five digit registrant w/ subcode
			{'doi=10.09999.1/something'},										-- invalid registrant (fail)
			{'doi=10.10000.1/something'},										-- valid registrant (pass)
			{'doi=10.39999.1/something'},										-- valid registrant (pass)
			{'doi=10.40000.1/something'},										-- invalid registrant (fail)

	--terminal punctuation
			{'doi=10.1000/something.'},											-- trailing dot (fail)
			{'doi=10.1000/something,'},											-- trailing comma (fail)

			{'doi=10.1000/some thing'},											-- space character in identifier (fail)

	-- doi-broken date
			{'doi=10.1000/something |doi-broken-date=2020'},					-- valid doi-broken date (pass)
			{'doi=10.1000/something |doi-broken-date=January 1900'},			-- valid doi-broken date (pass)
			{'doi=10.1000/something |doi-broken-date=XXXX'},					-- invalid doi-broken date (fail)
			{'doi=10.1000/something |doi-broken-date=January 3500'},			-- invalid doi-broken date (fail)
		},
		{nowiki=false, templatestyles=true}
	)
end


return p