বিষয়বস্তুতে চলুন

মডিউল:pi-conj/verb/testcases

উইকিঅভিধান, মুক্ত অভিধান থেকে

এই মডিউলের জন্য মডিউল:pi-conj/verb/testcases/নথি-এ নথিপত্র তৈরি করা হয়ে থাকতে পারে

local tests = require('Module:UnitTests')
local m_conj_verb = require('Module:pi-conj/verb')
local to_script = require("Module:pi-Latn-translit").tr

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

-- tests.sc="Lana"
tests.sc = "Latn"
tests.option = {impl="yes"}

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

local empty6 = {{}, {}, {}, {}, {}, {}}
local num = {[1] = 1, [3] = 2, [5] = 3}

local comp_lists = function(vref, vgot, label, tablet1, tablet2)
	local exp, got
	if tablet2 then
		exp =	spaceJoin(vref[tablet1] or {})..' ; '..
				spaceJoin(vref[tablet2] or {})
		got =	spaceJoin(vgot[tablet1] or {})..' ; '..
				spaceJoin(vgot[tablet2] or {})
	else
		exp =  spaceJoin(vref[tablet1] or {})
		got =  spaceJoin(vgot[tablet1] or {})
	end
	tests:equals(label, got, to_script(exp, tests.sc, tests.option))
end

local pass_through = function(x) return x end

local knockout = function(forms)
	retval = {}
	for _, v in pairs(forms) do
		if not match(v, "[โเໂເ][มวມວ]["..u(0x0e3a)..u(0x0eba)..']') then
			table.insert(retval, v)
		end
	end
	return retval
end

local compare = function(vref, vgot, label, tablet1, tablet2)
	local exp, got
	local r1 = vref[tablet1] or empty6
	local g1 = vgot[tablet1] or empty6
	local r2, g2
	if tablet2 then
		r2 = vref[tablet2] or empty6
		g2 = vgot[tablet2] or empty6
	end
	local f
	if (tests.sc == "Thai" or tests.sc == "Laoo") and
	tests.option.impl ~= "no" then
		f = knockout
	else
		f = pass_through
	end
	for i = 1, 5, 2 do
		if tablet2 then
			exp =  spaceJoin(r1[i])..' ; '..spaceJoin(r1[i+1])
		  ..' ; '..spaceJoin(r2[i])..' ; '..spaceJoin(r2[i+1])
			got =  spaceJoin(f(g1[i]))..' ; '..spaceJoin(f(g1[i+1]))
		  ..' ; '..spaceJoin(f(g2[i]))..' ; '..spaceJoin(f(g2[i+1]))
		 else
			exp =  spaceJoin(r1[i])..' ; '..spaceJoin(r1[i+1])
			got =  spaceJoin(f(g1[i]))..' ; '..spaceJoin(f(g1[i+1]))
		 end
		tests:equals(label..num[i], got, to_script(exp, tests.sc, tests.option))
	end
end

local pacati_ref = {
	presa = {
		{"pacāmi"}, {"pacāma"},		{"pacasi"}, {"pacatha"},
		{"pacati"}, {"pacanti"}
	},
	presm = {
		{"pace"}, {"pacāmhe"},		{"pacase"}, {"pacavhe"},
		{"pacate"}, {"pacante", "pacare"}
	},
	impfa = {
		{"apaca", "apacaṃ"}, {"apacamhā"},
		{"apaco"}, {"apacattha"},
		{"apaca", "apacā"}, {"apacu", "apacū"}
	},
	impfm = {
		{"apaciṃ"}, {"apacāmhase", "apacamhase"},
		{"apacase"}, {"apacavhaṃ"},
		{"apacattha"}, {"apacatthuṃ"}
	},
	impra = {
		{"pacāmi"}, {"pacāma"},		{"paca", "pacāhi"}, {"pacatha"},
		{"pacatu"}, {"pacantu"}
	},
	imprm = {
		{"pace"}, {"pacāmase"},		{"pacassu"}, {"pacavho"},
		{"pacataṃ"}, {"pacantaṃ"}
	},
	optaa = {
		{"paceyyāmi", "paceyyaṃ", "pace"},		{"paceyyāma"},
		{"paceyyāsi", "pace"},					{"paceyyātha"},
		{"paceyya", "pace"},					{"paceyyuṃ"}
	},
	optaa_irr = {
		{"paceyyāmi", "paceyyaṃ"},		{"paceyyāma"},
		{"paceyyāsi"},					{"paceyyātha"},
		{"paceyya"},					{"paceyyuṃ"}
	},
	optam = {
		{"paceyyaṃ"}, {"paceyyāmhe"},		{"pacetho"}, {"paceyyavho"},
		{"pacetha"}, {"paceraṃ"}
	},
	pap = {"pacant"},
	pmp = {"pacamāna"},
}

local corayati_ref = {
	presa = {
		{"corayāmi"}, {"corayāma"},		{"corayasi"}, {"corayatha"},
		{"corayati"}, {"corayanti"}
	},
	presm = {
		{"coraye"}, {"corayāmhe"},		{"corayase"}, {"corayavhe"},
		{"corayate"}, {"corayante", "corayare"}
	},
	impfa = {
		{"coraya", "corayaṃ"}, {"corayamhā"},
		{"corayo"}, {"corayattha"},
		{"coraya", "corayā"}, {"corayu", "corayū"}
	},
	impfm = {
		{"corayiṃ"}, {"corayāmhase", "corayamhase"},
		{"corayase"}, {"corayavhaṃ"},
		{"corayattha"}, {"corayatthuṃ"}
	},
	impra = {
		{"corayāmi"}, {"corayāma"},		{"corayāhi"}, {"corayatha"},
		{"corayatu"}, {"corayantu"}
	},
	imprm = {
		{"coraye"}, {"corayāmase"},		{"corayassu"}, {"corayavho"},
		{}, {"corayantaṃ"} -- 3s deleted pending review!
	},
	optaa = {
		{"corayeyyāmi", "corayeyyaṃ"},		{"corayeyyāma"}, --aye 1s & 2s needs
		{"corayeyyāsi"},					{"corayeyyātha"}, -- attestation.
		{"corayeyya", "coraye"},			{"corayeyyuṃ"}
	},
	optam = {
		{"corayeyyaṃ"}, {"corayeyyāmhe"},		{"corayetho"}, {"corayeyyavho"},
		{"corayetha"}, {"corayeraṃ"}
	},
	pap = {"corayant"},
	pmp = {"corayamāna"},
}
local coreti_ref = {
	presa = {
		{"coremi"}, {"corema"},		{"coresi"}, {"coretha"},
		{"coreti"}, {"corenti"}
	},
	impra = {
		{"coremi"}, {"corema"},		{"corehi"}, {"coretha"},
		{"coretu"}, {"corentu"}
	},
	optaa = {
		{"coreyyāmi", "coreyyaṃ"},		{"coreyyāma"}, --aye 1s & 2s needs
		{"coreyyāsi"},					{"coreyyātha"}, -- attestation.
		{"coreyya"},			{"coreyyuṃ"}
	},
	optam = {
		{"coreyyaṃ"}, {"coreyyāmhe"},		{"coretho"}, {"coreyyavho"},
		{"coretha"}, {"coreraṃ"}
	},
	pap = {"corent"},
}
local corete_ref = {
	presm = {
		{"coraye"}, {"corayāmhe"},		{"corayase"}, {"corayavhe"},
		{"corayate"}, {"corayante", "corayare"}
	},
	imprm = {
		{"coraye"}, {"corayāmase"},		{"corayassu"}, {"corayavho"},
		{}, {"corayantaṃ"} -- 3s deleted pending review!
	},
	optaa = coreti_ref.optaa,
	optam = coreti_ref.optam,
	pmp = {"corayamāna"},
}

local tanoti_ref = { -- Middle forms 
	presa = {
		{"tanomi"}, {"tanoma"},		{"tanosi"}, {"tanotha"},
		{"tanoti"}, {"tanonti"}
	},
	presm = {
		{"tanve"}, {"tanumhe"},		{"tanuse"}, {"tanuvhe"},
		{"tanute"}, {"tanunte", "tanure"}
	},
	impra = {
		{"tanomi"}, {"tanoma"},		{"tanohi"}, {"tanotha"},
		{"tanotu"}, {"tanontu"}
	},
	imprm = {
		{"tanve"}, {"tanvāmase"},		{"tanussu"}, {"tanuvho"},
		{"tanutaṃ"}, {"tanuntaṃ"}
	},
	optaa = {
		{"taneyyāmi", "taneyyaṃ"},		{"taneyyāma"},
		{"taneyyāsi"},					{"taneyyātha"},
		{"taneyya"},					{"taneyyuṃ"}
	},
	optam = {
		{"taneyyaṃ"}, {"taneyyāmhe"},		{"tanetho"}, {"taneyyavho"},
		{"tanetha"}, {"taneraṃ"}
	},
	pap = {"tanont"},
}

local dadati_ref = {
	presa = {
		{"dadāmi"}, {"dadāma"},		{"dadāsi"}, {"dadātha"},
		{"dadāti"}, {"dadanti"}
	},
	presm = {
		{"dade"}, {"dadāmhe"},		{"dadāse"}, {"dadavhe"},
		{"dadāte"}, {"dadante", "dadāre"}
	},
	impfa = {
		{"adada", "adadaṃ"}, {"adadamhā"},
		{"adado"}, {"adadattha"},
		{"adada", "adadā"}, {"adadu", "adadū"}
	},
	impfm_disabled = {
		{"adadiṃ"}, {"adadāmhase", "adadamhase"},
		{"adadase"}, {"adadavhaṃ"},
		{"adadattha"}, {"adadatthuṃ"}
	},
	impra = {
		{"dadāmi"}, {"dadāma"},		{"dadā", "dadāhi"}, {"dadātha"},
		{"dadātu"}, {"dadantu"}
	},
	optaa = {
		{"dadeyyāmi", "dadeyyaṃ"},		{"dadeyyāma"},  -- "dade" is exceptional.
		{"dadeyyāsi"},					{"dadeyyātha"}, -- "dade" is exceptional.
		{"dadeyya", "dade"},			{"dadeyyuṃ"}
	},
	optam = {
		{"dadeyyaṃ"}, {"dadeyyāmhe"},		{"dadetho"}, {"dadeyyavho"},
		{"dadetha"}, {"daderaṃ"}
	},
	pap = {"dadant"},
	pmp = {"dadamāna"},
}

local dajja_ref = {
	optaa = {
		{"dajjāmi"}, {"dajjāma"},		{"dajjāsi"}, {"dajjātha"},
		{"dajjā"}, {"dajjuṃ"}}, 
}

-- function tests:test_basic_tables()
function tests:test_ati()
	local impl = tests.option.impl or "yes"
	local pacati = to_script("pacati", tests.sc, tests.option)
	local pacati_got = m_conj_verb.special_forms(pacati,
		{augment="with_made", impf_voice="both", impl = impl})
	compare(pacati_ref, pacati_got, "pacati pres ", "presa", "presm")
	compare(pacati_ref, pacati_got, "pacati impf ", "impfa", "impfm")
	compare(pacati_ref, pacati_got, "pacati impr ", "impra", "imprm")
	compare(pacati_ref, pacati_got, "pacati opt ",  "optaa", "optam")
	comp_lists(pacati_ref,  pacati_got, "pacati part ", "pap", "pmp")
	local pacate = to_script("pacate", tests.sc, tests.option)
	local pacate_got = m_conj_verb.special_forms(pacate,
		{	augment="with_made", impf_voice="both", opta_voice = "both",
			impl = impl	})
	compare(pacati_ref, pacate_got, "pacate pres ", "presm")
	compare(pacati_ref, pacate_got, "pacate impf ", "impfm")
	compare(pacati_ref, pacate_got, "pacate impr ", "imprm")
	compare(pacati_ref, pacate_got, "pacate opt ", "optaa", "optam")
	comp_lists(pacati_ref,  pacate_got, "pacate part ", "pmp")
	local namati = to_script("namati", tests.sc, tests.option)
	local apaca  = to_script("apaca",  tests.sc, tests.option)
	local apaca_got = m_conj_verb.special_forms(namati,
		{	impf_voice="both", impf=apaca, impf2=apaca, augment="with_given",
			impl = impl	})
	compare(pacati_ref, apaca_got, "apaca impf ", "impfa", "impfm")
	local namate    = to_script("namate",    tests.sc, tests.option)
	local nama      = to_script("nama",      tests.sc, tests.option)
	local apacattha = to_script("apacattha", tests.sc, tests.option)
	local apacattha_got = m_conj_verb.special_forms(namati,
		{midl=namate, impf_voice="midl", impl = impl, 
		 impf=nama, impf_midl=apacattha, augment="with_given"})
	compare(pacati_ref, apacattha_got, "apacattha impf m", "impfm")
--	if nil then -- Unusability is a deliberate, documented feature, not a bug. 
--		local pace = to_script("pace", tests.sc, tests.option)
--		local pace_got = m_conj_verb.special_forms("namati", {
--			opta_mod="replace", opta=pace})
--		compare(pacati_ref, pace_got, "pace opt ", "optaa", "optam")
--	end
	local paceyya = to_script("paceyya", tests.sc, tests.option)
	local paceyya_got = m_conj_verb.special_forms(namati, {
		opta_mod="replace", opta=paceyya, impl = impl})
	local paceyya_ref = {	optaa = pacati_ref.optaa_irr,
							optam = pacati_ref.optam }
	compare(paceyya_ref, paceyya_got, "paceyya opt ", "optaa", "optam")
	local pacetha = to_script("pacetha", tests.sc, tests.option)
	local pacetha_got = m_conj_verb.special_forms(namati, {
		opta_midl=pacetha, impl = impl})
	if nil then -- This is useful as a selectional test.
		compare(pacati_ref, pacetha_got, "pacetha opt ", "optaa", "optam")
	end
	compare(pacati_ref, pacetha_got, "pacetha opt m", "optam")
end

-- Stems in -ayati have differences from -ati that aren't captured by -eti.
function tests:test_ayati()
	local impl = tests.option.impl or "yes"
	local corayati = to_script("corayati", tests.sc, tests.option)
	local corayati_got = m_conj_verb.special_forms(corayati,
		{impf_voice="both", augment="without", impl = impl})
	compare(corayati_ref, corayati_got, "corayati pres ", "presa", "presm")
	compare(corayati_ref, corayati_got, "corayati impf ", "impfa", "impfm")
	compare(corayati_ref, corayati_got, "corayati impr ", "impra", "imprm")
	compare(corayati_ref, corayati_got, "corayati opt ",  "optaa", "optam")
	comp_lists(corayati_ref,  corayati_got, "corayati part ", "pap", "pmp")
	corayate = to_script("corayate", tests.sc, tests.option)
	local corayate_got = m_conj_verb.special_forms(corayate,
		{impf_voice="both", augment="without", opta_voice = "both", impl = impl})
	compare(corayati_ref, corayate_got, "corayate pres ", "presm")
	compare(corayati_ref, corayate_got, "corayate impf ", "impfm")
	compare(corayati_ref, corayate_got, "corayate impr ", "imprm")
	compare(corayati_ref, corayate_got, "corayate opt ",  "optaa", "optam")
	comp_lists(corayati_ref,  corayate_got, "corayate part ", "pmp")
	namati = to_script("namati", tests.sc, tests.option)
	coraya = to_script("coraya", tests.sc, tests.option)
	local coraya_got = m_conj_verb.special_forms(namati,
		{impf_voice="both", impf=coraya, augment="with_given", impl = impl})
	compare(corayati_ref, coraya_got, "coraya impf ", "impfa", "impfm")
	nama       = to_script("nama",       tests.sc, tests.option)
	namate     = to_script("namate",     tests.sc, tests.option)
	corayattha = to_script("corayattha", tests.sc, tests.option)
	local corayattha_got = m_conj_verb.special_forms(namati,
		{midl=namate, impf_voice="midl",
		 impf=nama, impf_midl=corayattha, augment="with_given"})
	compare(corayati_ref, corayattha_got, "corayattha impf m", "impfm")
end

function tests:test_eti()
	local impl = tests.option.impl or "yes"
	local coreti = to_script("coreti", tests.sc, tests.option)
	local coreti_got = m_conj_verb.special_forms(coreti,
		{augment="without", impf_voice="both", impl = impl})
	compare(coreti_ref, coreti_got, "coreti pres ", "presa", "presm")
	compare(coreti_ref, coreti_got, "coreti impf ", "impfa", "impfm")
	compare(coreti_ref, coreti_got, "coreti impr ", "impra", "imprm")
	compare(coreti_ref, coreti_got, "coreti opt ",  "optaa", "optam")
	comp_lists(coreti_ref,  coreti_got, "coreti part ", "pap", "pmp")
	local corete = to_script("corete", tests.sc, tests.option)
	local corete_got = m_conj_verb.special_forms(corete,
		{	augment="without", impf_voice="both", opta_voice="both",
			impl=impl	})
	compare(corete_ref, corete_got, "corete pres ", "presm")
	compare(corete_ref, corete_got, "corete impf ", "impfm")
	compare(corete_ref, corete_got, "corete impr ", "imprm")
	compare(corete_ref, corete_got, "corete opt ",  "optaa", "optam")
	comp_lists(corete_ref,  corete_got, "corete part ", "pmp")
end

function tests:test_oti()
	local impl = tests.option.impl or "yes"
	local tanoti = to_script("tanoti", tests.sc, tests.option)
	local tanoti_got = m_conj_verb.special_forms(tanoti,
		{augment="without", impf_voice="both", impl=impl})
	compare(tanoti_ref, tanoti_got, "tanoti pres ", "presa", "presm")
	compare(tanoti_ref, tanoti_got, "tanoti impf ", "impfa", "impfm")
	compare(tanoti_ref, tanoti_got, "tanoti impr ", "impra", "imprm")
	compare(tanoti_ref, tanoti_got, "tanoti opt ",  "optaa", "optam")
	comp_lists(tanoti_ref, tanoti_got, "tanoti part ", "pap", "pmp")
	local tanute = to_script("tanute", tests.sc, tests.option)
	local tanute_got = m_conj_verb.special_forms(tanute,
		{	augment="without", impf_voice="both", opta_voice = "both",
			impl=impl	})
	compare(tanoti_ref,  tanute_got, "tanute pres ", "presm")
	compare(tanoti_ref,  tanute_got, "tanute impf ", "impfm")
	compare(tanoti_ref,  tanute_got, "tanute impr ", "imprm")
	compare(tanoti_ref, tanute_got, "tanute opt ",  "optaa", "optam")
	comp_lists(tanoti_ref, tanute_got, "tanute part ", "pmp")
end

function tests:test_aati()
	local impl = tests.option.impl or "yes"
	local dadati = to_script("dadāti", tests.sc, tests.option)
	local dadati_got = m_conj_verb.special_forms(dadati,
		{augment="with_made", impf_voice="both", impl=impl})
	compare(dadati_ref, dadati_got, "dadāti pres ", "presa", "presm")
	compare(dadati_ref, dadati_got, "dadāti impf ", "impfa", "impfm")
	compare(dadati_ref, dadati_got, "dadāti impr ", "impra", "imprm")
	compare(dadati_ref, dadati_got, "dadāti opt ",  "optaa", "optam")
	comp_lists(dadati_ref,  dadati_got, "dadāti part ", "pap", "pmp")
	local dadate = to_script("dadāte", tests.sc, tests.option)
	local dadate_got = m_conj_verb.special_forms(dadate,
		{	augment="without", impf_voice="both", opta_voice="both",
			impl = impl	})
	compare(dadati_ref, dadate_got, "dadāte pres ", "presm")
	compare(dadati_ref, dadate_got, "dadāte impf ", "impfm")
	compare(dadati_ref, dadate_got, "dadāte impr ", "imprm")
	compare(dadati_ref, dadate_got, "dadāte opt ",  "optaa", "optam")
	comp_lists(dadati_ref, dadate_got, "dadāte part ", "pmp")
	local dajja = to_script("dajjā", tests.sc, tests.option)
	local dajja_got = m_conj_verb.special_forms(dadati,
		{	voice="none", opta_voice="act", opta_mod="replace", opta=dajja,
			impl=impl})
	compare(dajja_ref, dajja_got, "dadāti alt opt a", "optaa")
end


return tests