Module:DateI18n/sandbox/testcases
මොඩියුල උපදෙස්
local TUT = mw.title.new(mw.getCurrentFrame():getTitle()).basePageTitle -- the title under test
local p = require(TUT.prefixedText)-- the module to be tested
local Date = p._Date
local ScribuntoUnit = require('Module:ScribuntoUnit')
local suite = ScribuntoUnit:new()
function suite:test_01_English()
self:assertEquals( '20 July 1969, 20:17:40', Date({1969,07,20,20,17,40},'en'))
self:assertEquals( '20 July 1969, 20:17', Date({1969,07,20,20,17},'en'))
self:assertEquals( '20 July 1969', Date({1969,07,20,20},'en'))
self:assertEquals( '20 July 1969', Date({1969,07,20},'en'))
self:assertEquals( '20 July 1969', Date({1969,07,20,nil,17,40},'en'))
self:assertEquals( 'July 1969', Date({1969,07},'en'))
self:assertEquals( '1969', Date({1969},'en'))
self:assertEquals( '1969', Date({1969,'','','','',''},'en'))
self:assertEquals( '20 July', Date({nil,07,20},'en'))
self:assertEquals( 'July', Date({nil,07},'en'))
end
function suite:test_02_French()
self:assertEquals( '1<sup>er</sup> juin 1999', Date({1999,6,1},'fr'))
self:assertEquals( '2 juin 1999', Date({1999,6,2},'fr'))
self:assertEquals( '1<sup>er</sup> mai', Date({'',5,1},'fr'))
self:assertEquals( '2 mai', Date({'',5,2},'fr'))
end
function suite:test_03_Catalan()
self:assertEquals( '1r de juny de 1999', Date({1999,6,1},'ca'))
self:assertEquals( '2 de juny de 1999', Date({1999,6,2},'ca'))
self:assertEquals( '1r de maig', Date({'',5,1},'ca'))
self:assertEquals( '2 de maig', Date({'',5,2},'ca'))
end
function suite:test_04_Gallic()
self:assertEquals( '1<sup>ú</sup> Meitheamh 1999', Date({1999,6,1},'ga'))
self:assertEquals( '2 Meitheamh 1999', Date({1999,6,2},'ga'))
self:assertEquals( '1<sup>ú</sup> Bealtaine', Date({'',5,1},'ga'))
self:assertEquals( '2 Bealtaine', Date({'',5,2},'ga'))
end
function suite:test_05_Basque()
self:assertEquals( '1999ko uztailaren 1ea', Date({1999,7,01},'eu'))
self:assertEquals( '1999ko uztailaren 2a', Date({1999,7,02},'eu'))
self:assertEquals( '1999ko uztailaren 11', Date({1999,7,11},'eu'))
self:assertEquals( '1999ko uztailaren 21ea', Date({1999,7,21},'eu'))
self:assertEquals( '1999ko uztailaren 31', Date({1999,7,31},'eu'))
end
function suite:test_06_Thai_solar_calendar()
self:assertEquals( '1 มกราคม พ.ศ. 2484', Date({1941,1,1},'th'))
self:assertEquals( 'มกราคม พ.ศ. 2484', Date({1941,1},'th'))
--self:assertEquals( 'กันยายน พ.ศ. 2483', Date({1940,12},'th'))
self:assertEquals( 'กันยายน พ.ศ. 2484', Date({1941,09},'th'))
self:assertEquals( 'พ.ศ. 2484', Date({1941},'th'))
self:assertEquals( '2482 หรือ 2483', Date({1940},'th'))
end
function suite:test_07_Quechua()
self:assertEquals( '9 ñiqin inirupi 2009 watapi', Date({2009,1,9},'qu'))
self:assertEquals( '9 ñiqin inirupi', Date({nil,1,9},'qu'))
self:assertEquals( 'inirupi 2009 watapi', Date({2009,1},'qu'))
self:assertEquals( 'iniru 2009 watapi', Date({2009,1},'qu','nom'))
end
function suite:test_10_YMD_in_50_languages()
local datevec = {2010,1,9}
self:assertEquals( '9 студзеня 2010', Date(datevec,'be'))
self:assertEquals( '9 студзеня 2010', Date(datevec,'be-tarask'))
self:assertEquals( '9 студзеня 2010', Date(datevec,'be-x-old'))
self:assertEquals( '৯ জানুয়ারি ২০১০', Date(datevec,'bn'))
self:assertEquals( 'জানুয়ারী ৯, মারি ২০১০', Date(datevec,'bpy'))
self:assertEquals( '9 de gener de 2010', Date(datevec,'ca'))
self:assertEquals( '2010 шeран 9 январь', Date(datevec,'ce'))
self:assertEquals( '٩ی کانوونی دووەمی ٢٠١٠', Date(datevec,'ckb'))
self:assertEquals( '9. ledna 2010', Date(datevec,'cs'))
self:assertEquals( '9. januar 2010', Date(datevec,'da'))
self:assertEquals( '9. Januar 2010', Date(datevec,'de'))
self:assertEquals( '9 Ιανουαρίου 2010', Date(datevec,'el'))
self:assertEquals( '9 January 2010', Date(datevec,'en'))
self:assertEquals( 'la 9-a de januaro 2010', Date(datevec,'eo'))
self:assertEquals( '9 de enero de 2010', Date(datevec,'es'))
self:assertEquals( '9. jaanuar 2010', Date(datevec,'et'))
self:assertEquals( '2010ko urtarrilaren 9a', Date(datevec,'eu'))
self:assertEquals( '‏۹ ژانویهٔ ۲۰۱۰‏', Date(datevec,'fa'))
self:assertEquals( '9. tammikuuta 2010', Date(datevec,'fi'))
self:assertEquals( '9 janvier 2010', Date(datevec,'fr'))
self:assertEquals( '9 Eanáir 2010', Date(datevec,'ga'))
self:assertEquals( '9 de xaneiro de 2010', Date(datevec,'gl'))
self:assertEquals( '‏9 בינואר 2010‏', Date(datevec,'he'))
self:assertEquals( '९ जनवरी २०१०', Date(datevec,'hi'))
self:assertEquals( '9. siječnja 2010.', Date(datevec,'hr'))
self:assertEquals( '9. januara 2010', Date(datevec,'hsb'))
self:assertEquals( '2010. január 9.', Date(datevec,'hu'))
self:assertEquals( '9 de januario 2010', Date(datevec,'ia'))
self:assertEquals( '9. janúar 2010', Date(datevec,'is'))
self:assertEquals( '2010年1月9日', Date(datevec,'ja'))
self:assertEquals( 'ಜನವರಿ ೯, ೨೦೧೦', Date(datevec,'kn'))
self:assertEquals( '2010년 1월 9일', Date(datevec,'ko'))
self:assertEquals( '2010 m. sausio 9 d.', Date(datevec,'lt'))
self:assertEquals( '2010. gada 9. janvāris', Date(datevec,'lv'))
self:assertEquals( '9 јануари 2010', Date(datevec,'mk'))
self:assertEquals( '9 ജനുവരി 2010', Date(datevec,'ml'))
self:assertEquals( 'जानेवारी ९, इ.स. २०१०', Date(datevec,'mr'))
self:assertEquals( 'ज्यानुवरी ९, ई सं २०१०', Date(datevec,'new'))
self:assertEquals( '9. januar 2010', Date(datevec,'nn'))
self:assertEquals( '9. januar 2010', Date(datevec,'no'))
self:assertEquals( '9 genièr de 2010', Date(datevec,'oc'))
self:assertEquals( '9 ਜਨਵਰੀ 2010', Date(datevec,'pa'))
self:assertEquals( '9 stycznia 2010', Date(datevec,'pl'))
self:assertEquals( '9 de janeiro de 2010', Date(datevec,'pt'))
self:assertEquals( '9 ñiqin inirupi 2010 watapi', Date(datevec,'qu'))
self:assertEquals( '9 niki Kamaypi 2010 watapi', Date(datevec,'qug'))
self:assertEquals( '9 января 2010', Date(datevec,'ru'))
self:assertEquals( '9. januára 2010', Date(datevec,'sk'))
self:assertEquals( '9. januarja 2010', Date(datevec,'sl'))
self:assertEquals( '9. јануар 2010.', Date(datevec,'sr'))
self:assertEquals( '9 มกราคม พ.ศ. 2553', Date(datevec,'th'))
self:assertEquals( '9 січня 2010', Date(datevec,'uk'))
self:assertEquals( '9 tháng 1 năm 2010', Date(datevec,'vi'))
self:assertEquals( '2010年1月9日', Date(datevec,'zh-hans'))
end
function suite:test_11_YMDHMS()
local datevec = {1569,09,3,20,17,40}
self:assertEquals( '3 September 1569, 20:17:40', Date(datevec,'en'))
self:assertEquals( '1569ko irailaren 3a, 20:17:40', Date(datevec,'eu'))
self:assertEquals( '٣ی ئەیلوولی ١٥٦٩، ٢٠:١٧:٤٠', Date(datevec,'ckb'))
self:assertEquals( '3. septembra 1569 ob 20:17:40', Date(datevec,'sl'))
self:assertEquals( '3 tháng 9 năm 1569 lúc 20:17:40', Date(datevec,'vi'))
end
function suite:test_12_YMDHM()
local datevec = {1569,09,3,20,17}
self:assertEquals( '3 September 1569, 20:17', Date(datevec,'en'))
self:assertEquals( '1569ko irailaren 3a, 20:17', Date(datevec,'eu'))
self:assertEquals( '٣ی ئەیلوولی ١٥٦٩، ٢٠:١٧', Date(datevec,'ckb'))
self:assertEquals( '3. septembra 1569 ob 20:17', Date(datevec,'sl'))
self:assertEquals( '3 tháng 9 năm 1569 lúc 20:17', Date(datevec,'vi'))
end
function suite:test_13_German()
self:assertEquals( '20. Juli 1969, 20:17:40', Date({1969,07,20,20,17,40},'de'))
self:assertEquals( '20. Juli 1969, 20:17', Date({1969,07,20,20,17},'de'))
self:assertEquals( '20. Juli 1969', Date({1969,07,20,20},'de'))
self:assertEquals( '20. Juli 1969', Date({1969,07,20},'de'))
self:assertEquals( '20. Juli 1969', Date({1969,07,20,nil,17,40},'de'))
self:assertEquals( 'Juli 1969', Date({1969,07},'de'))
self:assertEquals( '1969', Date({1969},'de'))
self:assertEquals( '1969', Date({1969,'','','','',''},'de'))
self:assertEquals( '20. Juli', Date({nil,07,20},'de'))
self:assertEquals( 'Juli', Date({nil,07},'de'))
self:assertEquals( '', Date({nil},'de'))
end
function suite:test_outer_function()
-- rest the p.Date(frame) function accessible to template functions
local mod = '{{#invoke:' .. TUT.text .. '| Date'
self:assertSameResult( '9 January 2009, 15:28:37 +03:30', mod..'|year=2009|month=01|day=09|hour=15|minute=28|second=37|tzhour=3|tzmin=30|class=|lang=en}}')
self:assertSameResult( '9 January 2009, 15:28:37', mod..'|year=2009|month=01|day=09|hour=15|minute=28|second=37|class=|lang=en}}')
self:assertSameResult( '25 mai 1943, 15:28:37', mod..'|year=1943|month=05|day=25|hour=15|minute=28|second=37|class=|lang=fr}}')
self:assertSameResult( '<time class="dtstart" datetime="2009-01-09" lang="pl" dir="ltr" style="white-space:nowrap">9 stycznia 2009</time>', mod..'|year=2009|month=01|day=09|class=dtstart|lang=pl}}')
self:assertSameResult( '<time class="dtstart" datetime="2009-01-09" lang="pl" dir="ltr" style="white-space:nowrap">9 styczeń 2009</time>', mod..'|year=2009|month=01|day=09|case=nom|lang=pl}}')
end
function suite:test_class()
self:assertEquals('9 January 2009, 15:28:37', Date({2009,1,9,15,28,37}, 'en', '', ''))
self:assertEquals('<time class="dtstart" datetime="2009-01-09 15:28:37" lang="en" dir="ltr" style="white-space:nowrap">9 January 2009, 15:28:37</time>', Date({2009,1,9,15,28,37}, 'en', '', 'dtstart'))
self:assertEquals('9 January', Date({nil,1,9}, 'en', '', 'dtstart'))
end
function suite:test_timezones()
self:assertEquals('9 January 2009, 15:28:37 +03:30', Date({2009,1,9,15,28,37,3,30}, 'en'))
self:assertEquals('9 January 2009, 15:28:37 −11:00', Date({2009,1,9,15,28,37,-11} , 'en'))
self:assertEquals('ज्यानुवरी ९, ई सं २००९, १५:२८:३७ −११:००', Date({2009,1,9,15,28,37,-11} , 'new'))
end
function suite:test_gramatical_cases()
self:assertEquals( '20 July 1969', Date({1969,07,20},'en',''))
self:assertEquals( '21 lipca 1969', Date({1969,07,21},'pl',''))
self:assertEquals( '22 lipiec 1969', Date({1969,07,22},'pl','nom'))
self:assertEquals( '23 lipca 1969', Date({1969,07,23},'pl','gen'))
self:assertEquals( '24 lipcem 1969', Date({1969,07,24},'pl','ins'))
self:assertEquals( '25 lipcu 1969', Date({1969,07,25},'pl','loc'))
self:assertEquals( '21 июля 1969', Date({1969,07,21},'ru',''))
self:assertEquals( '22 июль 1969', Date({1969,07,22},'ru','nom'))
self:assertEquals( '23 июля 1969', Date({1969,07,23},'ru','gen'))
self:assertEquals( '24 июлем 1969', Date({1969,07,24},'ru','ins'))
self:assertEquals( '25 июле 1969', Date({1969,07,25},'ru','loc'))
self:assertEquals( 'marraskuu 1960', Date({1960,11},'fi',''))
self:assertEquals( 'marraskuu 1961', Date({1961,11},'fi','nom'))
self:assertEquals( 'marraskuun 1962', Date({1962,11},'fi','gen'))
self:assertEquals( 'marraskuuta 1963', Date({1963,11},'fi','ptv'))
self:assertEquals( 'marraskuussa 1964', Date({1964,11},'fi','ine'))
self:assertEquals( 'marraskuusta 1965', Date({1965,11},'fi','ela'))
self:assertEquals( 'marraskuuhun 1966', Date({1966,11},'fi','ill'))
end
function suite:test_year_trimming()
self:assertEquals( '1 September 999', Date({999, 9, 1}, 'en', '', '', true))
self:assertEquals( '2 September 99', Date({ 99, 9, 2}, 'en', '', '', 'true'))
self:assertEquals( '3 September 9', Date({ 9, 9, 3}, 'en', '', '', 1))
self:assertEquals( '4 September 0999', Date({999, 9, 4}, 'en', '', '', false))
self:assertEquals( '5 September 0999', Date({999, 9, 5}, 'en', '', '', 'false'))
self:assertEquals( '6 September 999', Date({999, 9, 6}, 'en', '', '', '100-999'))
self:assertEquals( '7 September 0999', Date({999, 9, 7}, 'en', '', '', '100-990'))
self:assertEquals( '৮ সেপ্টেম্বর ৯৮৭', Date({987, 9, 8}, 'bn', '', '', '1'))
self:assertEquals( 'सप्टेंबर ९, इ.स. ९८७', Date({987, 9, 9}, 'mr', '', '', '1'))
self:assertEquals( 'ಸೆಪ್ಟೆಂಬರ್ ೧೦, ೯೮೭', Date({987, 9,10}, 'kn', '', '', '1'))
end
function suite:test_out_of_range_dates()
self:assertEquals( '20 July 1969, 20:17:40', Date({1969,07,20,20,17,40},'en')) -- correct
self:assertEquals( '20 July 1969, 20:17', Date({1969,07,20,20,17,80},'en')) -- bad second
self:assertEquals( '20 July 1969', Date({1969,07,20,20,67,40},'en')) -- bad minute
self:assertEquals( '20 July 1969', Date({1969,07,20,30,17,40},'en')) -- bad hour
self:assertEquals( 'July 1969', Date({1969,07,80,20,17,40},'en')) -- bad day
self:assertEquals( '1969', Date({1969,13,20,20,17,40},'en')) -- bad month
end
function suite:test_strReplace()
self:assertEquals( 'new old book', p.strReplace('old old book', 'old', 'new'))
self:assertEquals( '"old" new book', p.strReplace('"old" old book', 'old', 'new'))
self:assertEquals( 'my "old" new book', p.strReplace('my "old" old book', 'old', 'new'))
end
function suite:test_clean_datevec()
self:assertDeepEquals( {1969,07,20,20,17,40,3,30}, p.clean_datevec({1969,07,20,20,17,40,3,30}))
self:assertDeepEquals({1969,7,20,20,17,40}, p.clean_datevec({1969,07,20,20,17,40}))
self:assertDeepEquals({1969,7,20,20,17,40}, p.clean_datevec({'1969','07','20','20','17','40'}))
self:assertDeepEquals({1969,7,20,20,17,40}, p.clean_datevec({'1969','July','20','20','17','40'}))
self:assertDeepEquals({1969,7,20,20,17}, p.clean_datevec({1969,7,20,20,17,90})) -- bad second
self:assertDeepEquals({1969,7,20, 20,nil,40}, p.clean_datevec({1969,7,20,20,90,40})) -- bad minute
self:assertDeepEquals({1969,7,20,nil,17,40}, p.clean_datevec({1969,7,20,24,17,40})) -- bad hour
self:assertDeepEquals({1969,7,nil,20,17,40}, p.clean_datevec({1969,7,32,20,17,40})) -- bad day
self:assertDeepEquals({1969,nil,20,20,17,40}, p.clean_datevec({1969,13,20,20,17,40})) -- bad month
self:assertDeepEquals({1968,7,20,20,17}, p.clean_datevec({1968,7,20,20,17,60})) -- bad second
self:assertDeepEquals({1970,6,30,23,59,60}, p.clean_datevec({1970,06,30,23,59,60})) -- leap second
self:assertDeepEquals({1971,12,31,23,59,60}, p.clean_datevec({1971,12,31,23,59,60})) -- leap second
end
function suite:test_getTimestamp()
local function get_datecode(datenum)
local _, datecode = p.getTimestamp(datenum)
return datecode
end
self:assertEquals( 'YMDhms', get_datecode({1961,7,20,20,17,40,3,30}))
self:assertEquals( 'YMDhms', get_datecode({1962,7,20,20,17,40}))
self:assertEquals( 'YMDhm', get_datecode({1963,7,20,20,17}))
self:assertEquals( 'YMD', get_datecode({1964,7,20,nil,17}))
self:assertEquals( 'YMD', get_datecode({1965,7,20,20}))
self:assertEquals( 'YMD', get_datecode({1966,7,20}))
self:assertEquals( 'YM', get_datecode({1967,7,nil,20,17}))
self:assertEquals( 'YM', get_datecode({1968,7,nil,20,nil}))
self:assertEquals( 'YM', get_datecode({1969,7,nil,nil,17}))
self:assertEquals( 'YM', get_datecode({1970,7}))
self:assertEquals( 'Y', get_datecode({1971,nil,20,20,17,40}))
self:assertEquals( 'Y', get_datecode({1971,nil,20,20,nil,40}))
self:assertEquals( 'Y', get_datecode({1971}))
self:assertEquals( 'MDhms', get_datecode({nil,7,20,20,17,40,3,30}))
self:assertEquals( 'MDhms', get_datecode({nil,7,20,20,17,40}))
self:assertEquals( 'MDhm', get_datecode({nil,7,20,20,17}))
self:assertEquals( 'MD', get_datecode({nil,7,20,nil,17}))
self:assertEquals( 'MD', get_datecode({nil,7,20,20}))
self:assertEquals( 'MD', get_datecode({nil,7,20}))
self:assertEquals( 'M', get_datecode({nil,7,nil,20,17}))
self:assertEquals( 'M', get_datecode({nil,7,nil,20,nil}))
self:assertEquals( 'M', get_datecode({nil,7,nil,nil,17}))
self:assertEquals( 'M', get_datecode({nil,7}))
end
function suite:test_1()
end
function suite:test_checkDateValidity()
local check = p.checkDateValidity
self:assertEquals(true, check({1969,2,28}))
self:assertEquals(false, check({1969,2,29}))
self:assertEquals(true, check({1968,2,29}))
self:assertEquals(false, check({2010,2,29}))
self:assertEquals(true, check({2400,2,29}))
self:assertEquals(true, check({-3,2,29}))
self:assertEquals(true, check({100,2,29}))
self:assertEquals(false, check({1969,2,30}))
self:assertEquals(false, check({1969,13,30}))
self:assertEquals(false, check({1969,nil,28}))
end
return suite