Difference between revisions of "Module:Example/testcases"

From blackwiki
Jump to navigation Jump to search
blackwiki>ViniciusBR11
m
m (22 revisions imported)
 
(11 intermediate revisions by 6 users not shown)
Line 1: Line 1:
−
local p = {}
+
-- Unit tests for [[Module:Example]]. Click talk page to run tests.
−
function p.animate( f )
+
local p = require('Module:UnitTests')
−
local args = f
+
 
−
if f == mw.getCurrentFrame() then
+
function p:test_hello()
−
args = f:getParent().args
+
    self:preprocess_equals('{{#invoke:Example | hello}}', 'Hello World!')
−
end
+
end
−
local files = args[1] or ''
+
 
−
local size = args[2] or ''
+
function p:test_hello_to()
−
+
    self:preprocess_equals('{{#invoke:Example|hello|Fred}}', 'Hello, Fred!')
−
if size ~= '' then
+
end
−
size = '|' .. size
+
 
−
end
+
function p:test_count_fruit()
−
+
    self:preprocess_equals('{{#invoke:Example|count_fruit|bananas=5|apples=3}}', 'I have 5 bananas and 3 apples')
−
local images = {}
 
−
for image in mw.text.gsplit( files, '%s*;%s*' ) do
 
−
if image == '' then
 
−
table.insert( images, '<span><br></span>' )
 
−
else
 
−
table.insert( images, '<span>[[File:' .. image .. size .. ']]</span>' )
 
−
end
 
−
end
 
−
images[1] = images[1]:gsub( '^<span>', '<span class="active">' )
 
−
 
−
return '<span class="animated">' .. table.concat( images ) .. '</span>'
 
 
end
 
end
 
return p
 
return p

Latest revision as of 16:30, 26 September 2020

Documentation for this module may be created at Module:Example/testcases/doc

-- Unit tests for [[Module:Example]]. Click talk page to run tests.
local p = require('Module:UnitTests')

function p:test_hello()
    self:preprocess_equals('{{#invoke:Example | hello}}', 'Hello World!')
end

function p:test_hello_to()
    self:preprocess_equals('{{#invoke:Example|hello|Fred}}', 'Hello, Fred!')
end

function p:test_count_fruit()
    self:preprocess_equals('{{#invoke:Example|count_fruit|bananas=5|apples=3}}', 'I have 5 bananas and 3 apples')
end
return p