模組:Compound/testcases
3/4成功
失敗:
{{affix|en|lang1=grc|ἡδονή|gloss1=pleasure|-ism}}
派生分類
成功:
{{prefix|en|fore|sight}}
前綴分類{{affix|en|lang1=grc|ἡδονή|gloss1=pleasure|-ism}}
後綴分類{{af|en|wool|-en|id2=made of}}
括號分類
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 = {
{
"前綴分類",
"{{prefix|en|fore|sight}}",
contains "含有前綴fore-的英語詞|",
},
{
"派生分類",
"{{affix|en|lang1=grc|ἡδονή|gloss1=pleasure|-ism}}",
contains "派生自古希臘語的英語詞",
},
{
"後綴分類",
"{{affix|en|lang1=grc|ἡδονή|gloss1=pleasure|-ism}}",
contains "含有後綴-ism的英語詞",
},
{
"括號分類",
"{{af|en|wool|-en|id2=made of}}",
contains "含有後綴-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成功\n"):format(#tester.successes, total))
if #tester.failures > 0 then
output:insert "失敗:"
for _, failure in ipairs(tester.failures) do
output:insert("* " .. failure)
end
end
if #tester.successes > 0 then
output:insert "成功:"
for _, success in ipairs(tester.successes) do
output:insert("* " .. success)
end
end
return output:concat("\n")
end
return export