Jump to content

Module:pi-decl/noun/testcases

From Wiktionary, the free dictionary

See also the script-specific tests for Pali declension in the Bengali, Brahmi, Burmese, Chakma, Devanagari, Khmer, Lao, Sinhalese, Tai Tham and Thai scripts. Their results are not included in the result summary given here.

16 of 18 tests failed. (refresh)

TextExpectedActual
test_big_bang:
Failed{{pi-decl-noun|assa|a|g=m}}
Failed{{pi-decl-noun|showtr=none|অঙ্গ|a|g=n}}
Failed{{pi-decl-noun|showtr=none|චන්දිමා|ā|g=m}}
Failed{{pi-decl-noun|showtr=none|अम्मा|ā|g=f}}
Failed{{pi-decl-noun|showtr=none|ဣသိ|i|g=m}}
Failed{{pi-decl-noun|showtr=none|ชาติ|i|g=f}}
Failed{{pi-decl-noun|showtr=none|ᩋᨠ᩠ᨡᩥ|i|g=n}}
Failed{{pi-decl-noun|showtr=none|មានី|ī|g=m}}
Failed{{pi-decl-noun|nadī|ī|g=f}}
Failed{{pi-decl-noun|showtr=none|𑀧𑀁𑀲𑀼|u|g=m}}
Failed{{pi-decl-noun|showtr=none|जम्बु|u|g=f}}
Failed{{pi-decl-noun|showtr=none|জত্তু|u|g=n}}
Failed{{pi-decl-noun|sayambhū|ū|g=m}}
Failed{{pi-decl-noun|vadhū|ū|g=f}}
Failed{{pi-decl-noun|kattar|ar|g=m}}
Failed{{pi-decl-noun|kathin|in|g=m}}
Passed{{pi-decl-noun|kathin|in|g=m}}
Passed{{pi-decl-noun|kathin|in|g=n}}

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 .. " <small style=\"color:888\">or</small> "
		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 = '<div class="NavFrame" style="min-width:30%"><div class="NavHead" style="background:#d9ebff">Declension table of "' .. stem .. '" (' .. genders[g] .. ')</div><div class="NavContent">'
	output = output .. '<table class="inflection-table" style="background:#F9F9F9;text-align:center;width:100%"><tr><th style="background:#eff7ff">Case \\ Number</th><th style="background:#eff7ff">Singular</th><th style="background:#eff7ff">Plural</th></tr>'

	for i,v in ipairs(rows) do
		output = output .. "<tr><td style=\"background-color:#eff7ff;\">" .. v .. "</td>"
		output = output .. "<td>" .. tests.joinSuffix(stem, selectedPattern[2 * i - 1]) .. "</td>"
		output = output .. "<td>" .. tests.joinSuffix(stem, selectedPattern[2 * i]) .. "</td>"
		output = output .. "</tr>"
	end

	output = output .. "</table></div></div>"
	return output

end

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

    tests:preprocess_equals_preprocess('{{pi-decl-noun|assa|a|g=m}}', '{{pi-decl-noun/test1|assa|a|g=m}}') -- , {["nowiki"]=1})
    tests:preprocess_equals_preprocess('{{pi-decl-noun|showtr=none|অঙ্গ|a|g=n}}', '{{pi-decl-noun/test1|অঙ্গ|a|g=n}}') -- , {["nowiki"]=1})
    tests:preprocess_equals_preprocess('{{pi-decl-noun|showtr=none|චන්දිමා|ā|g=m}}', '{{pi-decl-noun/test1|චන්දිමා|ā|g=m}}') -- , {["nowiki"]=1})
    tests:preprocess_equals_preprocess('{{pi-decl-noun|showtr=none|अम्मा|ā|g=f}}', '{{pi-decl-noun/test1|अम्मा|ā|g=f}}') -- , {["nowiki"]=1})
    tests:preprocess_equals_preprocess('{{pi-decl-noun|showtr=none|ဣသိ|i|g=m}}', '{{pi-decl-noun/test1|ဣသိ|i|g=m}}') -- , {["nowiki"]=1})
    tests:preprocess_equals_preprocess('{{pi-decl-noun|showtr=none|ชาติ|i|g=f}}', '{{pi-decl-noun/test1|ชาติ|i|g=f}}') -- , {["nowiki"]=1})
    tests:preprocess_equals_preprocess('{{pi-decl-noun|showtr=none|ᩋᨠ᩠ᨡᩥ|i|g=n}}', '{{pi-decl-noun/test1|ᩋᨠ᩠ᨡᩥ|i|g=n}}') -- , {["nowiki"]=1})
    tests:preprocess_equals_preprocess('{{pi-decl-noun|showtr=none|មានី|ī|g=m}}', '{{pi-decl-noun/test1|មានី|ī|g=m}}') -- , {["nowiki"]=1})
    tests:preprocess_equals_preprocess('{{pi-decl-noun|nadī|ī|g=f}}', '{{pi-decl-noun/test1|nadī|ī|g=f}}') -- , {["nowiki"]=1})
    tests:preprocess_equals_preprocess('{{pi-decl-noun|showtr=none|𑀧𑀁𑀲𑀼|u|g=m}}', '{{pi-decl-noun/test1|𑀧𑀁𑀲𑀼|u|g=m}}') -- , {["nowiki"]=1})
    tests:preprocess_equals_preprocess('{{pi-decl-noun|showtr=none|जम्बु|u|g=f}}', '{{pi-decl-noun/test1|जम्बु|u|g=f}}') -- , {["nowiki"]=1})
    tests:preprocess_equals_preprocess('{{pi-decl-noun|showtr=none|জত্তু|u|g=n}}', '{{pi-decl-noun/test1|জত্তু|u|g=n}}') -- , {["nowiki"]=1})
    tests:preprocess_equals_preprocess('{{pi-decl-noun|sayambhū|ū|g=m}}', '{{pi-decl-noun/test1|sayambhū|ū|g=m}}') -- , {["nowiki"]=1})
    tests:preprocess_equals_preprocess('{{pi-decl-noun|vadhū|ū|g=f}}', '{{pi-decl-noun/test1|vadhū|ū|g=f}}') -- , {["nowiki"]=1})
    tests:preprocess_equals_preprocess('{{pi-decl-noun|kattar|ar|g=m}}', '{{pi-decl-noun/test1|kattar|ar|g=m}}') -- , {["nowiki"]=1})
    tests:preprocess_equals_preprocess('{{pi-decl-noun|kathin|in|g=m}}', '{{pi-decl-noun/test1|kathin|in|g=m}}') -- , {["nowiki"]=1})
-- Check masculine -in and -ī are equivalent, and neuter -in and -i
    tests:preprocess_equals_preprocess('{{pi-decl-noun|kathin|in|g=m}}',
'{{pi-decl-noun|kathī|ī|g=m|label=kathin}}') -- , {["nowiki"]=1})
    tests:preprocess_equals_preprocess('{{pi-decl-noun|kathin|in|g=n}}',
'{{pi-decl-noun|kathi|i|g=n|label=kathin}}') -- , {["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].."<br>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