Difference between revisions of "Module:Time ago/testcases"

From blackwiki
Jump to navigation Jump to search
blackwiki>FunPika
(Every test should pass now.)
blackwiki>FunPika
(Update with new main function name.)
Line 2: Line 2:
 
local p = require('Module:UnitTests')
 
local p = require('Module:UnitTests')
  
function p:test_timeAgo()
+
function p:test_main()
 
local lang = mw.language.getContentLanguage()
 
local lang = mw.language.getContentLanguage()
 
 
Line 18: Line 18:
 
yearsuntilaug57 = math.floor( ( lang:formatDate ( 'U', '4 August 2057' ) - currentTime ) / 31557600 )
 
yearsuntilaug57 = math.floor( ( lang:formatDate ( 'U', '4 August 2057' ) - currentTime ) / 31557600 )
 
 
self:preprocess_equals('{{#invoke:TimeAgo|timeAgo|15 September 2013}}', monthssincesep13 .. ' months ago')
+
self:preprocess_equals('{{#invoke:TimeAgo|main|15 September 2013}}', monthssincesep13 .. ' months ago')
self:preprocess_equals('{{#invoke:TimeAgo|timeAgo|{{CURRENTTIMESTAMP}}}}', '0 seconds ago')
+
self:preprocess_equals('{{#invoke:TimeAgo|main|{{CURRENTTIMESTAMP}}}}', '0 seconds ago')
self:preprocess_equals('{{#invoke:TimeAgo|timeAgo|15 September 2013|purge=yes}}', monthssincesep13 .. ' months ago <span class="plainlinks">([//en.wikipedia.org/w/index.php?title=Module_talk:TimeAgo/testcases&action=purge purge])</span>')
+
self:preprocess_equals('{{#invoke:TimeAgo|main|15 September 2013|purge=yes}}', monthssincesep13 .. ' months ago <span class="plainlinks">([//en.wikipedia.org/w/index.php?title=Module_talk:TimeAgo/testcases&action=purge purge])</span>')
self:preprocess_equals('{{#invoke:TimeAgo|timeAgo|{{CURRENTTIMESTAMP}}|purge=yes}}', '0 seconds ago <span class="plainlinks">([//en.wikipedia.org/w/index.php?title=Module_talk:TimeAgo/testcases&action=purge purge])</span>')
+
self:preprocess_equals('{{#invoke:TimeAgo|main|{{CURRENTTIMESTAMP}}|purge=yes}}', '0 seconds ago <span class="plainlinks">([//en.wikipedia.org/w/index.php?title=Module_talk:TimeAgo/testcases&action=purge purge])</span>')
self:preprocess_equals('{{#invoke:TimeAgo|timeAgo|July 1 2009}}', yearssincejul09 .. ' years ago')
+
self:preprocess_equals('{{#invoke:TimeAgo|main|July 1 2009}}', yearssincejul09 .. ' years ago')
self:preprocess_equals('{{#invoke:TimeAgo|timeAgo|July 1 2009|magnitude=minutes}}', minutessincejul09 .. ' minutes ago')
+
self:preprocess_equals('{{#invoke:TimeAgo|main|July 1 2009|magnitude=minutes}}', minutessincejul09 .. ' minutes ago')
self:preprocess_equals('{{#invoke:TimeAgo|timeAgo|July 1 2009|magnitude=days}}', dayssincejul09 .. ' days ago')
+
self:preprocess_equals('{{#invoke:TimeAgo|main|July 1 2009|magnitude=days}}', dayssincejul09 .. ' days ago')
self:preprocess_equals('{{#invoke:TimeAgo|timeAgo|July 1 2009|magnitude=weeks}}', weekssincejul09 .. ' weeks ago')
+
self:preprocess_equals('{{#invoke:TimeAgo|main|July 1 2009|magnitude=weeks}}', weekssincejul09 .. ' weeks ago')
self:preprocess_equals('{{#invoke:TimeAgo|timeAgo|July 1 2009|magnitude=months}}', monthssincejul09 .. ' months ago')
+
self:preprocess_equals('{{#invoke:TimeAgo|main|July 1 2009|magnitude=months}}', monthssincejul09 .. ' months ago')
self:preprocess_equals('{{#invoke:TimeAgo|timeAgo|July 1 2049|magnitude=months}}', monthsuntiljul49 .. ' months\' time')
+
self:preprocess_equals('{{#invoke:TimeAgo|main|July 1 2049|magnitude=months}}', monthsuntiljul49 .. ' months\' time')
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|main|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}}', secondssincejul09 .. ' seconds ago')
+
self:preprocess_equals('{{#invoke:TimeAgo|main|July 1 2009|magnitude=fruits}}', secondssincejul09 .. ' seconds ago')
self:preprocess_equals('{{#invoke:TimeAgo|timeAgo}}', '0 seconds ago')
+
self:preprocess_equals('{{#invoke:TimeAgo|main}}', '0 seconds ago')
self:preprocess_equals('{{#invoke:TimeAgo|timeAgo|July 1 2009|magnitude=HoUrS}}', secondssincejul09 .. ' seconds ago')
+
self:preprocess_equals('{{#invoke:TimeAgo|main|July 1 2009|magnitude=HoUrS}}', secondssincejul09 .. ' seconds ago')
self:preprocess_equals('{{#invoke:TimeAgo|timeAgo|4 August 2057}}', yearsuntilaug57 .. ' years\' time')
+
self:preprocess_equals('{{#invoke:TimeAgo|main|4 August 2057}}', yearsuntilaug57 .. ' years\' time')
 
end
 
end
  
 
return p
 
return p

Revision as of 22:50, 21 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_main()
	local lang = mw.language.getContentLanguage()
	
	-- Calculate the time since/until the test dates here, so that the test cases do not fail in the future.
	currentTime = lang:formatDate( 'U' )
	jul09 = currentTime - lang:formatDate( 'U', '1 July 2009' )
	secondssincejul09 = math.floor( jul09 )
	minutessincejul09 = math.floor( jul09 / 60 )
	dayssincejul09 = math.floor( jul09 / 86400 )
	weekssincejul09 = math.floor( jul09 / 604800 )
	monthssincejul09 = math.floor( jul09 / 2678400 )
	yearssincejul09 = math.floor( jul09 / 31557600 )
	monthssincesep13 = math.floor( ( currentTime - lang:formatDate( 'U', '15 September 2013' ) ) / 2678400 )
	monthsuntiljul49 = math.floor( ( lang:formatDate ( 'U', '1 July 2049' ) - currentTime ) / 2678400 )
	yearsuntilaug57 = math.floor( ( lang:formatDate ( 'U', '4 August 2057' ) - currentTime ) / 31557600 )
	
	self:preprocess_equals('{{#invoke:TimeAgo|main|15 September 2013}}', monthssincesep13 .. ' months ago')
	self:preprocess_equals('{{#invoke:TimeAgo|main|{{CURRENTTIMESTAMP}}}}', '0 seconds ago')
	self:preprocess_equals('{{#invoke:TimeAgo|main|15 September 2013|purge=yes}}', monthssincesep13 .. ' months ago <span class="plainlinks">([//en.wikipedia.org/w/index.php?title=Module_talk:TimeAgo/testcases&action=purge purge])</span>')
	self:preprocess_equals('{{#invoke:TimeAgo|main|{{CURRENTTIMESTAMP}}|purge=yes}}', '0 seconds ago <span class="plainlinks">([//en.wikipedia.org/w/index.php?title=Module_talk:TimeAgo/testcases&action=purge purge])</span>')
	self:preprocess_equals('{{#invoke:TimeAgo|main|July 1 2009}}', yearssincejul09 .. ' years ago')
	self:preprocess_equals('{{#invoke:TimeAgo|main|July 1 2009|magnitude=minutes}}', minutessincejul09 .. ' minutes ago')
	self:preprocess_equals('{{#invoke:TimeAgo|main|July 1 2009|magnitude=days}}', dayssincejul09 .. ' days ago')
	self:preprocess_equals('{{#invoke:TimeAgo|main|July 1 2009|magnitude=weeks}}', weekssincejul09 .. ' weeks ago')
	self:preprocess_equals('{{#invoke:TimeAgo|main|July 1 2009|magnitude=months}}', monthssincejul09 .. ' months ago')
	self:preprocess_equals('{{#invoke:TimeAgo|main|July 1 2049|magnitude=months}}', monthsuntiljul49 .. ' months\' time')
	self:preprocess_equals('{{#invoke:TimeAgo|main|Julio 1}}', '<strong class="error">Error: first parameter cannot be parsed as a date or time.</strong>')
	self:preprocess_equals('{{#invoke:TimeAgo|main|July 1 2009|magnitude=fruits}}', secondssincejul09 .. ' seconds ago')
	self:preprocess_equals('{{#invoke:TimeAgo|main}}', '0 seconds ago')
	self:preprocess_equals('{{#invoke:TimeAgo|main|July 1 2009|magnitude=HoUrS}}', secondssincejul09 .. ' seconds ago')
	self:preprocess_equals('{{#invoke:TimeAgo|main|4 August 2057}}', yearsuntilaug57 .. ' years\' time')
end

return p