Jump to content

Module:String/testcases

विकिपीडिया से
imported>Dragons flight के द्वारा 20:47, 25 फरवरी 2013 के बदलाव
-- Unit tests for [[Module:String]]. Click talk page to run tests.
local p = require('Module:UnitTests')
 
function p:test_len()
    self:preprocess_equals_many('{{#invoke:String|len|', '}}', {
        {' foo ', '5'},
        {'s= foo ', '3'},
        {'', '0'},
        {'s=', '0'},
        {'   ', '3'},
    })
end

function p:test_replace()
    self:preprocess_equals_many('{{#invoke:String|replace|', '}}', {
        {'1.1.1.1|.|/', '1/1/1/1'},
        {'alpha (beta)| (| gamma (', 'alpha gamma (beta)'},
        {'Dog (cat)|%s%(.*%)||plain=false', 'Dog'},
    })
end

function p:test_match()
    self:preprocess_equals_many('{{#invoke:String|match|', '}}', {
        {'dog (cat)|%((%a-)%)', 'cat'},
        {'dog (cat) (canary) (fish)|%((%a-)%)||-1', 'fish'},
        {'dog (cat) (canary) (fish)|%((%a-)%)||2', 'canary'},
        {'dog (cat) (canary) (fish)|%((%a-)%)|6|1', 'canary'},
        {'dog (cat) (canary) (fish)|%((%a-)%)|6|2', 'fish'},
        {'dog (cat)|%((%a-)%)||2|no_category=true', '<strong class="error">String Module Error: Match not found</strong>'},
        {'dog (cat)|%((%a-)%)||2|ignore_errors=true', ''},
    })
end

return p