コンテンツにスキップ

英文维基 | 中文维基 | 日文维基 | 草榴社区

モジュール:BananasArgs/testcases

-- Unit tests for [[Module:BananaArgs]]. Click talk page to run tests.
local p = require('Module:UnitTests')
 
function p:test_hello_world()
    self:preprocess_equals('{{#invoke:BananasArgs|hello_world}}', 'Hello, world!')
end
 
function p:test_hello()
    self:preprocess_equals('{{#invoke:BananasArgs|hello|Fred}}', 'Hello, Fred!')
end
 
function p:test_add()
    self:preprocess_equals('{{#invoke:BananasArgs|add|5|3}}', '8')
end
 
function p:test_count_fruit()
    self:preprocess_equals('{{#invoke:BananasArgs|count_fruit|bananas=5|apples=3}}', 'I have 5 bananas and 3 apples')
end

function p:test_has_fruit()
    self:preprocess_equals('{{#invoke:BananasArgs|has_fruit|Fred|bananas=5|cherries=7}}', 'Fred has: 5 bananas 7 cherries')
    self:preprocess_equals('{{#invoke:BananasArgs|has_fruit|Fred|bananas=5|cherries=}}', 'Fred has: 5 bananas  cherries')
    self:preprocess_equals('{{#invoke:BananasArgs|has_fruit|1=|bananas=5|cherries=}}', ' has: 5 bananas  cherries')
    self:preprocess_equals('{{#invoke:BananasArgs|has_fruit||bananas=5|cherries=}}', ' has: 5 bananas  cherries')
    self:preprocess_equals('{{#invoke:BananasArgs|has_fruit|bananas=5|cherries=7}}', '')
end
 
function p:test_custom_fruit()
    self:preprocess_equals('{{#invoke:BananasArgs|custom_fruit|pineapples=10|kiwis=5}}', 'I have: 5 kiwis 10 pineapples')
end
 
function p:test_custom_fruit_2()
    self:preprocess_equals('{{#invoke:BananasArgs|custom_fruit_2|Fred|pineapples=10|kiwis=5}}', 'Fred has: 5 kiwis 10 pineapples')
end

function p:test_hello_world_extraneous()
    self:preprocess_equals('{{#invoke:BananasArgs|hello_world|extra}}', 'Hello, world!')
end
 
function p:test_hello_noone()
    self:preprocess_equals('{{#invoke:BananasArgs|hello|}}', 'Hello, !')
end
 
function p:test_add_backwards()
    self:preprocess_equals('{{#invoke:BananasArgs|add|2=5|1=3}}', '8')
end
 
function p:test_count_fruit_otherorder()
    self:preprocess_equals('{{#invoke:BananasArgs|count_fruit|apples=3|bananas=5}}', 'I have 5 bananas and 3 apples')
end

function p:test_has_fruit_alternateorder()
    self:preprocess_equals('{{#invoke:BananasArgs|has_fruit|cherries=7|1=Fred|bananas=5}}', 'Fred has: 5 bananas 7 cherries')
end
 
function p:test_custom_fruit_otherorder()
    self:preprocess_equals('{{#invoke:BananasArgs|custom_fruit|kiwis=5|pineapples=10}}', 'I have: 10 pineapples 5 kiwis')
end
 
function p:test_custom_fruit_2_alternateorder()
    self:preprocess_equals('{{#invoke:BananasArgs|custom_fruit_2|kiwis=5|1=Fred|pineapples=10}}', 'Fred has: 10 pineapples 5 kiwis')
end

return p