Mô đun:String/testcases

Từ Từ điển tri thức Hội Thánh của Đức Chúa Trời
Bước tới điều hướng Bước tới tìm kiếm

Có thể viết tài liệu về mô đun này tại Mô đun:String/testcases/tài liệu.

-- Các trường hợp kiểm thử đơn vị cho [[Mô đun:String]]. Mở trang thảo luận để chạy các
-- trường hợp kiểm thử.
local p = require('Mô đun:UnitTests')
 
function p:test_len()
    self:preprocess_equals_many('{{#gọi:String/sandbox|len|', '}}', {
        {' foo ', '5'},
        {'s= foo ', '3'},
        {'', '0'},
        {'s=', '0'},
        {'   ', '3'},
        {'最近の更新', '5'},
    })
end

function p:test_replace()
    self:preprocess_equals_many('{{#gọi: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('{{#gọi: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">Lỗi mô đun String: Không tìm thấy kết quả</strong>'},
        {'dog (cat)|%((%a-)%)||2|ignore_errors=true', ''},
    })
end
function p:test_match()
    self:preprocess_equals_many('{{#gọi: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">Lỗi mô đun String: Không tìm thấy kết quả</strong>'},
        {'dog (cat)|%((%a-)%)||2|ignore_errors=true', ''},
    })
end

function p:test_find()
    self:preprocess_equals_many('{{#gọi: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('{{#gọi: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">Lỗi mô đun String: tham số thứ 2 của hàm rep có giá trị "glug" thay cho số</strong>'},
        {'bla|glug|ignore_errors=true', ''},
        {'àèò|3', 'àèòàèòàèò'}
    })
end

return p