Module:User:Erutuon/patterns/testcases
Appearance
- The following documentation is located at Module:User:Erutuon/patterns/testcases/documentation. [edit]
- Useful links: root page • root page’s subpages • links • transclusions • tested module • sandbox
All tests passed. (refresh)
Text | Expected | Actual | |
---|---|---|---|
"(%=%=+)([^%=]+)%=%=+" | 🗸true | 🗸true | |
"αειου" | 🗸true | 🗸true | |
"[αειου]" | 🗴false | 🗴false | |
"%[%%%s%]" | 🗴false | 🗴false | |
"%[αειου%]" | 🗸true | 🗸true | |
"[ae][ʊɪ]" | 🗴false | 🗴false | |
"a?" | 🗸true | 🗸true | |
"α?" | 🗴false | 🗴false | |
"a*" | 🗸true | 🗸true | |
"α*" | 🗴false | 🗴false | |
"a-" | 🗸true | 🗸true | |
"α-" | 🗴false | 🗴false | |
"a+" | 🗸true | 🗸true | |
"α+" | 🗴false | 🗴false | |
"a.b" | 🗴false | 🗴false |
local tests = require("Module:UnitTests")
local canUseString = require("Module:User:Erutuon/patterns").canUseString
local highlight = require("Module:debug").highlight
highlight = highlight{ inline = true }
local function LuaString(text)
return highlight('"' .. text .. '"')
end
local function displayBoolean(text)
local color, emoji
if text == "false" then
color = "red"
emoji = "🗴"
elseif text == "true" then
color = "green"
emoji = "🗸"
end
return emoji .. '<code><span style="color: ' .. (color or '') .. ';">' .. text .. '</span></code>'
end
local options = { display = displayBoolean }
function tests:check(example, expected)
self:equals(LuaString(example), canUseString(example), expected, options)
end
tests["test canUseString"] = function (self)
local examples = {
{ "(%=%=+)([^%=]+)%=%=+", true }, -- section heading
{ "αειου", true },
{ "[αειου]", false }, -- Greek lowercase vowel letter
{ "%[%%%s%]", false },
{ "%[αειου%]", true },
{ "[ae][ʊɪ]", false }, -- needs an actual example
{ "a?", true },
{ "α?", false },
{ "a*", true },
{ "α*", false },
{ "a-", true },
{ "α-", false },
{ "a+", true },
{ "α+", false },
{ "a.b", false },
}
self:iterate(examples, "check")
end
return tests