Module:ISOdate/sandbox/testcases
< Module:ISOdate | sandbox
Lua
CodeDiscussionEditHistoryLinksLink count Subpages:DocumentationTestsResultsSandboxLive code All modules
Test results
[edit] All tests passed.
Name | Expected | Actual | |
---|---|---|---|
![]() |
test_1_ISOyear | ||
![]() |
test_2_ISOdate_basic | ||
![]() |
test_3_ISOdate_odd_dates | ||
![]() |
test_4_ISOdate_not_dates | ||
![]() |
test_5_ISOdate_out_or_range | ||
![]() |
test_6_ISOdate_arguments | ||
![]() |
test_outer |
Code
require('strict')
local TUT = mw.title.new(mw.getCurrentFrame():getTitle()).basePageTitle -- the title under test
local p = require(TUT.prefixedText) -- the module to be tested
local ScribuntoUnit = require('Module:ScribuntoUnit')
local suite = ScribuntoUnit:new()
local Date = require('Module:DateI18n')._Date
local function ISOdate(datestr, lang, case, class, trim_year)
local datestr, succeded = p._ISOdate(datestr, lang, case, class, trim_year)
return datestr
end
local function ISOdate_en(datestr)
local datestr, succeded = p._ISOdate(datestr, 'en', '', '', '100-999')
return datestr
end
function suite:test_outer()
local mod = '{{#invoke:' .. TUT.text .. '| '
self:assertSameResult(p._ISOyear('1999-08-18 08:15:30Z'), mod..'ISOyear|1999-08-18 08:15:30Z}}')
self:assertSameResult(p._ISOdate('1999-08-18 08:15:30Z', 'en', '', 'dtstart', '100-999'), mod..'ISOdate|1999-08-18 08:15:30Z|lang=en}}')
self:assertSameResult(p._ISOdate('1999-08-18 08:15:30Z', 'pl', 'gen', 'test', true), mod..'ISOdate|1999-08-18 08:15:30Z|lang=pl|case=gen|class=test|trim_year=t}}')
end
function suite:test_1_ISOyear()
self:assertEquals('1999', p._ISOyear('1999-08-18 08:15:30Z'))
self:assertEquals('1999', p._ISOyear('1999-08-18 08:15:30'))
self:assertEquals('1999', p._ISOyear('1999-08-18 08:15'))
self:assertEquals('1999', p._ISOyear('1999-08-18'))
self:assertEquals('1999', p._ISOyear('1999-08'))
self:assertEquals('1999', p._ISOyear('1999'))
self:assertEquals('0099', p._ISOyear('99-09'))
self:assertEquals('0000', p._ISOyear('0'))
self:assertEquals('' , p._ISOyear('qwerty'))
self:assertEquals('' , p._ISOyear(''))
self:assertEquals('' , p._ISOyear('1999/09'))
end
function suite:test_2_ISOdate_basic()
self:assertEquals('10 August 1999, 08:15:30', ISOdate_en('1999-08-10 08:15:30Z'))
self:assertEquals('11 August 1999, 08:15:30', ISOdate_en('1999-08-11 08:15:30'))
self:assertEquals('12 August 1999, 08:15', ISOdate_en('1999-08-12 08:15'))
self:assertEquals('13 August 1999', ISOdate_en('1999-08-13'))
self:assertEquals( 'August 1999', ISOdate_en('1999-08'))
self:assertEquals( '1999', ISOdate_en('1999'))
self:assertEquals('14 May 999', ISOdate_en('999-05-14'))
self:assertEquals('15 July 0099', ISOdate_en('99-07-15'))
self:assertEquals('16 September 0009', ISOdate_en('9-09-16'))
self:assertEquals('December 1969', ISOdate_en('1969-12'))
self:assertEquals('February 999', ISOdate_en('999-02'))
self:assertEquals('999', ISOdate_en('999'))
self:assertEquals('0099', ISOdate_en('99'))
self:assertEquals('0009', ISOdate_en('9'))
self:assertEquals('"2010"', '"'..ISOdate_en(' 2010 ')..'"')
end
function suite:test_3_ISOdate_odd_dates()
self:assertEquals('1 August 1999, 08:05:03', ISOdate_en('1999-8-1 8:5:3')) -- no 0s in front of dates or months
self:assertEquals('10 August 2010, 18:15:30', ISOdate_en(' 2010-08-10 18:15:30Z')) -- spaces in front of the date
self:assertEquals('11 August 1999, 08:15', ISOdate_en('1999-08-11T08:15')) -- dates with "T" separator
self:assertEquals('12 August 1999, 08:15:30', ISOdate_en('1999-08-12T08:15:30')) -- dates with "T" separator
self:assertEquals('13 August 1999, 08:15:30', ISOdate_en('1999-08-13T08:15:30Z')) -- parse YYYY-MM-DD HH:MM:SS format with "Z"
self:assertEquals('14 August 1999, 08:15:30 (qwerty)', ISOdate_en('1999-08-14T08:15:30Z (qwerty)')) -- parse date with text behind it
self:assertEquals('15 August 1999, 08:15 (qwerty)', ISOdate_en('1999-08-15T08:15 (qwerty)'))
end
function suite:test_4_ISOdate_not_dates()
-- not proper dates will be returned as-is
self:assertEquals('qwerty', ISOdate_en('qwerty'))
self:assertEquals('', ISOdate_en(' '))
self:assertEquals('-2009-09', ISOdate_en('-2009-09'))
self:assertEquals('15-12-2008', ISOdate_en('15-12-2008'))
self:assertEquals('15 May 1999', ISOdate_en('15 May 1999'))
self:assertEquals('1999-08-18T08 (creation date)', ISOdate_en('1999-08-18T08 (creation date)'))
self:assertSameResult('{{other date|ca|1999}}', ISOdate_en('{{other date|ca|1999}}'))
end
function suite:test_5_ISOdate_out_or_range()
self:assertEquals('18 August 1999', ISOdate_en('1999-08-18 08:90:30')) -- minute out of range, keep only the valid date
self:assertEquals('1999', ISOdate_en('1999-18-18 08:20:30')) -- month out of range, keep only the valid year
self:assertEquals('2000', ISOdate_en('2000-13-29')) -- month out of range, keep only the valid year
self:assertEquals('September 2009', ISOdate_en('+2009-09')) -- a plus sign for the year is ignored
self:assertEquals('1 March 1567', ISOdate_en('1567-02-29')) -- leap day on non-leap year
self:assertEquals('29 February 2000', ISOdate_en('2000-02-29')) -- leap day on leap year
end
function suite:test_6_ISOdate_arguments()
-- many arguments are just passed into Module:DateI18n
local datevec, datestr = {2010,1,9}, '2010-01-09'
local case, class, trim_year = '', '',
self:assertEquals( ISOdate(datestr, 'pl'), Date(datevec, 'pl'))
self:assertEquals( ISOdate(datestr, 'he'), Date(datevec, 'he'))
self:assertEquals( ISOdate(datestr, 'pl','nom'), Date(datevec, 'pl','nom'))
self:assertEquals( ISOdate(datestr, 'pl','gen'), Date(datevec, 'pl','gen'))
self:assertEquals( ISOdate(datestr, 'ru','ins'), Date(datevec, 'ru','ins'))
self:assertEquals( ISOdate(datestr, 'ru','ins','dtstart'), Date(datevec, 'ru','ins','dtstart'))
datevec, datestr = {995,10,28}, '995-10-28'
self:assertEquals( ISOdate(datestr, 'fr'), Date(datevec, 'fr'))
self:assertEquals( ISOdate(datestr, 'fr', '', '', true), Date(datevec, 'fr', '', '', true))
self:assertEquals( ISOdate(datestr, 'fr', '', '', false), Date(datevec, 'fr', '', '', false))
self:assertEquals( ISOdate(datestr, 'fr', '', '', '100-990'), Date(datevec, 'fr', '', '', '100-990'))
end
return suite