Module:Date/sandbox/testcases

From Wikimedia Commons, the free media repository
Jump to: navigation, search

Documentation for this module may be created at Module:Date/sandbox/testcases/doc

-- Unit tests for [[Module:Date/sandbox]] date function. Click talk page to run tests.
local p = require('Module:UnitTests')
 

function p:test_Date_languages()
-- Test the Module:Date/sandbox|Date function by comparing to the "template only" version of {{date}} template, preserved as {{date/old}}
-- The tests involving time use {{date/test}} which combines old date and time templates

	-- test time YYYY-MM-DD (2010-01-09) for different languages
	self:preprocess_equals_preprocess_many(
		'{{#invoke:Date/sandbox|Date|year=2010|month=01|day=09|lang=', '}}',
		'{{Date/old|2010|01|09|4=','}}', {
			{'en'}, 
			{'de'}, 
			{'es'}, 
			{'pl'}, 
			--{'ru'}, - someone requested changes to the format of the ru version
			{'cs'}, 
			{'ja'}, 
			{'eo'}, 
			{'hu'}, 
			{'hr'}, 
			{'ia'}, 
			{'lt'}, 
			{'ko'}, 
			{'hi'}, 
			{'pa'}, 
			{'fi'}, 
			{'fr'}, 
			{'ga'}, 
			{'lv'}, 
			{'mk'}, 
			{'ml'}, 
			{'oc'}, 
			{'sr'}, 
			{'th'}, 
			{'vi'}, 
			{'he'}, 
			{'bn'}, 
			{'bpy'}, 
			{'mr'}, 
			{'new'}, 
			{'kn'}, 
			--{'ar'}, -- old {{date}} was incorect (?)
	} )
	self:preprocess_equals_preprocess_many(
		'{{#invoke:Date/sandbox|Date|year=2010|month=09|day=01|lang=', '}}',
		'{{Date/old|2010|09|01|4=','}}', {
			{'fr'}, 
			{'ga'}, 
	} )

    -- test time in YYYY-MM (999-02) format for different languages
    self:preprocess_equals_preprocess_many(
		'{{#invoke:Date/sandbox|Date|year=999|month=02|lang=', '}}',
		'{{Date/old|999|02||4=','}}', {
			{'en'}, 
			{'de'}, 
			{'es'}, 
			{'pl'}, 
			{'ru'}, 
			{'cs'}, 
			{'ja'}, 
			{'eo'}, 
			{'hu'}, 
			{'hr'}, 
			{'ia'}, 
			{'lt'}, 
			{'ko'}, 
			{'fa'}, 
			{'hi'}, 
			{'pa'}, 
			{'fi'}, 
			{'fr'}, 
			{'ga'}, 
			{'lv'}, 
			{'mk'}, 
			{'ml'}, 
			{'oc'}, 
			{'sr'}, 
			{'th'}, 
			{'vi'}, 
			{'he'}, 
			--{'bn'},	-- old {{date}} was incorect (?): extra space due to RTL issue
			--{'bpy'},	-- old {{date}} was incorect (?): extra space due to RTL issue
			--{'mr'},	-- old {{date}} was incorect (?): extra space due to RTL issue
			--{'new'},	-- old {{date}} was incorect (?): extra space due to RTL issue
			--{'kn'},  	-- old {{date}} was incorect (?): extra space due to RTL issue
	} )

	-- test time in MM-DD (04-03) format for different languages
	self:preprocess_equals_preprocess_many(
		'{{#invoke:Date/sandbox|Date|month=04|day=03|lang=', '}}',
		'{{Date/old||04|03|4=','}}', {
			{'en'}, 
			{'de'}, 
			{'es'}, 
			{'pl'}, 
			{'ru'}, 
			{'cs'}, 
			{'ja'}, 
			{'eo'}, 
			{'hu'}, 
			{'hr'}, 
			{'ia'}, 
			{'lt'}, 
			{'ko'}, 
			{'fa'}, 
			{'hi'}, 
			{'pa'}, 
			{'fi'}, 
			{'fr'}, 
			{'ga'}, 
			{'lv'}, 
			{'mk'}, 
			{'ml'}, 
			{'th'}, 
			{'he'}, 
			--{'oc'}, 	-- old {{date}} was incorect (?): the part coupling it with year is present
			--{'sr'}, 	-- old {{date}} was incorect (?): the part coupling it with year is present
			--{'vi'}, 	-- old {{date}} was incorect (?): the part coupling it with year is present
			--{'bn'}, 	-- old {{date}} was incorect (?): the part coupling it with year is present
			--{'bpy'}, 	-- old {{date}} was incorect (?): the part coupling it with year is present
			--{'mr'}, 	-- old {{date}} was incorect (?): the part coupling it with year is present
			--{'new'}, 	-- old {{date}} was incorect (?): the part coupling it with year is present
			--{'kn'}, 	-- old {{date}} was incorect (?): the part coupling it with year is present
	} )

	-- test time YYYY-MM-DD HH:MM:SS (1943-05-25 15:28:37) for different languages
	self:preprocess_equals_preprocess_many(
		'{{#invoke:Date/sandbox|Date|year=1943|month=05|day=25|hour=15|minute=28|second=37|class=|lang=', '}}',
		'{{Date/test|1=1943|2=05|3=25|4=15|5=28|6=37|class=|lang=','}}', {
			{'en'}, 
			{'de'}, 
			{'es'}, 
			{'pl'}, 
			--{'ru'}, someone requested changes to the ru version
			{'cs'}, 
			{'ja'}, 
			{'eo'}, 
			{'hu'}, 
			{'hr'}, 
			{'ia'}, 
			{'lt'}, 
			{'ko'}, 
			{'fa'}, 
			{'hi'}, 
			{'pa'}, 
			{'fi'}, 
			{'fr'}, 
			{'ga'}, 
			{'lv'}, 
			{'mk'}, 
			{'ml'}, 
			{'oc'}, 
			{'sr'}, 
			--{'vi'}, 
			{'bn'}, 
			{'bpy'}, 
			{'mr'}, 
			{'new'}, 
			{'kn'}, 
			--{'th'}, 	-- old {{date}} was incorect (?): time was using local numerals, while rest of the date did not
			--{'mn'}, 	-- old {{date}} was incorect (?): time was using local numerals, while rest of the date did not
			--{'te'}, 	-- old {{date}} was incorect (?): time was using local numerals, while rest of the date did not
	} )

	-- test time YYYY-MM-DD HH:MM (1943-06-25 15:28) for different languages
	self:preprocess_equals_preprocess_many(
	'{{#invoke:Date/sandbox|Date|year=1943|month=06|day=25|hour=15|minute=28|class=|lang=', '}}',
	'{{Date/test|1=1943|2=06|3=25|4=15|5=28|class=|lang=','}}', {
			{'en'}, 
			{'de'}, 
			{'es'}, 
			{'pl'}, 
	} )
	
	--test time YYYY-MM-DD HH:MM:SS (1943-07-25 15:28:37) for different RTL languages
	self:preprocess_equals_preprocess_many(
	'<div dir="rtl" >{{#invoke:Date/sandbox|Date|year=1943|month=07|day=25|hour=15|minute=28|second=37|class=|lang=', '}}</div>',
	'<div dir="rtl" >{{Date/test|1=1943|2=07|3=25|4=15|5=28|6=37|class=|lang=','}}</div>', {
			{'he'}, 
			{'fa'}, 
			--{'glk'}, 	-- old {{date}} was incorect (?): time was using local numerals, while rest of the date did not
			--{'mzn'}, 	-- old {{date}} was incorect (?): time was using local numerals, while rest of the date did not
			--{'ur'}, 	-- old {{date}} was incorect (?): time was using local numerals, while rest of the date did not
	} )
	
	-- test time YYYY (1939) for different languages
	self:preprocess_equals_preprocess_many(
		'{{#invoke:Date/sandbox|Date|year=1939|lang=', '}}',
		'{{Date/old|1939|||4=','}}', {
			{'en'}, 
			--{'vi'}, 
			{'zh'}, 
			{'ko'}, 
			--{'hu'}, 
			{'lt'}, 
			{'lv'}, 
			{'bpy'}, 
			{'mr'}, 
			{'new'}, 
	} )

	-- test time in YYYY-MM (1999-08) format for different slavic languages (force genitive case)
	self:preprocess_equals_preprocess_many(
		'{{#invoke:Date/sandbox|Date|year=1999|month=08|lang=', '|case=gen}}',
		'{{Date/old|1999|08||4=','|form=gen}}', {
			{'pl'}, 
			{'ru'}, 
			{'cs'}, 
			{'sk'}, 
			{'sl'}, 
			{'fi'}, 
			{'en'}, 
	} )
	
	-- test time in YYYY-MM (1999-09) format for different slavic languages (force instrumental case)
	self:preprocess_equals_preprocess_many(
		'{{#invoke:Date/sandbox|Date|year=1999|month=09|lang=', '|case=ins}}',
		'{{Date/old|1999|09||4=','|form=ins}}', {
			{'pl'}, 
			{'cs'}, 
			{'sk'},
			{'sl'}, 
			{'ru'}, 
	} )

	-- test time in YYYY-MM (1999-10) format for different slavic languages (force locative case)
	self:preprocess_equals_preprocess_many(
		'{{#invoke:Date/sandbox|Date|year=1999|month=10|lang=', '|case=loc}}',
		'{{Date/old|1999|10||4=','|form=loc}}', {
			{'pl'}, 
			{'cs'}, 
			{'sk'},
			{'sl'}, 
	} )

	-- test time in YYYY-MM (1999-11) format for finish language (force several cases)
	self:preprocess_equals_preprocess_many(
		'{{#invoke:Date/sandbox|Date|year=1999|month=11|lang=fi|case=','}}',
		'{{Date/old|1999|11||4=fi|form=', '}}', {
			{'gen'}, 
			{'ptv'}, 
			{'ine'}, 
			{'ela'}, 
			{'ill'}, 
	} )
end

function p:test_Date_inputs()

	self:preprocess_equals_preprocess_many('{{#invoke:Date/sandbox|Date|', '|lang=en}}','{{Date/old|','|4=en}}', {
		{'month=02','|02'}, 													-- test month-only format
		{'year=1990|month=02','1990|02'}, 										-- test month formats
		{'year=1990|month=Oct|day=01|class=','1990|Oct|01|class='}, 			-- test month formats
		{'year=1990|month=December|day=01|class=','1990|December|01|class='}, 	-- test month formats
		{'year=1990|day=01','1990'}, 												-- test missing month case
		{'year=1990|month=09|day=01|hour=08','1990|09|01'}, 					-- test incomplete time (no minutes or seconds) case
		{'year=1990|month=09|day=01|hour=08|second=59','1990|09|01'}, 			-- test incomplete time (no minutes) case
		{'year=999' , '999'},													-- test leading zero trimming
		{'year=99'  , '0099'},													-- test leading zero trimming
		{'year=1'   , '0001'},													-- test leading zero trimming
		{'year=0'   , '0000'},													-- test leading zero trimming
		{'year=999|trim_year=no' , '0999'},										-- test leading zero trimming and trim_year parameter
		{'year=99|trim_year=yes' , '99'},										-- test leading zero trimming and trim_year parameter
	} )
	-- test Thai solar calendar dates and formats
	self:preprocess_equals_preprocess_many('{{#invoke:Date/sandbox|Date|', '|lang=th}}','{{Date/old|','|4=th}}', {
		{'year=2010|month=09|day=01','2010|09|01'}, 
		{'year=1930|month=09|day=01','1930|09|01'}, 
		{'year=1940|month=03','1940|03|'}, 
		{'year=1940|month=04','1940|04|'}, 
		{'year=1941|month=03','1941|03|'}, 
		{'year=1941|month=04','1941|04|'}, 
		{'year=1950','1950||'}, 
		{'year=1900','1900||'}, 
	} )

	self:preprocess_equals_preprocess_many('{{#invoke:Date/sandbox|Date|', '|class=}}','','', {
		--{'year=1941|month=04|lang=th',      'เมษายน พ.ศ. 2484'},
		--{'year=1941|month=03|lang=th',      'มีนาคม พ.ศ. 2484'},
		--{'year=1940|month=04|lang=th',      'เมษายน พ.ศ. 2483'},
		--{'year=1940|month=03|lang=th',      'มีนาคม พ.ศ. 2482'},
		--{'year=1939|month=04|lang=th',      'เมษายน พ.ศ. 2482'},
		--{'year=1939|month=03|lang=th',      'มีนาคม พ.ศ. 2481'},
		{'year=2009|month=01|day=09|hour=15|minute=28|second=37|lang=qu',      '9 ñiqin inirupi 2009 watapi, 15:28:37'},
		{'year=2009|month=01|day=09|lang=qu',      '9 ñiqin inirupi 2009 watapi'},
		{'year=2009|month=01|lang=qu',      'inirupi 2009 watapi'},
		{'year=2009|month=01|lang=qu|case=nom',      'iniru 2009 watapi'},
		{'year=2009|month=01|lang=qu|case=gen',      'inirupi 2009 watapi'},
		{'month=01|day=09|lang=qu',      '9 ñiqin inirupi'},
		{'month=01|lang=qu',      'iniru'},
		{'year=2009|lang=qu',      '2009'},
	} )

end

return p