Modul:Citation/CS1/testcases/dates
Utseende
Moduldokumentasjon
[opprett]
--[=[
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 >------------------------------------------------------------
]]
function p:test_ymx_dates() -- EDTF dates
self:preprocess_equals_preprocess_many(
'{{cite book/new |title=Title |', '}}', '{{cite book |title=Title |', '}}',
{
{'date=1500-10-XX'}, -- invalid year
{'date=5500-10-XX'}, -- invalid year
{'date=1980-00-XX'}, -- invalid month
{'date=1980-13-XX'}, -- invalid month
{'date=2000-02-XX'},
},
{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(
'{{cite book/new |title=Title |url=//example.com |', '}}', '{{cite book |title=Title |url=//example.com |', '}}',
{
{'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