Module:affix/testcases

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,		" " .. 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", "",			contains "English words prefixed with fore-|", },		{			"contains derived-from category", "",			contains "English terms derived from Ancient Greek", },		{			"contains suffixed-with category", "",			contains "English words suffixed with -ism", },		{			"contains category with parenthesis", "",			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