Difference between revisions of "Module:String/testcases"

From blackwiki
Jump to navigation Jump to search
blackwiki>קיפודנחש
(rep)
blackwiki>Mr. Stradivarius
(test sandbox version)
Line 3: Line 3:
 
   
 
   
 
function p:test_len()
 
function p:test_len()
     self:preprocess_equals_many('{{#invoke:String|len|', '}}', {
+
     self:preprocess_equals_many('{{#invoke:String/sandbox|len|', '}}', {
 
         {' foo ', '5'},
 
         {' foo ', '5'},
 
         {'s= foo ', '3'},
 
         {'s= foo ', '3'},
Line 14: Line 14:
  
 
function p:test_replace()
 
function p:test_replace()
     self:preprocess_equals_many('{{#invoke:String|replace|', '}}', {
+
     self:preprocess_equals_many('{{#invoke:String/sandbox|replace|', '}}', {
 
         {'1.1.1.1|.|/', '1/1/1/1'},
 
         {'1.1.1.1|.|/', '1/1/1/1'},
 
         {'alpha (beta)| (| gamma (', 'alpha gamma (beta)'},
 
         {'alpha (beta)| (| gamma (', 'alpha gamma (beta)'},
Line 22: Line 22:
  
 
function p:test_match()
 
function p:test_match()
     self:preprocess_equals_many('{{#invoke:String|match|', '}}', {
+
     self:preprocess_equals_many('{{#invoke:String/sandbox|match|', '}}', {
 
         {'dog (cat)|%((%a-)%)', 'cat'},
 
         {'dog (cat)|%((%a-)%)', 'cat'},
 
         {'dog (cat) (canary) (fish)|%((%a-)%)||-1', 'fish'},
 
         {'dog (cat) (canary) (fish)|%((%a-)%)||-1', 'fish'},
Line 33: Line 33:
 
end
 
end
 
function p:test_match()
 
function p:test_match()
     self:preprocess_equals_many('{{#invoke:String|match|', '}}', {
+
     self:preprocess_equals_many('{{#invoke:String/sandbox|match|', '}}', {
 
         {'dog (cat)|%((%a-)%)', 'cat'},
 
         {'dog (cat)|%((%a-)%)', 'cat'},
 
         {'dog (cat) (canary) (fish)|%((%a-)%)||-1', 'fish'},
 
         {'dog (cat) (canary) (fish)|%((%a-)%)||-1', 'fish'},
Line 45: Line 45:
  
 
function p:test_find()
 
function p:test_find()
     self:preprocess_equals_many('{{#invoke:String|find|', '}}', {
+
     self:preprocess_equals_many('{{#invoke:String/sandbox|find|', '}}', {
 
         {'', '0'},
 
         {'', '0'},
 
         {'source=', '0'},
 
         {'source=', '0'},
Line 63: Line 63:
  
 
function p:test_rep()
 
function p:test_rep()
     self:preprocess_equals_many('{{#invoke:String|rep|', '}}', {
+
     self:preprocess_equals_many('{{#invoke:String/sandbox|rep|', '}}', {
 
         {'abc|1', 'abc'},
 
         {'abc|1', 'abc'},
 
         {'a b|7', 'a ba ba ba ba ba ba b'},
 
         {'a b|7', 'a ba ba ba ba ba ba b'},

Revision as of 10:38, 26 April 2013

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

-- 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/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()
    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_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/sandbox|rep|', '}}', {
        {'abc|1', 'abc'},
        {'a b|7', 'a ba ba ba ba ba ba b'},
        {'bla|glug', '<strong class="error">String Module Error: function rep expects a number as second parameter, received "glug"</strong>'},
        {'bla|glug|ignore_errors=true', ''},
    })
end

return p