This module contains testcases for its parent module, String.
See also
-- <nowiki>
-- Unit tests for [[Module:String]].
-- @see [[Module talk:String/testcases]]
return {
len = {
options = {
mode = 'invocation',
nowiki = false
},
tests = {
{ ' foo ', '5' },
{ 's= foo ', '3' },
{ '', '0' },
{ 's=', '0' },
{ ' ', '3' },
{ '最近の更新', '5' }
}
},
sub = {
options = {
mode = 'invocation',
nowiki = false
},
tests = {
{ ' foo |2|4', 'foo' },
{ 's= foo |1|3', 'foo' },
{ '最近の更新|4|5', '更新' }
}
},
sublength = {
options = {
mode = 'invocation',
nowiki = false
},
tests = {
{ ' 1234567 |3|2', '34' },
{ 's = 1234567| i = 3| len = 2', '45' },
{ ' alphabet |1|5', 'alpha' },
{ 's = alphabet|i = 0|len = 5', 'alpha' },
{ 'alph abet|0|5', 'alph ' },
{ ' three words here |2|10', 'hree words' },
{ 's = three words here |i = 3|len = 10', 'ee words h' }
}
},
match = {
options = {
mode = 'invocation',
nowiki = false
},
tests = {
{ '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', '' }
}
},
pos = {
options = {
mode = 'invocation',
nowiki = false
},
tests = {
{ 'abcdefghi | 4 ', 'd' },
{ 'target = abcdefghi |pos = 4', 'd' }
}
},
find = {
options = {
mode = 'invocation',
nowiki = false
},
tests = {
{ '', '0' },
{ 'source=', '0' },
{ 'source=|target=', '0' },
{ 'source=|target=Bob', '0' },
{ 'abc123def|12', '4' },
{ 'Bob|Joe', '0' },
{ 'Bob|b', '3' },
{ 'Bob Joe|oe', '6' },
{ 'source = abc123def| target = 12', '4' },
{ 'source = abc123def| target = pqr', '0' },
{ ' abc123def |123', '5' },
{ 'source = abc123def|target = %d |start = 3 |plain = false', '4' },
{ 'source= Bob |o', '2' },
{ ' Bob |o', '3' },
{ '높지만 급격히|만', '3' },
{ 'source=BAAAB|target=%w|plain=false', '1' },
{ 'source=BAAAB|target=%w|start=3|plain=false', '3' },
{ 'source=BAAAB|target=(%w)%1|plain=false', '2' }
}
},
str_find = {
options = {
mode = 'invocation',
nowiki = false
},
tests = {
{ nil, '1' },
{ '1=', '1' },
{ '1=|2=', '1' },
{ 'abc|', '1' },
{ 'bbc|z', '-1' },
{ 'bbc|zz', '-1' },
{ 'bbc|bb', '1' },
{ 'abc|b', '2' },
{ 'abb|bb', '2' },
{ 'Bob|', '1' },
{ '|Bob', '-1' },
{ 'Bob|Joe', '-1' },
{ 'Bob|Joe', '-1' },
{ 'BobBob|bB', '3' },
{ 'Bob|B|', '1' },
{ 'Bob|o|', '2' },
{ 'Bob|b|', '3' },
{ 'o|Bob', '-1' },
{ ' Bob |o', '3' },
{ ' Bob Jones |b J', '4' },
{ 'aaa aaa| a', '4' },
{ 'aaa aaa|a ', '3' },
{ '높지만 급격히|만', '3' },
{ 'test test| ', '5' },
{ 'test test| ', '-1' },
{ 'test test|2= ', '1' },
{ 'test test|2= ', '-1' }
}
},
prefix = {
options = {
mode = 'invocation',
nowiki = false
},
tests = {
{ 'aabbcc|a', 'yes' },
{ 'aabbcc|c', 'no' }
}
},
suffix = {
options = {
mode = 'invocation',
nowiki = false
},
tests = {
{ 'aabbcc|c', 'yes' },
{ 'aabbcc|a', 'no' }
}
},
count = {
options = {
mode = 'invocation',
nowiki = false
},
tests = {
{ 'aabbcc|a', '2' },
{ 'aabbcc|[ac]|plain=false', '4' },
{ 'aaabaaac|[^a]|plain=false', '2' },
{ 'aaabaaac|^a|plain=false', '1' }
}
},
replace = {
options = {
mode = 'invocation',
nowiki = false
},
tests = {
{ '1.1.1.1|.|/', '1/1/1/1' },
{ 'alpha (beta)| (| gamma (', 'alpha gamma (beta)' },
{ 'Dog (cat)|%s%(.*%)||plain=false', 'Dog' }
}
},
rep = {
options = {
mode = 'invocation',
nowiki = false
},
tests = {
{ 'abc|1', 'abc' },
{ 'a b|7', 'a ba ba ba ba ba ba b' },
{ 'bla|glug|no_category=true', '<strong class="error">String Module Error: function rep expects a number as second parameter, received "glug"</strong>' },
{ 'bla|glug|ignore_errors=true', '' },
{ 'àèò|3', 'àèòàèòàèò' }
}
},
lc = {
options = {
mode = 'invocation',
nowiki = false
},
tests = {
{ 'INPUT STRING', 'input string' },
{ 'Województwo Łódzkie', 'województwo łódzkie' }
}
},
uc = {
options = {
mode = 'invocation',
nowiki = false
},
tests = {
{ 'input string', 'INPUT STRING' },
{ 'Województwo Łódzkie', 'WOJEWÓDZTWO ŁÓDZKIE' }
}
},
lcfirst = {
options = {
mode = 'invocation',
nowiki = false
},
tests = {
{ 'Input string', 'input string' },
{ 'Łódź', 'łódź' }
}
},
ucfirst = {
options = {
mode = 'invocation',
nowiki = false
},
tests = {
{ 'iNPUT STRING', 'INPUT STRING' },
{ 'łódź', 'Łódź' }
}
},
padleft = {
options = {
mode = 'invocation',
nowiki = true
},
tests = {
{ 'input string', 'input string' },
{ 'input string|16', ' input string' },
{ 'input string|16|>', '>>>>input string' }
}
},
padright = {
options = {
mode = 'invocation',
nowiki = true
},
tests = {
{ 'input string', 'input string' },
{ 'input string|16', 'input string ' },
{ 'input string|16|<', 'input string<<<<' }
}
},
explode = {
options = {
mode = 'invocation',
nowiki = true
},
tests = {
{ 'And if you tolerate this| |2', 'you' },
{ 'String/Functions/Code|/|-1', 'Code' },
{ 'Split%By%Percentage%Signs|%|2', 'Percentage' },
{ 'And if you tolerate this| |2|3', 'you tolerate this' },
{ 'And if you tolerate this| |-1|3', 'you tolerate this' },
{ 'Žmržlina|ž|1', 'lina' },
{ 'Explode with an empty delimiter||2', 'p' }
}
},
urlencode = {
options = {
mode = 'invocation',
nowiki = false
},
tests = {
{ 'Input string', 'input string' },
{ 'Łódź', 'łódź' }
}
},
urlencode = {
options = {
mode = 'invocation',
nowiki = false
},
tests = {
{ 'x:y/z á é', 'x%3Ay%2Fz+%C3%A1+%C3%A9' },
{ 'x:y/z á é|QUERY', 'x%3Ay%2Fz+%C3%A1+%C3%A9' },
{ 'x:y/z á é|WIKI', tonumber(mw.site.currentVersion:match('^%d%.%d+')) >= 1.30 and 'x:y/z_%C3%A1_%C3%A9' or 'x%3Ay%2Fz_%C3%A1_%C3%A9' },
{ 'x:y/z á é|PATH', 'x%3Ay%2Fz%20%C3%A1%20%C3%A9' }
}
},
urldecode = {
options = {
mode = 'invocation',
nowiki = false
},
tests = {
{ 'x%3Ay%2Fz+%C3%A1+%C3%A9', 'x:y/z á é' },
{ 'x%3Ay%2Fz+%C3%A1+%C3%A9|QUERY', 'x:y/z á é' },
{ 'x%3Ay%2Fz_%C3%A1_%C3%A9|WIKI', 'x:y/z á é' },
{ 'x%3Ay%2Fz%20%C3%A1%20%C3%A9|PATH', 'x:y/z á é' }
}
},
main = {
options = {
mode = 'invocation',
nowiki = true
},
tests = {
{ nil, 'you must specify a function to call', { err = true } },
}
}
}
-- </nowiki>