Module:pi-decl/noun/testcases

local tests = require('Module:UnitTests')

local links = require("Module:links") local lang = require("Module:languages").getByCode("pi") local m_scripts = require("Module:scripts") local m_decl_noun = require('Module:pi-decl/noun')

local gsub = mw.ustring.gsub local match = mw.ustring.match local sub = mw.ustring.sub local u = mw.ustring.char

local genders = { ["m"] = "masculine", ["f"] = "feminine", ["n"] = "neuter", } local rows = { "Nominative (first)", "Accusative (second)", "Instrumental (third)", "Dative (fourth)", "Ablative (fifth)", "Genitive (sixth)", "Locative (seventh)", "Vocative (calling)", }

local endings = { ["one"] = { -- key    Latn  Thai Deva       Beng       Mymr       Lana     Laoo       Khmr            Sinh     Brah ["ā"] = { "ā",  "า", "ा", "आ", "া", "আ", "ါ", "ာ", "ᩣ", "ᩤ", "າ",       "ា", u(0x17A4), "ා", "ආ", "𑀸", "𑀆" }, ["i"] = { "i",  "ิ",  "ि", "इ",  "ি", "ই", "ိ", "ဣ",  "ᩥ", "ᩍ", "ິ",        "ិ", "ឥ",       "ි", "ඉ", "𑀺", "𑀇" }, ["ī"] = { "ī",  "ี",  "ी", "ई",  "ী", "ঈ", "ီ", "ဤ", "ᩦ", "ᩎ", "ີ",        "ី", "ឦ",       "ී", "ඊ", "𑀻", "𑀈" }, ["u"] = { "u",  "ุ",  "ु", "उ",  "ু", "উ", "ု", "ဥ",  "ᩩ", "ᩏ",  "ຸ",        "ុ", "ឧ",        "ු", "උ", "𑀼", "𑀉" }, ["ū"] = { "ū",  "ู",  "ू", "ऊ",  "ূ", "ঊ", "ူ", "ဦ",  "ᩪ", "ᩐ",  "ູ",        "ូ", "ឨ", "ឩ",  "ූ", "ඌ", "𑀽", "𑀊" }, },	["two"] = { -- key    Latn  Thai Deva       Beng       Mymr       Lana     Laoo       Khmr            Sinh     Brah ["ar"] = { "ar", "รฺ", "र्",      "র্",      "ရ်",       "ᩁ᩺", "ᩁ᩼", "ຣ໌", "ຣ຺", "រ៑",             "ර්",     "𑀭𑁆"     }, ["as"] = { "as", "สฺ", "स्",     "স্",      "သ်",      "ᩈ᩺", "ᩈ᩼", "ສ໌", "ສ຺", "ស៑",           "ස්",     "𑀲𑁆"    }, ["an"] = { "an", "นฺ", "न्",     "ন্",      "န်",       "ᨶ᩺", "ᨶ᩼",  "ນ໌", "ນ຺", "ន៑",           "න්",     "𑀦𑁆"     }, ["in"] = { "in", } -- Only simple for Roman script. }, }

function tests.detectEnding(stem)

local oneLetter = sub(stem, -1) for key, arr in pairs(endings.one) do		for _, val in ipairs(arr) do			if oneLetter == val then return key end end end local twoLetters = sub(stem, -2) for key, arr in pairs(endings.two) do		for _, val in ipairs(arr) do			if twoLetters == val then return key end end end

return "a"

end

function tests.joinSuffix(stem, suffixes)

local output = "" local term

for _,suffix in ipairs(suffixes) do		if match(suffix, "^⌫⌫") then --backspace term = sub(stem, 1, -3) .. sub(suffix, 3, -1) elseif match(suffix, "^⌫") then --backspace term = sub(stem, 1, -2) .. sub(suffix, 2, -1) else term = stem .. suffix end if scriptCode == "Thai" then term = gsub(term, "(.)↶([เโ])", "%2%1") --swap --term = gsub(term, "[ญฐ]", "%1" .. u(0xFE00)) *currently no font supports end if scriptCode == "Mymr" then term = gsub(term, "င္", "င်္") term = gsub(term, "(င်္)([ဝခဂငဒပ])(ေ?)ာ", "%1%2%3ါ") term = gsub(term, "္[ယရ]", { ["္ယ"] = "ျ", ["္ရ"] = "ြ" }) --these not need tall aa			term = gsub(term, "^([ဝခဂငဒပ])(ေ?)ာ", "%1%2ါ") term = gsub(term, "([^္])([ဝခဂငဒပ])(ေ?)ာ", "%1%2%3ါ") term = gsub(term, "([ဝခဂငဒပ])(္[က-အဿ])(ေ?)ာ", "%1%2%3ါ") term = gsub(term, "္[ဝဟ]", { ["္ဝ"] = "ွ", ["္ဟ"] = "ှ" }) term = gsub(term, "ဉ္ဉ", "ည") term = gsub(term, "သ္သ", "ဿ") --term = gsub(term, "[ကဂငတထပမယလဝေ]", "%1" .. u(0xFE00)) *currently no font supports end if scriptCode == "Lana" then term = gsub(term, "ᨦ᩠", "ᩘ") term = gsub(term, "^([ᩅᨣᨵᨷᨻ])(ᩮ?)ᩣ", "%1%2ᩤ") term = gsub(term, "([^᩠])([ᩅᨣᨵᨷᨻ])(ᩮ?)ᩣ", "%1%2%3ᩤ") term = gsub(term, "([ᩅᨣᨵᨷᨻ])(᩠[ᨠ-ᩌᩔ])(ᩮ?)ᩣ", "%1%2%3ᩤ") term = gsub(term, "᩠[ᩁᩃ]", { ["᩠ᩁ"] = "ᩕ", ["᩠ᩃ"] = "ᩖ" }) term = gsub(term, "([ᨭ-ᨱ])᩠ᨮ", "%1ᩛ") term = gsub(term, "([ᨷ-ᨾ])᩠ᨻ", "%1ᩛ") term = gsub(term, "ᩈ᩠ᩈ", "ᩔ") end if output ~= "" then output = output .. " or " end output = output .. links.full_link({lang = lang, sc = currentScript, term = term, tr='-'}) end

return output

end

function tests.show(frame)

local args = frame:getParent.args local PAGENAME = mw.title.getCurrentTitle.text local stem = args[1] or args["stem"] or PAGENAME currentScript = lang:findBestScript(stem) scriptCode = currentScript:getCode local ending = args[2] or args["ending"] or tests.detectEnding(stem) local g = args[3] or args["g"] or args["gender"] -- for each gender only

if not g then error("A gender is required to display proper declensions.") end

local pattern = require("Module:pi-decl/noun/" .. scriptCode) or nil local selectedPattern = pattern[ending][g]

local output = ' Declension table of "' .. stem .. '" (' .. genders[g] .. ') ' output = output .. ' "	return output

end

function tests:test_big_bang -- here be the tests --preprocess_equals(text, expected, options)

tests:preprocess_equals_preprocess(, ) --, {["nowiki"]=1})   tests:preprocess_equals_preprocess(, ) -- , {["nowiki"]=1}) tests:preprocess_equals_preprocess(, ) --, {["nowiki"]=1})   tests:preprocess_equals_preprocess(, ) -- , {["nowiki"]=1}) tests:preprocess_equals_preprocess(, ) --, {["nowiki"]=1})   tests:preprocess_equals_preprocess(, ) -- , {["nowiki"]=1}) tests:preprocess_equals_preprocess(, ) --, {["nowiki"]=1})   tests:preprocess_equals_preprocess(, ) -- , {["nowiki"]=1}) tests:preprocess_equals_preprocess(, ) --, {["nowiki"]=1})   tests:preprocess_equals_preprocess(, ) -- , {["nowiki"]=1}) tests:preprocess_equals_preprocess(, ) --, {["nowiki"]=1})   tests:preprocess_equals_preprocess(, ) -- , {["nowiki"]=1}) tests:preprocess_equals_preprocess(, ) --, {["nowiki"]=1})   tests:preprocess_equals_preprocess(, ) -- , {["nowiki"]=1}) tests:preprocess_equals_preprocess(, ) --, {["nowiki"]=1})   tests:preprocess_equals_preprocess(, ) -- , {["nowiki"]=1}) -- Check masculine -in and -ī are equivalent, and neuter -in and -i tests:preprocess_equals_preprocess(, ) --, {["nowiki"]=1})   tests:preprocess_equals_preprocess('', '') --, {["nowiki"]=1}) end

local spaceJoin = function(vals) output = "" for i, v in ipairs(vals) do		if output == "" then output = v		else output = output.." "..v		end end return output end

-- Argument is either a list of script codes or a single script code. function tests:script_consistency_test(script_list, option) local scripts if type(script_list) == 'table' then scripts = script_list else -- Assume string scripts = {script_list} end -- The words must not have exercised options in spellings. local words = {{"buddha", "m"}, {"kaññā", "f"}, {"aṅga", "n"}, -- buddha and aṅga will need replacing. {"aggi", "m"}, {"bodhi", "f"}, {"aṭṭhi", "n"}, {"bandhu", "m"}, {"dhenu", "f"}, {"cakkhu", "n"}, {"balī", "m"}, {"yakkhī", "f"}, {"viññū", "m"}, {"sassū", "f"}, {"candimā", "m"}, {"kattar", "m"}, {"sotas", "n"}, {"attan", "m"}, {"kathin", "m"}, {"pacant", "m"}, {"gacchant", "n"}, {"desent", "m"}, {"desent", "n"}, {"karont", "m"}, {"karont", "n"}, {"bhagavant", "m"}, {"saravant", "n"}, {"āyasmant", "m"}, {"āyasmant", "n"}, }	local caseFormList, mergedList = {}, {} local scrCaseFormList, scrMergedList = {}, {} local xCaseFormList, xMergedList = {}, {} local m_xlit = require("Module:pi-Latn-translit") local latEnd, latPat local script, sword, scrEnd, scrPat local errcnt = 0 local analysis = "" for wi, wv in ipairs(words) do		latEnd = m_decl_noun.detectEnding(wv[1], nil) latPat = m_decl_noun.getSuffixes("Latn", latEnd, wv[2]) for i = 1, 16 do			caseFormList[i] = m_decl_noun.joinSuffix("Latn", wv[1], latPat[i]) mergedList[i] = m_decl_noun.orJoin(m_scripts.getByCode("Latn"), caseFormList[i]) end for _, sv in ipairs(scripts) do			script = m_scripts.getByCode(sv) sword = m_xlit.tr(wv[1], sv, option) scrEnd = m_decl_noun.detectEnding(sword, option) scrPat = m_decl_noun.getSuffixes(sv, scrEnd, wv[2], option) if scrPat then for i = 1, 16 do					scrCaseFormList[i] = m_decl_noun.joinSuffix(sv, sword, scrPat[i]) scrMergedList[i] = m_decl_noun.orJoin(script, scrCaseFormList[i], option) xCaseFormList[i] = {} for ai, av in ipairs(caseFormList[i]) do						xCaseFormList[i][ai] = m_xlit.tr(av, sv, option) end xMergedList[i] = m_decl_noun.orJoin(script, xCaseFormList[i], option) --				equals(name, actual, expected, options) local ic, ino ic, ino = math.modf((i+1)/2) local number if ino == 0 then number = " s." else number = " pl." end if scrMergedList[i] == xMergedList[i] then tests:equals(sword.." "..rows[ic]..number, scrMergedList[i], xMergedList[i]) else -- comment doesn't work easily. tests:equals(sword.." "..rows[ic]..number, 							scrMergedList[i].." Roman script: "..mergedList[i],							xMergedList[i]) end end else tests:equals(sword, "No paradigm for "..wv[1], "") end end end tests:heading("'Expected' is Roman script with inflexions converted to other script.") end

-- To reinstate the following as a test, remove 'dont_' from the name! The testing has been delegated to the -- individual scripts' test cases. function tests:dont_test_consistency -- Check that different scripts have the same endings. local scripts = {"Beng", "Brah", "Deva", "Khmr", "Lana", "Laoo", "Mymr", "Sinh", "Thai"} tests:script_consistency_test(scripts) local dual = {"Laoo", "Thai"} tests:script_consistency_test(dual) end

function tests.remove_noun_tests tests.test_big_bang = nil tests.test_consistency = nil end

return tests