Jump to content

Module:Time ago/testcases

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by FunPika (talk | contribs) at 20:06, 20 December 2013 (Try calculating the number of months in this function for one of the tests.). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
-- 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