Module:affix/testcases
Appearance
- The following documentation is located at Module:affix/testcases/documentation. [edit]
- Useful links: root page • root page’s subpages • links • transclusions • tested module • sandbox
1/4 successes
Failures:
{{prefix|en|fore|sight}}
contains prefixed-with category{{affix|en|lang1=grc|ἡδονή|gloss1=pleasure|-ism}}
contains suffixed-with category{{af|en|wool|-en|id2=made of}}
contains category with parenthesis
Successes:
{{affix|en|lang1=grc|ἡδονή|gloss1=pleasure|-ism}}
contains derived-from category
local export = {}
local tester_methods = {}
function tester_methods.do_test(self, statement, template_text, test)
local force_cat_template_text = template_text:gsub("}}$", "|force_cat=1}}")
local expanded = self.frame:preprocess(force_cat_template_text)
local success = test(expanded)
if not success then
mw.log(expanded)
end
table.insert(
success and self.successes or self.failures,
"<code>" .. mw.text.nowiki(template_text) .. "</code> " .. statement)
end
local tester_mt = {
__index = tester_methods,
}
function export.do_tests(frame)
local tester = setmetatable({
frame = frame, successes = {}, failures = {}
}, tester_mt)
local function contains(needle)
return function(haystack)
return haystack:find(needle, 1, true)
end
end
local tests = {
{
"contains prefixed-with category",
"{{prefix|en|fore|sight}}",
contains "English words prefixed with fore-|",
},
{
"contains derived-from category",
"{{affix|en|lang1=grc|ἡδονή|gloss1=pleasure|-ism}}",
contains "English terms derived from Ancient Greek",
},
{
"contains suffixed-with category",
"{{affix|en|lang1=grc|ἡδονή|gloss1=pleasure|-ism}}",
contains "English words suffixed with -ism",
},
{
"contains category with parenthesis",
"{{af|en|wool|-en|id2=made of}}",
contains "English words suffixed with -en (made of)"
}
}
for _, test in ipairs(tests) do
tester:do_test(unpack(test))
end
local output = require "Module:array"()
local total = #tester.successes + #tester.failures
output:insert(("%d/%d successes\n"):format(#tester.successes, total))
if #tester.failures > 0 then
output:insert "Failures:"
for _, failure in ipairs(tester.failures) do
output:insert("* " .. failure)
end
end
if #tester.successes > 0 then
output:insert "Successes:"
for _, success in ipairs(tester.successes) do
output:insert("* " .. success)
end
end
return output:concat("\n")
end
return export