Difference between revisions of "Module:Time ago/testcases"
Jump to navigation
Jump to search
blackwiki>FunPika m (Fix a couple parameters.) |
blackwiki>FunPika (Try calculating the number of months in this function for one of the tests.) |
||
| Line 3: | Line 3: | ||
function p:test_timeAgo() | function p:test_timeAgo() | ||
| − | self:preprocess_equals('{{#invoke:TimeAgo|timeAgo| | + | local lang = mw.language.getContentLanguage() |
| − | self:preprocess_equals('{{#invoke:TimeAgo|timeAgo|{{CURRENTTIMESTAMP}}}}', ' | + | monthssincejan11 = ( lang:formatDate( 'U' ) - lang:formatDate( 'U', '15 January 2011' ) ) / 2678400 |
| − | self:preprocess_equals('{{#invoke:TimeAgo|timeAgo| | + | self:preprocess_equals('{{#invoke:TimeAgo|timeAgo|15 January 2011}}', monthssincejan11 .. 'months ago') |
| + | self:preprocess_equals('{{#invoke:TimeAgo|timeAgo|{{CURRENTTIMESTAMP}}}}', '0 seconds ago') | ||
| + | self:preprocess_equals('{{#invoke:TimeAgo|timeAgo|15 January 2011|purge=yes}}', '{{Time ago|1 January 2012|purge=yes}}') | ||
self:preprocess_equals('{{#invoke:TimeAgo|timeAgo|{{CURRENTTIMESTAMP}}}}|purge=yes}}', '{{Time ago|{{CURRENTTIMESTAMP}}|purge=yes}}') | self:preprocess_equals('{{#invoke:TimeAgo|timeAgo|{{CURRENTTIMESTAMP}}}}|purge=yes}}', '{{Time ago|{{CURRENTTIMESTAMP}}|purge=yes}}') | ||
self:preprocess_equals('{{#invoke:TimeAgo|timeAgo|July 1 2009}}', '{{Time ago|July 1 2009}}') | self:preprocess_equals('{{#invoke:TimeAgo|timeAgo|July 1 2009}}', '{{Time ago|July 1 2009}}') | ||
| Line 15: | Line 17: | ||
self:preprocess_equals('{{#invoke:TimeAgo|timeAgo|Julio 1}}', '<strong class="error">Error: first parameter cannot be parsed as a date or time.</strong>') | self:preprocess_equals('{{#invoke:TimeAgo|timeAgo|Julio 1}}', '<strong class="error">Error: first parameter cannot be parsed as a date or time.</strong>') | ||
self:preprocess_equals('{{#invoke:TimeAgo|timeAgo|July 1 2009|magnitude=fruits}}', '{{Time ago|July 1 2009|July 1 2009|magnitude=fruits}}') | self:preprocess_equals('{{#invoke:TimeAgo|timeAgo|July 1 2009|magnitude=fruits}}', '{{Time ago|July 1 2009|July 1 2009|magnitude=fruits}}') | ||
| − | self:preprocess_equals('{{#invoke:TimeAgo|timeAgo}}', ' | + | self:preprocess_equals('{{#invoke:TimeAgo|timeAgo}}', '0 seconds ago') |
self:preprocess_equals('{{#invoke:TimeAgo|timeAgo|July 1 2009|magnitude=HoUrS}}', '{{Time ago|July 1 2009|magnitude=HoUrS}}') | self:preprocess_equals('{{#invoke:TimeAgo|timeAgo|July 1 2009|magnitude=HoUrS}}', '{{Time ago|July 1 2009|magnitude=HoUrS}}') | ||
self:preprocess_equals('{{#invoke:TimeAgo|timeAgo|4 August 2057}}', '{{time ago|4 August 2057}}') | self:preprocess_equals('{{#invoke:TimeAgo|timeAgo|4 August 2057}}', '{{time ago|4 August 2057}}') | ||
Revision as of 20:06, 20 December 2013
Documentation for this module may be created at Module:Time ago/testcases/doc
-- Unit tests for [[Module:TimeAgo]]. Click talk page to run tests.
local p = require('Module:UnitTests')
function p:test_timeAgo()
local lang = mw.language.getContentLanguage()
monthssincejan11 = ( lang:formatDate( 'U' ) - lang:formatDate( 'U', '15 January 2011' ) ) / 2678400
self:preprocess_equals('{{#invoke:TimeAgo|timeAgo|15 January 2011}}', monthssincejan11 .. 'months ago')
self:preprocess_equals('{{#invoke:TimeAgo|timeAgo|{{CURRENTTIMESTAMP}}}}', '0 seconds ago')
self:preprocess_equals('{{#invoke:TimeAgo|timeAgo|15 January 2011|purge=yes}}', '{{Time ago|1 January 2012|purge=yes}}')
self:preprocess_equals('{{#invoke:TimeAgo|timeAgo|{{CURRENTTIMESTAMP}}}}|purge=yes}}', '{{Time ago|{{CURRENTTIMESTAMP}}|purge=yes}}')
self:preprocess_equals('{{#invoke:TimeAgo|timeAgo|July 1 2009}}', '{{Time ago|July 1 2009}}')
self:preprocess_equals('{{#invoke:TimeAgo|timeAgo|July 1 2009|magnitude=minutes}}', '{{Time ago|July 1 2009|magnitude=minutes}}')
self:preprocess_equals('{{#invoke:TimeAgo|timeAgo|July 1 2009|magnitude=days}}', '{{Time ago|July 1 2009|magnitude=days}}')
self:preprocess_equals('{{#invoke:TimeAgo|timeAgo|July 1 2009|magnitude=weeks}}', '{{Time ago|July 1 2009|magnitude=weeks}}')
self:preprocess_equals('{{#invoke:TimeAgo|timeAgo|July 1 2009|magnitude=months}}', '{{Time ago|July 1 2009|magnitude=months}}')
self:preprocess_equals('{{#invoke:TimeAgo|timeAgo|July 1 2049|magnitude=months}}', '{{Time ago|July 1 2049|magnitude=months}}')
self:preprocess_equals('{{#invoke:TimeAgo|timeAgo|Julio 1}}', '<strong class="error">Error: first parameter cannot be parsed as a date or time.</strong>')
self:preprocess_equals('{{#invoke:TimeAgo|timeAgo|July 1 2009|magnitude=fruits}}', '{{Time ago|July 1 2009|July 1 2009|magnitude=fruits}}')
self:preprocess_equals('{{#invoke:TimeAgo|timeAgo}}', '0 seconds ago')
self:preprocess_equals('{{#invoke:TimeAgo|timeAgo|July 1 2009|magnitude=HoUrS}}', '{{Time ago|July 1 2009|magnitude=HoUrS}}')
self:preprocess_equals('{{#invoke:TimeAgo|timeAgo|4 August 2057}}', '{{time ago|4 August 2057}}')
end
return p