All 111 tests passed.
test_len
| Text | Expected | Actual | |
|---|---|---|---|
| {{#invoke:String/sandbox|len| foo }} | 5 | 5 | |
| {{#invoke:String/sandbox|len|s= foo }} | 3 | 3 | |
| {{#invoke:String/sandbox|len|}} | 0 | 0 | |
| {{#invoke:String/sandbox|len|s=}} | 0 | 0 | |
| {{#invoke:String/sandbox|len| }} | 3 | 3 | |
| {{#invoke:String/sandbox|len|最近の更新}} | 5 | 5 |
test_replace
| Text | Expected | Actual | |
|---|---|---|---|
| {{#invoke:String/sandbox|replace|1.1.1.1|.|/}} | 1/1/1/1 | 1/1/1/1 | |
| {{#invoke:String/sandbox|replace|alpha (beta)| (| gamma (}} | alpha gamma (beta) | alpha gamma (beta) | |
| {{#invoke:String/sandbox|replace|Dog (cat)|%s%(.*%)||plain=false}} | Dog | Dog |
test_match
| Text | Expected | Actual | |
|---|---|---|---|
| {{#invoke:String/sandbox|match|dog (cat)|%((%a-)%)}} | cat | cat | |
| {{#invoke:String/sandbox|match|dog (cat) (canary) (fish)|%((%a-)%)||-1}} | fish | fish | |
| {{#invoke:String/sandbox|match|dog (cat) (canary) (fish)|%((%a-)%)||2}} | canary | canary | |
| {{#invoke:String/sandbox|match|dog (cat) (canary) (fish)|%((%a-)%)|6|1}} | canary | canary | |
| {{#invoke:String/sandbox|match|dog (cat) (canary) (fish)|%((%a-)%)|6|2}} | fish | fish | |
| {{#invoke:String/sandbox|match|dog (cat)|%((%a-)%)||2|no_category=true}} | String Module Error: Match not found | String Module Error: Match not found | |
| {{#invoke:String/sandbox|match|dog (cat)|%((%a-)%)||2|ignore_errors=true}} |
test_match
| Text | Expected | Actual | |
|---|---|---|---|
| {{#invoke:String|match|dog (cat)|%((%a-)%)}} | cat | cat | |
| {{#invoke:String|match|dog (cat) (canary) (fish)|%((%a-)%)||-1}} | fish | fish | |
| {{#invoke:String|match|dog (cat) (canary) (fish)|%((%a-)%)||2}} | canary | canary | |
| {{#invoke:String|match|dog (cat) (canary) (fish)|%((%a-)%)|6|1}} | canary | canary | |
| {{#invoke:String|match|dog (cat) (canary) (fish)|%((%a-)%)|6|2}} | fish | fish | |
| {{#invoke:String|match|dog (cat)|%((%a-)%)||2|no_category=true}} | String Module Error: Match not found | String Module Error: Match not found | |
| {{#invoke:String|match|dog (cat)|%((%a-)%)||2|ignore_errors=true}} | |||
| {{#invoke:String/sandbox|match|dog (cat)|%((%a-)%)}} | cat | cat | |
| {{#invoke:String/sandbox|match|dog (cat) (canary) (fish)|%((%a-)%)||-1}} | fish | fish | |
| {{#invoke:String/sandbox|match|dog (cat) (canary) (fish)|%((%a-)%)||2}} | canary | canary | |
| {{#invoke:String/sandbox|match|dog (cat) (canary) (fish)|%((%a-)%)|6|1}} | canary | canary | |
| {{#invoke:String/sandbox|match|dog (cat) (canary) (fish)|%((%a-)%)|6|2}} | fish | fish | |
| {{#invoke:String/sandbox|match|dog (cat)|%((%a-)%)||2|no_category=true}} | String Module Error: Match not found | String Module Error: Match not found | |
| {{#invoke:String/sandbox|match|dog (cat)|%((%a-)%)||2|ignore_errors=true}} |
test_match_reverse
| Text | Expected | Actual | |
|---|---|---|---|
| {{#invoke:String|match|a (1) (2) (3) (4) (5) (6) (a)|%((%d)%)||-1}} | 6 | 6 | |
| {{#invoke:String|match|a (1) (2) (3) (4) (5) (6) (a)|%((%d)%)||-2}} | 5 | 5 | |
| {{#invoke:String|match|a (1) (2) (3) (4) (5) (6) (a)|%((%d)%)||-4}} | 3 | 3 | |
| {{#invoke:String|match|a (1) (2) (3) (4) (5) (6) (a)|%((%d)%)||-5}} | 2 | 2 | |
| {{#invoke:String|match|a (1) (2) (3) (4) (5) (6) (a)|%((%d)%)||-6}} | 1 | 1 | |
| {{#invoke:String|match|a (1) (2) (3) (4) (5) (6) (a)|%((%d)%)||-7|no_category=true}} | String Module Error: Match not found | String Module Error: Match not found | |
| {{#invoke:String/sandbox|match|a (1) (2) (3) (4) (5) (6) (a)|%((%d)%)||-1}} | 6 | 6 | |
| {{#invoke:String/sandbox|match|a (1) (2) (3) (4) (5) (6) (a)|%((%d)%)||-2}} | 5 | 5 | |
| {{#invoke:String/sandbox|match|a (1) (2) (3) (4) (5) (6) (a)|%((%d)%)||-4}} | 3 | 3 | |
| {{#invoke:String/sandbox|match|a (1) (2) (3) (4) (5) (6) (a)|%((%d)%)||-5}} | 2 | 2 | |
| {{#invoke:String/sandbox|match|a (1) (2) (3) (4) (5) (6) (a)|%((%d)%)||-6}} | 1 | 1 | |
| {{#invoke:String/sandbox|match|a (1) (2) (3) (4) (5) (6) (a)|%((%d)%)||-7|no_category=true}} | String Module Error: Match not found | String Module Error: Match not found |
test_find
| Text | Expected | Actual | |
|---|---|---|---|
| {{#invoke:String/sandbox|find|}} | 0 | 0 | |
| {{#invoke:String/sandbox|find|source=}} | 0 | 0 | |
| {{#invoke:String/sandbox|find|source=|target=}} | 0 | 0 | |
| {{#invoke:String/sandbox|find|source=|target=Bob}} | 0 | 0 | |
| {{#invoke:String/sandbox|find|Bob|Joe}} | 0 | 0 | |
| {{#invoke:String/sandbox|find|Bob|b}} | 3 | 3 | |
| {{#invoke:String/sandbox|find|Bob Joe|oe}} | 6 | 6 | |
| {{#invoke:String/sandbox|find|source= Bob |o}} | 2 | 2 | |
| {{#invoke:String/sandbox|find| Bob |o}} | 3 | 3 | |
| {{#invoke:String/sandbox|find|높지만 급격히|만}} | 3 | 3 | |
| {{#invoke:String/sandbox|find|source=BAAAB|target=%w|plain=false}} | 1 | 1 | |
| {{#invoke:String/sandbox|find|source=BAAAB|target=%w|start=3|plain=false}} | 3 | 3 | |
| {{#invoke:String/sandbox|find|source=BAAAB|target=(%w)%1|plain=false}} | 2 | 2 |
test_rep
| Text | Expected | Actual | |
|---|---|---|---|
| {{#invoke:String|rep|abc|1}} | abc | abc | |
| {{#invoke:String|rep|a b|7}} | a ba ba ba ba ba ba b | a ba ba ba ba ba ba b | |
| {{#invoke:String|rep|bla|glug|no_category=true}} | String Module Error: function rep expects a number as second parameter, received "glug" | String Module Error: function rep expects a number as second parameter, received "glug" | |
| {{#invoke:String|rep|bla|glug|ignore_errors=true}} | |||
| {{#invoke:String|rep|àèò|3}} | àèòàèòàèò | àèòàèòàèò | |
| {{#invoke:String/sandbox|rep|abc|1}} | abc | abc | |
| {{#invoke:String/sandbox|rep|a b|7}} | a ba ba ba ba ba ba b | a ba ba ba ba ba ba b | |
| {{#invoke:String/sandbox|rep|bla|glug|no_category=true}} | String Module Error: function rep expects a number as second parameter, received "glug" | String Module Error: function rep expects a number as second parameter, received "glug" | |
| {{#invoke:String/sandbox|rep|bla|glug|ignore_errors=true}} | |||
| {{#invoke:String/sandbox|rep|àèò|3}} | àèòàèòàèò | àèòàèòàèò |
test_escapePattern
| Text | Expected | Actual | |
|---|---|---|---|
| {{#invoke:String/sandbox|escapePattern|foo}} | foo | foo | |
| {{#invoke:String/sandbox|escapePattern|A.D.}} | A%.D%. | A%.D%. | |
| {{#invoke:String/sandbox|escapePattern|0123}} | 0123 | 0123 | |
| {{#invoke:String/sandbox|escapePattern|^}} | %^ | %^ | |
| {{#invoke:String/sandbox|escapePattern|$}} | %$ | %$ | |
| {{#invoke:String/sandbox|escapePattern|(}} | %( | %( | |
| {{#invoke:String/sandbox|escapePattern|)}} | %) | %) | |
| {{#invoke:String/sandbox|escapePattern|%}} | %% | %% | |
| {{#invoke:String/sandbox|escapePattern|.}} | %. | %. | |
| {{#invoke:String/sandbox|escapePattern|[}} | %[ | %[ | |
| {{#invoke:String/sandbox|escapePattern|]}} | %] | %] | |
| {{#invoke:String/sandbox|escapePattern|*}} | %* | %* | |
| {{#invoke:String/sandbox|escapePattern|+}} | %+ | %+ | |
| {{#invoke:String/sandbox|escapePattern|-}} | %- | %- | |
| {{#invoke:String/sandbox|escapePattern|?}} | %? | %? | |
| {{#invoke:String/sandbox|escapePattern|!}} | ! | ! | |
| {{#invoke:String/sandbox|escapePattern|"}} | " | " | |
| {{#invoke:String/sandbox|escapePattern|&}} | & | & | |
| {{#invoke:String/sandbox|escapePattern|'}} | ' | ' | |
| {{#invoke:String/sandbox|escapePattern|{}} | { | { | |
| {{#invoke:String/sandbox|escapePattern|}}} | } | } | |
| {{#invoke:String/sandbox|escapePattern|`}} | ` | ` | |
| {{#invoke:String/sandbox|escapePattern|@}} | @ | @ | |
| {{#invoke:String/sandbox|escapePattern|,}} | , | , | |
| {{#invoke:String/sandbox|escapePattern|<}} | < | < | |
| {{#invoke:String/sandbox|escapePattern|>}} | > | > | |
| {{#invoke:String/sandbox|escapePattern|/}} | / | / | |
| {{#invoke:String/sandbox|escapePattern|_}} | _ | _ | |
| {{#invoke:String/sandbox|escapePattern|\}} | \ | \ | |
| {{#invoke:String/sandbox|escapePattern|~}} | ~ | ~ | |
| {{#invoke:String/sandbox|escapePattern| }} | |||
| {{#invoke:String/sandbox|escapePattern|}} | |||
| {{#invoke:String/sandbox|escapePattern|x#}} | x# | x# | |
| {{#invoke:String/sandbox|escapePattern|x;}} | x; | x; | |
| {{#invoke:String/sandbox|escapePattern|x:}} | x: | x: | |
| {{#invoke:String/sandbox|escapePattern|{{!}}}} | |||
| {{#invoke:String/sandbox|escapePattern|1==}} | = | = | |
| {{#invoke:String/sandbox|escapePattern|no_category=true}} | String Module Error: No pattern string specified | String Module Error: No pattern string specified |
test_join
| Text | Expected | Actual | |
|---|---|---|---|
| {{#invoke:String/sandbox|join|}} | |||
| {{#invoke:String/sandbox|join|X}} | |||
| {{#invoke:String/sandbox|join|X|a}} | a | a | |
| {{#invoke:String/sandbox|join|X|a|b}} | aXb | aXb | |
| {{#invoke:String/sandbox|join|X|a|b|c}} | aXbXc | aXbXc | |
| {{#invoke:String/sandbox|join|X|a|b|c|d}} | aXbXcXd | aXbXcXd | |
| {{#invoke:String/sandbox|join|X|a|b||d}} | aXbXd | aXbXd | |
| {{#invoke:String/sandbox|join|X|a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z}} | aXbXcXdXeXfXgXhXiXjXkXlXmXnXoXpXqXrXsXtXuXvXwXxXyXz | aXbXcXdXeXfXgXhXiXjXkXlXmXnXoXpXqXrXsXtXuXvXwXxXyXz |
Module source
local p = require('Module:UnitTests')
function p:test_len()
self:preprocess_equals_many('{{#invoke:String/sandbox|len|', '}}', {
{' foo ', '5'},
{'s= foo ', '3'},
{'', '0'},
{'s=', '0'},
{' ', '3'},
{'最近の更新', '5'},
})
end
function p:test_replace()
self:preprocess_equals_many('{{#invoke:String/sandbox|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/sandbox|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
function p:test_match()
local cases = {
{'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', ''},
}
self:preprocess_equals_many('{{#invoke:String|match|', '}}', cases)
self:preprocess_equals_many('{{#invoke:String/sandbox|match|', '}}', cases)
end
function p:test_match_reverse()
local cases = {
{'a (1) (2) (3) (4) (5) (6) (a)|%((%d)%)||-1', '6'},
{'a (1) (2) (3) (4) (5) (6) (a)|%((%d)%)||-2', '5'},
{'a (1) (2) (3) (4) (5) (6) (a)|%((%d)%)||-4', '3'},
{'a (1) (2) (3) (4) (5) (6) (a)|%((%d)%)||-5', '2'},
{'a (1) (2) (3) (4) (5) (6) (a)|%((%d)%)||-6', '1'},
{'a (1) (2) (3) (4) (5) (6) (a)|%((%d)%)||-7|no_category=true', '<strong class="error">String Module Error: Match not found</strong>'},
}
self:preprocess_equals_many('{{#invoke:String|match|', '}}', cases)
self:preprocess_equals_many('{{#invoke:String/sandbox|match|', '}}', cases)
end
function p:test_find()
self:preprocess_equals_many('{{#invoke:String/sandbox|find|', '}}', {
{'', '0'},
{'source=', '0'},
{'source=|target=', '0'},
{'source=|target=Bob', '0'},
{'Bob|Joe', '0'},
{'Bob|b', '3'},
{'Bob Joe|oe', '6'},
{'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'},
})
end
function p:test_rep()
self:preprocess_equals_many('{{#invoke:String|rep|', '}}', {
{'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', 'àèòàèòàèò'}
})
self:preprocess_equals_many('{{#invoke:String/sandbox|rep|', '}}', {
{'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', 'àèòàèòàèò'}
})
end
function p:test_escapePattern()
self:preprocess_equals_many('{{#invoke:String/sandbox|escapePattern|', '}}', {
{'foo', 'foo'},
{'A.D.', 'A%.D%.'},
{'0123', '0123'},
{'^', '%^'},
{'$', '%$'},
{'(', '%('},
{')', '%)'},
{'%', '%%'},
{'.', '%.'},
{'[', '%['},
{']', '%]'},
{'*', '%*'},
{'+', '%+'},
{'-', '%-'},
{'?', '%?'},
{'!', '!'},
{'"', '"'},
{'&', '&'},
{"'", "'"},
{'{', '{'},
{'}', '}'},
{'`', '`'},
{'@', '@'},
{',', ','},
{'<', '<'},
{'>', '>'},
{'/', '/'},
{'_', '_'},
{'\\', '\\'},
{'~', '~'},
{' ', ' '},
{'', ''},
{'x#', 'x#'}, -- We can't just test "#" because it will be interpreted as a list
{'x;', 'x;'}, -- We can't just test ";" because it will be interpreted as a list
{'x:', 'x:'}, -- We can't just test ":" because it will be interpreted as a list
{'{{!}}', '|'}, -- Need to escape the template pipe syntax
{'1==', '='}, -- Need to escape the "foo = bar" template syntax
{'no_category=true', '<strong class="error">String Module Error: No pattern string specified</strong>'},
})
end
function p:test_join()
self:preprocess_equals_many('{{#invoke:String/sandbox|join|', '}}', {
{'', ''},
{'X', ''},
{'X|a', 'a'},
{'X|a|b', 'aXb'},
{'X|a|b|c', 'aXbXc'},
{'X|a|b|c|d', 'aXbXcXd'},
{'X|a|b||d', 'aXbXd'},
{'X|a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z', 'aXbXcXdXeXfXgXhXiXjXkXlXmXnXoXpXqXrXsXtXuXvXwXxXyXz'}
})
end
return p