Module:User:Chernorizets/bg-orthography/testcases
Appearance
- The following documentation is located at Module:User:Chernorizets/bg-orthography/testcases/documentation. [edit]
- Useful links: root page • root page’s subpages • links • transclusions • tested module • sandbox
All tests passed. (refresh)
Text | Expected | Actual | |
---|---|---|---|
is_valid(nil, nil) | |||
return value | false | false | |
failed rule | no input | no input | |
is_valid(, nil) | |||
return value | true | true | |
failed rule | (nil) | (nil) | |
is_valid(nil, { nil_is_valid }) | |||
return value | true | true | |
failed rule | (nil) | (nil) | |
is_valid(колан, nil) | |||
return value | true | true | |
failed rule | (nil) | (nil) | |
is_valid(Станислав, nil) | |||
return value | true | true | |
failed rule | (nil) | (nil) | |
is_valid(КОРЕКОМ, nil) | |||
return value | true | true | |
failed rule | (nil) | (nil) | |
is_valid(бърЗовар, nil) | |||
return value | false | false | |
failed rule | valid letter case | valid letter case | |
is_valid(ОрангутаН, nil) | |||
return value | false | false | |
failed rule | valid letter case | valid letter case | |
is_valid(траЛалаЛА, nil) | |||
return value | false | false | |
failed rule | valid letter case | valid letter case | |
is_valid(БЬОРК, nil) | |||
return value | true | true | |
failed rule | (nil) | (nil) | |
is_valid(Бьорк, nil) | |||
return value | true | true | |
failed rule | (nil) | (nil) | |
is_valid(миньор, nil) | |||
return value | true | true | |
failed rule | (nil) | (nil) | |
is_valid(бельо, nil) | |||
return value | true | true | |
failed rule | (nil) | (nil) | |
is_valid(Ьордан, nil) | |||
return value | false | false | |
failed rule | correct use of ьЬ | correct use of ьЬ | |
is_valid(ьерархия, nil) | |||
return value | false | false | |
failed rule | correct use of ьЬ | correct use of ьЬ | |
is_valid(конь, nil) | |||
return value | false | false | |
failed rule | correct use of ьЬ | correct use of ьЬ | |
is_valid(коьот, nil) | |||
return value | false | false | |
failed rule | correct use of ьЬ | correct use of ьЬ | |
is_valid(ваььар, nil) | |||
return value | false | false | |
failed rule | correct use of ьЬ | correct use of ьЬ | |
is_valid(Facebook, nil) | |||
return value | true | true | |
failed rule | (nil) | (nil) | |
is_valid(VIP, nil) | |||
return value | true | true | |
failed rule | (nil) | (nil) | |
is_valid(TOEFL, nil) | |||
return value | true | true | |
failed rule | (nil) | (nil) | |
is_valid(Туитър, nil) | |||
return value | true | true | |
failed rule | (nil) | (nil) | |
is_valid(Fейсбук, nil) | |||
return value | false | false | |
failed rule | no alphabet mixing | no alphabet mixing | |
is_valid(VIП, nil) | |||
return value | false | false | |
failed rule | no alphabet mixing | no alphabet mixing | |
is_valid(караванaта, nil) | |||
return value | false | false | |
failed rule | no alphabet mixing | no alphabet mixing | |
is_valid(окoкорихме, nil) | |||
return value | false | false | |
failed rule | no alphabet mixing | no alphabet mixing |
Text | Expected | Actual | |
---|---|---|---|
is_valid(3.14): error | {message="Input must be a string!", status=false} | {message="Input must be a string!", status=false} | |
is_valid(true): error | {message="Input must be a string!", status=false} | {message="Input must be a string!", status=false} | |
is_valid(function): error | {message="Input must be a string!", status=false} | {message="Input must be a string!", status=false} | |
is_valid(table): error | {message="Input must be a string!", status=false} | {message="Input must be a string!", status=false} |
local tests = require("Module:UnitTests")
local m_ortho = require("Module:User:Chernorizets/bg-orthography")
local is_valid = m_ortho.is_valid
local test_cases = {
{ word = nil, expected_ret = false, expected_rule = "no input" },
{ word = "", expected_ret = true, expected_rule = nil },
{
word = nil,
opts = { nil_is_valid = true },
opts_hint = "{ nil_is_valid }",
expected_ret = true,
expected_rule = nil
},
-- Valid letter case.
{ word = "колан", expected_ret = true, expected_rule = nil },
{ word = "Станислав", expected_ret = true, expected_rule = nil },
{ word = "КОРЕКОМ", expected_ret = true, expected_rule = nil },
-- Invalid letter case
{ word = "бърЗовар", expected_ret = false, expected_rule = "valid letter case" },
{ word = "ОрангутаН", expected_ret = false, expected_rule = "valid letter case" },
{ word = "траЛалаЛА", expected_ret = false, expected_rule = "valid letter case" },
-- Valid use of Ьь
{ word = "БЬОРК", expected_ret = true, expected_rule = nil },
{ word = "Бьорк", expected_ret = true, expected_rule = nil },
{ word = "миньор", expected_ret = true, expected_rule = nil },
{ word = "бельо", expected_ret = true, expected_rule = nil },
-- Invalid use of Ьь
{ word = "Ьордан", expected_ret = false, expected_rule = "correct use of ьЬ" },
{ word = "ьерархия", expected_ret = false, expected_rule = "correct use of ьЬ" },
{ word = "конь", expected_ret = false, expected_rule = "correct use of ьЬ" },
{ word = "коьот", expected_ret = false, expected_rule = "correct use of ьЬ" },
{ word = "ваььар", expected_ret = false, expected_rule = "correct use of ьЬ" },
-- No alphabet mixing.
{ word = "Facebook", expected_ret = true, expected_rule = nil },
{ word = "VIP", expected_ret = true, expected_rule = nil },
{ word = "TOEFL", expected_ret = true, expected_rule = nil },
{ word = "Туитър", expected_ret = true, expected_rule = nil },
-- Some alphabet mixing
{ word = "Fейсбук", expected_ret = false, expected_rule = "no alphabet mixing" },
{ word = "VIП", expected_ret = false, expected_rule = "no alphabet mixing" },
-- Some of the a's and o's below are Latin vs. Cyrillic (tough to spot)
{ word = "караванaта", expected_ret = false, expected_rule = "no alphabet mixing" },
{ word = "окoкорихме", expected_ret = false, expected_rule = "no alphabet mixing" },
}
local function make_heading(test_case)
local word, opts = test_case.word, test_case.opts
local word_arg = word and word or "nil"
local opts_arg = opts and test_case.opts_hint or "nil"
return ("is_valid(%s, %s)"):format(word_arg, opts_arg)
end
function tests:check_single_case(test_case)
local ret, rule = is_valid(test_case.word, test_case.opts)
tests:header(make_heading(test_case))
tests:equals("return value", ret, test_case.expected_ret)
tests:equals("failed rule", rule, test_case.expected_rule)
end
function tests:test_is_valid()
for _, test_case in ipairs(test_cases) do
tests:check_single_case(test_case)
end
end
local malformed_input_cases = {
3.14, -- number
true, -- boolean
function(a, b) return a + b end, -- function
{}, -- table
}
function tests:check_malformed_input(input)
local status, message = pcall(is_valid, input)
local ret = {
status = status,
message = mw.ustring.gsub(message, "(.-): (.*)", "%2")
}
tests:equals_deep("is_valid(" .. tostring(input) .. "): error", ret, {
status = false,
message = "Input must be a string!"
})
end
function tests:test_malformed_input()
for _, input in ipairs(malformed_input_cases) do
tests:check_malformed_input(input)
end
end
return tests