Module:Time ago/testcases: Difference between revisions

Content deleted Content added
m Wugapodes moved page Module:TimeAgo/testcases to Module:Time Ago/testcases without leaving a redirect: Per requested move Template_talk:Time_ago#Requested_move_30_October_2019
No edit summary
 
(6 intermediate revisions by 3 users not shown)
Line 1:
-- Unit tests for [[Module:TimeAgoTime ago]]. Click talk page to run tests.
local p = require('Module:UnitTests')
local Date = require('Module:Date')._Date
Line 34:
local yearsuntilaug57 = math.floor( ( lang:formatDate ( 'U', '4 August 2057' ) - currentTime ) / 31557600 )
 
self:preprocess_equals('{{#invoke:TimeAgoTime ago/sandbox|main|'..checker(3, 'date')..'}}', checker(3, 'm') .. ' months ago')
self:preprocess_equals('{{#invoke:TimeAgoTime ago/sandbox|main|{{CURRENTTIMESTAMP}}}}', '0 seconds ago')
self:preprocess_equals('{{#invoke:TimeAgoTime ago/sandbox|main|'..checker(3, 'date')..'|purge=yes}}', checker(3, 'm') .. ' months ago <span class="plainlinks">([//en.wikipedia.org/w/index.php?title=Module_talk:TimeAgoTime ago/testcases&action=purge purge])</span>')
self:preprocess_equals('{{#invoke:TimeAgoTime ago/sandbox|main|{{CURRENTTIMESTAMP}}|purge=yes}}', '0 seconds ago <span class="plainlinks">([//en.wikipedia.org/w/index.php?title=Module_talk:TimeAgoTime ago/testcases&action=purge purge])</span>')
self:preprocess_equals('{{#invoke:TimeAgoTime ago/sandbox|main|July 1 2009}}', checker(2, 'y') .. ' years ago')
self:preprocess_equals('{{#invoke:TimeAgoTime ago/sandbox|main|July 1 2009|magnitude=minutes}}', minutessincejul09 .. ' minutes ago')
self:preprocess_equals('{{#invoke:TimeAgoTime ago/sandbox|main|July 1 2009|magnitude=days}}', checker(2, 'd') .. ' days ago')
self:preprocess_equals('{{#invoke:TimeAgoTime ago/sandbox|main|July 1 2009|magnitude=weeks}}', checker(2, 'w') .. ' weeks ago')
self:preprocess_equals('{{#invoke:TimeAgoTime ago/sandbox|main|July 1 2009|magnitude=months}}', checker(2, 'm') .. ' months ago')
self:preprocess_equals('{{#invoke:TimeAgoTime ago/sandbox|main|July 1 2049|magnitude=months}}', checker(4, 'm') .. ' months\' time')
self:preprocess_equals('{{#invoke:TimeAgoTime ago/sandbox|main|Julio 1}}', '<strong class="error">Error: first parameter cannot be parsed as a date or time.</strong>')
self:preprocess_equals('{{#invoke:TimeAgoTime ago/sandbox|main|July 1 2009|magnitude=fruits}}', secondssincejul09 .. ' seconds ago')
self:preprocess_equals('{{#invoke:TimeAgoTime ago/sandbox|main}}', '0 seconds ago')
self:preprocess_equals('{{#invoke:TimeAgoTime ago/sandbox|main|July 1 2009|magnitude=HoUrS}}', secondssincejul09 .. ' seconds ago')
self:preprocess_equals('{{#invoke:TimeAgoTime ago/sandbox|main|4 August 2057}}', yearsuntilaug57 .. ' years\' time')
self:preprocess_equals('{{#invoke:TimeAgoTime ago/sandbox|main|'..checker(3, 'date')..'|ago=in the past}}', checker(3, 'm') .. ' months in the past')
self:preprocess_equals('{{#invoke:TimeAgoTime ago/sandbox|main|{{CURRENTTIMESTAMP}}|min_magnitude=weeks}}', '0 weeks ago')
self:preprocess_equals('{{#invoke:TimeAgoTime ago/sandbox|main|'..checker(3, 'date')..'|ago=}}', checker(3, 'm') .. ' months')
self:preprocess_equals('{{#invoke:TimeAgoTime ago/sandbox|main|{{#time: r | -12 months -14 days}}|magnitude=months|spellout=yes}}', 'twelve months ago') -- #time always gives one month too few
self:preprocess_equals('{{#invoke:TimeAgoTime ago/sandbox|main|{{#time: r | -12 months -14 days}}|magnitude=months|spellout=y}}', 'twelve months ago')
self:preprocess_equals('{{#invoke:TimeAgoTime ago/sandbox|main|{{#time: r | -12 months -14 days}}|magnitude=months|spellout=y|spelloutmax=11}}', '12 months ago')
self:preprocess_equals('{{#invoke:TimeAgoTime ago/sandbox|main|{{#time: r | -12 months -14 days}}|magnitude=months|spellout=auto}}', '12 months ago')
self:preprocess_equals('{{#invoke:TimeAgoTime ago/sandbox|main|{{#time: r | -4 years -14 days}}|magnitude=years|spellout=auto}}', 'four years ago')
self:preprocess_equals('{{#invoke:TimeAgoTime ago/sandbox|main|July 1 2009|magnitude=weeks|spellout=yes}}', checker(2, 'w') .. ' weeks ago') -- [[Module:NumberSpell]] can only spell numbers up to 100.
self:preprocess_equals_preprocess('{{#invoke:TimeAgoTime ago/sandbox|main|'..checker(1, 'date')..'|magnitude=days}}' , checker(1, 'd')..' days ago')
self:preprocess_equals_preprocess('{{#invoke:TimeAgoTime ago/sandbox|main|'..checker(1, 'date')..'|magnitude=weeks}}' , checker(1, 'w')..' weeks ago')
self:preprocess_equals_preprocess('{{#invoke:TimeAgoTime ago/sandbox|main|'..checker(1, 'date')..'|magnitude=months}}', checker(1, 'm')..' months ago')
self:preprocess_equals_preprocess('{{#invoke:TimeAgoTime ago/sandbox|main|'..checker(1, 'date')..'|magnitude=years}}' , checker(1, 'y')..' years ago')
 
-- Testing whether the module is accurate on the day
self:preprocess_equals('{{#invoke:TimeAgoTime ago/sandbox|main|{{#time: r | -10 years }}}}', '10 years ago')
self:preprocess_equals('{{#invoke:TimeAgoTime ago/sandbox|main|{{#time: r | -10 years -1 days}}}}', '10 years ago')
self:preprocess_equals('{{#invoke:TimeAgoTime ago/sandbox|main|{{#time: r | -1 years }}}}', '12 months ago')
self:preprocess_equals('{{#invoke:TimeAgoTime ago/sandbox|main|{{#time: r | -1 years -1 days}}}}', '12 months ago')
self:preprocess_equals('{{#invoke:TimeAgoTime ago/sandbox|main|{{#time: r | -1 years -2 days}}}}', '12 months ago')
self:preprocess_equals('{{#invoke:TimeAgoTime ago/sandbox|main|{{#time: r | -1 years -3 days}}}}', '12 months ago')
self:preprocess_equals('{{#invoke:TimeAgoTime ago/sandbox|main|{{#time: r | -1 years -4 days}}}}', '12 months ago')
self:preprocess_equals('{{#invoke:TimeAgoTime ago/sandbox|main|{{#time: r | -1 years -5 days}}}}', '12 months ago')
self:preprocess_equals('{{#invoke:TimeAgoTime ago/sandbox|main|{{#time: r | -1 years -6 days}}}}', '12 months ago')
self:preprocess_equals('{{#invoke:TimeAgoTime ago/sandbox|main|{{#time: r | -1 years -7 days}}}}', '12 months ago')
self:preprocess_equals('{{#invoke:TimeAgoTime ago/sandbox|main|{{#time: r | -1 years -8 days}}}}', '12 months ago')
self:preprocess_equals('{{#invoke:Time ago/sandbox|main|{{#time: r | -1 years -8 days}}|numeric=y}}', '12')
end