--[=[  Unit tests for Module:Citation/CS1/Date validation.  Click talk page to run tests.  ]=]  local p = require('Module:UnitTests') --[[--------------------------< Y M X _ D A T E S >------------------------------------------------------------ ]] --[[--------------------------< Q Y _ D A T E S >-------------------------------------------------------------- ]]  function p:test_qy_dates()     self:preprocess_equals_preprocess_many(     	'', '', 		{ 			{'date=First Quarter 96'},											-- invalid year 			{'date=First Quarter 5500'},										-- invalid year 			{'date=1st Quarter 1980'},											-- invalid quarter 			{'date=first Quarter 1980'},										-- invalid quarter 			{'date=First quarter 1980'},										-- invalid quarter 			{'date=First Quarter, 1980'},										-- extraneous comma 			{'date=First Quarter1980'},											-- missing space 			{'date=FirstQuarter 1980'},											-- missing space 			{'date=First Quarter 2000'}, 			{'date=Second Quarter 2000'}, 			{'date=Third Quarter 2000'}, 			{'date=Fourth Quarter 2000'}, 		}, 		{nowiki=false, templatestyles=true} 	) end  --[[--------------------------< P R O P E R _ N A M E _ Y E A R _ D A T E S >---------------------------------- ]]  function p:test_proper_name_year_dates()     self:preprocess_equals_preprocess_many(     	'', '', 		{ 			{'date=Christmas 96'},												-- invalid year 			{'date=Christmas 5500'},											-- invalid year 			{'date=Xmas 1980'},													-- invalid proper name 			{'date=christmas 1980'},											-- invalid proper name 			{'date=easter 1980'},												-- invalid proper name 			{'date=Christmas, 1980'},											-- extraneous comma 			{'date=Cristmas1980'},												-- missing space 			{'date=Christmas 2000'}, 			{'date=Easter 2000'}, 		}, 		{nowiki=false, templatestyles=true} 	) end  --[[--------------------------< M M Y _ D A T E S >------------------------------------------------------------ ]]  function p:test_mmy_dates()     self:preprocess_equals_preprocess_many(     	'', '', 		{ 			{'date=October–November 96'},										-- invalid year 			{'date=October–November 5500'},										-- invalid year 			{'date=Oktober–November 1980'},										-- invalid 1st month 			{'date=Oktober–Novembre 1980'},										-- invalid 2nd month 			{'date=october–November 1980'},										-- invalid 1st month 			{'date=Sept–Nov 1980'},												-- invalid 2nd month 			{'date=sep–Nov 1980'},												-- invalid 1st month 			{'date=Sep–nov 1980'},												-- invalid 2nd month 			{'date=Oct–November 1980'},											-- mixed style 			{'date=October–Nov 1980'},											-- mixed style 			{'date=Summer–November 1980'},										-- mixed types 			{'date=October–Winter 1980'},										-- mixed types 			{'date=October–November, 1980'},									-- extraneous comma 			{'date=October –November 1980'},									-- extraneous space 			{'date=October– November 1980'},									-- extraneous space 			{'date=October–November1980'},										-- missing space 			{'date=October-October 1980'},										-- same months 			{'date=October-November 1980'},										-- hyphen 			{'date=January–February 2000'}, 		}, 		{nowiki=false, templatestyles=true} 	) end  --[[--------------------------< S S Y _ D A T E S >------------------------------------------------------------ ]]  function p:test_ssy_dates()     self:preprocess_equals_preprocess_many(     	'', '', 		{ 			{'date=Spring–Summer 96'},											-- invalid year 			{'date=Spring–Summer 5500'},										-- invalid year 			{'date=spring–Summer 1980'},										-- invalid 1st season 			{'date=Spring–summer 1980'},										-- invalid 2nd season 			{'date=Spring–Spring 1980'},										-- same season 			{'date=Autumn–Fall 1980'},											-- same season 			{'date=Fall–Autumn 1980'},											-- same season 			{'date=Spring–Summer, 1980'},										-- extraneous comma 			{'date=Spring –Summer 1980'},										-- extraneous space 			{'date=Spring– Summer 1980'},										-- extraneous space 			{'date=Spring–Summer1980'},											-- missing space 			{'date=Spring-Summer 1980'},										-- hyphen 			{'date=Spring–Summer 2000'}, 			{'date=Spring–Autumn 2000'}, 			{'date=Spring–Fall 2000'}, 			{'date=Spring–Winter 2000'},  			{'date=Summer–Autumn 2000'}, 			{'date=Summer–Fall 2000'}, 			{'date=Summer–Winter 2000'}, 			{'date=Summer–Spring 2000'},  			{'date=Autumn–Winter 2000'}, 			{'date=Autumn–Spring 2000'}, 			{'date=Autumn–Summer 2000'},  			{'date=Fall–Winter 2000'}, 			{'date=Fall–Spring 2000'}, 			{'date=Fall–Summer 2000'},  			{'date=Winter–Spring 2000'}, 			{'date=Winter–Summer 2000'}, 			{'date=Winter–Autumn 2000'}, 			{'date=Winter–Fall 2000'}, 		}, 		{nowiki=false, templatestyles=true} 	) end  --[[--------------------------< M Y M Y _ D A T E S >---------------------------------------------------------- ]]  function p:test_mymy_dates()     self:preprocess_equals_preprocess_many(     	'', '', 		{ 			{'date=October 95 – November 1996'},								-- invalid 1st year 			{'date=October 1995 – November 96'},								-- invalid 2nd year 			{'date=October 5500 – November 1996'},								-- invalid 1st year 			{'date=October 1995 – November 5500'},								-- invalid 2nd year 			{'date=Oktober 1979 – November 1980'},								-- invalid 1st month 			{'date=October 1979 – Novembre 1980'},								-- invalid 2nd month 			{'date=october 1979 – November 1980'},								-- invalid 1st month 			{'date=October 1979 – november 1980'},								-- invalid 2nd month 			{'date=Sept 1979 – Oct 1980'},										-- invalid 1st month 			{'date=Sep 1979 – Okt 1980'},										-- invalid 2nd month 			{'date=sep 1979 – Oct 1980'},										-- invalid 1st month 			{'date=October, 1979 – November 1980'},								-- extraneous comma 			{'date=October 1979, – November 1980'},								-- extraneous comma 			{'date=October 1979 – November, 1980'},								-- extraneous comma 			{'date=October1979 – November 1980'},								-- missing space 			{'date=October 1979– November 1980'},								-- missing space 			{'date=October 1979 –November 1980'},								-- missing space 			{'date=October 1979 – November1980'},								-- missing space 			{'date=Oct 1979 – November 1980'},									-- mixed month style 			{'date=October 1979 – Nov 1980'},									-- mixed month style 			{'date=September 1980 – October 1979'},								-- invalid year order 			{'date=October 1979 – October 1979'},								-- missing space 			{'date=October 1979 - November 1980'},								-- hyphen 			{'date=January 1979 – February 2000'}, 		}, 		{nowiki=false, templatestyles=true} 	) end  --[[--------------------------< S Y Y _ D A T E S >------------------------------------------------------------ ]]  function p:test_syy_dates()     self:preprocess_equals_preprocess_many(     	'', '', 		{ 			{'date=Summer 95–96'},												-- invalid 1st year 			{'date=Summer 5500–01'},											-- invalid 1st year 			{'date=Summer 1995–97'},											-- invalid 2nd year 			{'date=Summer 1995–1997'},											-- invalid 2nd year 			{'date=Summer 1995–95'},											-- same year 			{'date=Summer 1995–1995'},											-- same year 			{'date=Spring 1995–96'},											-- invalid season 			{'date=Spring 1995–1996'},											-- invalid season 			{'date=Autumn 1995–96'},											-- invalid season 			{'date=Autumn 1995–1996'},											-- invalid season 			{'date=Fall 1995–96'},												-- invalid season 			{'date=Fall 1995–1996'},											-- invalid season 			{'date=Summer 1995–96'}, 			{'date=Summer 1995–1996'}, 			{'date=Winter 1995–96'}, 			{'date=Winter 1995–1996'}, 		}, 		{nowiki=false, templatestyles=true} 	) end  --[[--------------------------< Y Y _ D A T E S >-------------------------------------------------------------- ]]  function p:test_yy_dates()     self:preprocess_equals_preprocess_many(     	'', '', 		{ 			{'date=99–100'},													-- invalid 1st year 			{'date=5500–100'},													-- invalid 1st year 			{'date=1995–5500'},													-- invalid 2nd year 			{'date=1995–997'},													-- invalid 2nd year 			{'date=1995–1995'},													-- same year 			{'date=100–99'},													-- invalid 2nd year 			{'date=995–997'}, 			{'date=995–1997'}, 			{'date=1995–1997'}, 		}, 		{nowiki=false, templatestyles=true} 	) end  --[[--------------------------< Y 4 Y 2 _ D A T E S >---------------------------------------------------------- ]]  function p:test_y4y2_dates()     self:preprocess_equals_preprocess_many(     	'', '', 		{ 			{'date=999–00'},													-- invalid 1st year 			{'date=5500–100'},													-- invalid 1st year 			{'date=1995–5500'},													-- invalid 2nd year 			{'date=2000–05'},													-- invalid range 			{'date=1999–05'},													-- invalid range 			{'date=1995–95'},													-- same year 			{'date=1995–94'},													-- invalid 2nd year 			{'date=1995–96'}, 		}, 		{nowiki=false, templatestyles=true} 	) end  --[[--------------------------< Y _ D A T E S >---------------------------------------------------------------- ]]  function p:test_y_dates()     self:preprocess_equals_preprocess_many(     	'', '', 		{ 			{'date=99'},														-- invalid year 			{'date=5500'},														-- invalid year 			{'date=995'}, 			{'date=2000'}, 		}, 		{nowiki=false, templatestyles=true} 	) end  --[[--------------------------< Y E A R _ D A T E _ M I S M A T C H >------------------------------------------ ]]  function p:test_year_date_mismatch()     self:preprocess_equals_preprocess_many(     	'', '', 		{ 			{'date=2020-06-13 |year=2020a'},									-- valid: year has disambiguator 			{'date=2020-06-13 |year=2002a'},									-- mismatch 			{'date=2020-06-13 |year=2020'},										-- redundant year match 			{'date=2020-06-13 |year=2002'},										-- mismatch 			{'date=13 June 2020 |year=2020'},									-- redundant year match 			{'date=13 June 2020 |year=2002'},									-- mismatch 			{'date=June 13, 2020 |year=2020'},									-- redundant year match 			{'date=June 13, 2020 |year=2002'},									-- mismatch 			{'date=13 June 2020 – 30 January 2021 |year=2020'},					-- redundant year match 			{'date=13 June 2020 – 30 January 2021 |year=2021'},					-- redundant year match 			{'date=13 June 2020 – 30 January 2021 |year=2002'},					-- mismatch 			{'date=June 13, 2020 – January 30, 2021 |year=2020'},				-- redundant year match 			{'date=June 13, 2020 – January 30, 2021 |year=2021'},				-- redundant year match 			{'date=June 13, 2020 – January 30, 2021 |year=2002'},				-- mismatch 			{'date=2020–2021 |year=2020'},										-- redundant year match 			{'date=2020–2021 |year=2021'},										-- redundant year match 			{'date=2020–2021 |year=2002'},										-- mismatch 			{'date=2020–21 |year=2020'},										-- redundant year match 			{'date=2020–21 |year=2021'},										-- redundant year match 			{'date=2020–21 |year=2002'},										-- mismatch 			{'date=2020 |year=2020'},											-- redundant year match 			{'date=2020 |year=2002'},											-- mismatch 		}, 		{nowiki=false, templatestyles=true} 	) end  --[[ =======================<< S P E C I A L   C A S E   T E S T I N G >>=============================== ]]  --[[--------------------------< 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 	M - abbreviated month name 	F - full month name 	d - zero-padded day 	j - day without zero-padding  <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 C C E S S - D A T E >-------------------------------------------------------- ]]  function p:test_access_dates()     self:preprocess_equals_preprocess_many(     	'', '', 		{ 			{'access-date=2001-01-14'},											-- invalid date (before Wikipedia) 			{'access-date=January 14, 2001'}, 			{'access-date=14 January 2001'}, 			{'access-date=2001-01-15'},											-- valid date (Wikipedia birthday) 			{'access-date=January 15, 2001'}, 			{'access-date=15 January 2001'}, 			{'access-date=' .. today_plus_offset_get('Y-m-d', '0 days')},		-- valid date (today) 			{'access-date=' .. today_plus_offset_get('Y-m-d', '1 days')},		-- valid date (tomorrow) 			{'access-date=' .. today_plus_offset_get('Y-m-d', '2 days')},		-- invalid date (day after tomorrow) 		}, 		{nowiki=false, templatestyles=true} 	) end  return p