Module:User:Oyunqi/ug-decl/testcases

local p = require('Module:UnitTests') local m = require('Module:User:Oyunqi/ug-decl') local testcases = require('Module:User:Oyunqi/ug-decl-noun/testcases/data')

local sub = mw.ustring.gsub local match = mw.ustring.gmatch

function format_input(params) local par = "" if params[1] and params[1] ~= "" then par = par .. "|" .. params[1] end if params[2] and params[2] ~= "" then par = par .. "|" .. params[2] end --if params["change"] and params["change"] ~= "" then par = par .. "|change=" .. params["change"] end --if params["tongue"] and params["tongue"] ~= "" then par = par .. "|tongue=" .. params["tongue"] end str = " " str = str .. "   "    str = str .. "   "    str = str .. "    "    return str end

function format_output(output) str ="" i = 1 for token in match(output,"[^%s]+") do	  sep = " " -- " " if i % 2 == 0 then sep = " " end str = str .. token.. sep i = i + 1 end str = str .. " "

return str end

function fill_args(params, args) params = sub(params, "|", " ") i=1 --log =params for token in match(params,"[^%s]+") do     t = sub(token, "=", " ") j =1 ts={} for tt in match(t,"[^%s]+") do         ts[j]=tt j=j+1 end

if j ==3 then args[ts[1]] =ts[2] --log=log..ts[1].."-"..ts[2].." " else args[i] = ts[1] --log=log..i.."-"..ts[1].." " i=i+1 end end args["test"] =1 end

function p:check_noun_decl(params, expected_decl) if expected_decl["imp"] and expected_decl["imp"] ~= {} then local frame={} frame.args={} fill_args(params, frame.args) local test = m.get_word(frame) local exp = table.concat(test, " ") self:equals(format_input(frame.args),			exp,			expected_decl.imp,			{}) end end

function p:test_decl p:iterate(testcases, "check_noun_decl") end

function p:test_case for params, expected in pairs(testcases) do		if type(expected) == "table" then local frame={} frame.args={} fill_args(params, frame.args) local word = m.get_word(frame) local nouns = m.createCases(word) result = nouns.forms if expected["imp"] and expected["imp"] ~= "" then local temp = {} table.insert(temp, result["imp_nom_s"]) table.insert(temp, result["imp_nom_p"]) table.insert(temp, result["imp_gen_s"]) table.insert(temp, result["imp_gen_p"]) table.insert(temp, result["imp_acc_s"]) table.insert(temp, result["imp_acc_p"]) table.insert(temp, result["imp_dat_s"]) table.insert(temp, result["imp_dat_p"]) table.insert(temp, result["imp_loc_s"]) table.insert(temp, result["imp_loc_p"]) table.insert(temp, result["imp_abl_s"]) table.insert(temp, result["imp_abl_p"]) table.insert(temp, result["imp_lqu_s"]) table.insert(temp, result["imp_lqu_p"]) table.insert(temp, result["imp_lim_s"]) table.insert(temp, result["imp_lim_p"]) table.insert(temp, result["imp_sem_s"]) table.insert(temp, result["imp_sem_p"]) table.insert(temp, result["imp_com_s"]) table.insert(temp, result["imp_com_p"]) table.insert(temp, result["imp_com_s2"]) table.insert(temp, result["imp_com_p2"]) local result = table.concat(temp, " ") self:equals(format_input(frame.args), format_output(result), format_output(expected["imp"])) end if expected["imp.gen"] and expected["imp.gen"] ~= "" then local temp = {} table.insert(temp, result["imp_gen_nom_s"]) table.insert(temp, result["imp_gen_nom_p"]) table.insert(temp, result["imp_gen_gen_s"]) table.insert(temp, result["imp_gen_gen_p"]) table.insert(temp, result["imp_gen_acc_s"]) table.insert(temp, result["imp_gen_acc_p"]) table.insert(temp, result["imp_gen_dat_s"]) table.insert(temp, result["imp_gen_dat_p"]) table.insert(temp, result["imp_gen_loc_s"]) table.insert(temp, result["imp_gen_loc_p"]) table.insert(temp, result["imp_gen_abl_s"]) table.insert(temp, result["imp_gen_abl_p"]) table.insert(temp, result["imp_gen_lqu_s"]) table.insert(temp, result["imp_gen_lqu_p"]) table.insert(temp, result["imp_gen_lim_s"]) table.insert(temp, result["imp_gen_lim_p"]) table.insert(temp, result["imp_gen_sem_s"]) table.insert(temp, result["imp_gen_sem_p"]) table.insert(temp, result["imp_gen_com_s"]) table.insert(temp, result["imp_gen_com_p"]) table.insert(temp, result["imp_gen_com_s2"]) table.insert(temp, result["imp_gen_com_p2"]) local result = table.concat(temp, " ") self:equals(format_input(frame.args), format_output(result), format_output(expected["imp.gen"])) end if expected["imp.lqu"] and expected["imp.lqu"] ~= "" then local temp = {} table.insert(temp, result["imp_lqu_nom_s"]) table.insert(temp, result["imp_lqu_nom_p"]) table.insert(temp, result["imp_lqu_gen_s"]) table.insert(temp, result["imp_lqu_gen_p"]) table.insert(temp, result["imp_lqu_acc_s"]) table.insert(temp, result["imp_lqu_acc_p"]) table.insert(temp, result["imp_lqu_dat_s"]) table.insert(temp, result["imp_lqu_dat_p"]) table.insert(temp, result["imp_lqu_loc_s"]) table.insert(temp, result["imp_lqu_loc_p"]) table.insert(temp, result["imp_lqu_abl_s"]) table.insert(temp, result["imp_lqu_abl_p"]) table.insert(temp, result["imp_lqu_lqu_s"]) table.insert(temp, result["imp_lqu_lqu_p"]) table.insert(temp, result["imp_lqu_lim_s"]) table.insert(temp, result["imp_lqu_lim_p"]) table.insert(temp, result["imp_lqu_sem_s"]) table.insert(temp, result["imp_lqu_sem_p"]) table.insert(temp, result["imp_lqu_com_s"]) table.insert(temp, result["imp_lqu_com_p"]) table.insert(temp, result["imp_lqu_com_s2"]) table.insert(temp, result["imp_lqu_com_p2"]) local result = table.concat(temp, " ") self:equals(format_input(frame.args), format_output(result), format_output(expected["imp.lqu"])) end --1st person singluar if expected["p1s"] and expected["p1s"] ~= "" then local temp = {} table.insert(temp, result["p1s_nom_s"]) table.insert(temp, result["p1s_nom_p"]) table.insert(temp, result["p1s_gen_s"]) table.insert(temp, result["p1s_gen_p"]) table.insert(temp, result["p1s_acc_s"]) table.insert(temp, result["p1s_acc_p"]) table.insert(temp, result["p1s_dat_s"]) table.insert(temp, result["p1s_dat_p"]) table.insert(temp, result["p1s_loc_s"]) table.insert(temp, result["p1s_loc_p"]) table.insert(temp, result["p1s_abl_s"]) table.insert(temp, result["p1s_abl_p"]) table.insert(temp, result["p1s_lqu_s"]) table.insert(temp, result["p1s_lqu_p"]) table.insert(temp, result["p1s_lim_s"]) table.insert(temp, result["p1s_lim_p"]) table.insert(temp, result["p1s_sem_s"]) table.insert(temp, result["p1s_sem_p"]) table.insert(temp, result["p1s_com_s"]) table.insert(temp, result["p1s_com_p"]) table.insert(temp, result["p1s_com_s2"]) table.insert(temp, result["p1s_com_p2"]) local result = table.concat(temp, " ") self:equals(format_input(frame.args), format_output(result), format_output(expected["p1s"])) end if expected["p1s.gen"] and expected["p1s.gen"] ~= "" then local temp = {} table.insert(temp, result["p1s_gen_nom_s"]) table.insert(temp, result["p1s_gen_nom_p"]) table.insert(temp, result["p1s_gen_gen_s"]) table.insert(temp, result["p1s_gen_gen_p"]) table.insert(temp, result["p1s_gen_acc_s"]) table.insert(temp, result["p1s_gen_acc_p"]) table.insert(temp, result["p1s_gen_dat_s"]) table.insert(temp, result["p1s_gen_dat_p"]) table.insert(temp, result["p1s_gen_loc_s"]) table.insert(temp, result["p1s_gen_loc_p"]) table.insert(temp, result["p1s_gen_abl_s"]) table.insert(temp, result["p1s_gen_abl_p"]) table.insert(temp, result["p1s_gen_lqu_s"]) table.insert(temp, result["p1s_gen_lqu_p"]) table.insert(temp, result["p1s_gen_lim_s"]) table.insert(temp, result["p1s_gen_lim_p"]) table.insert(temp, result["p1s_gen_sem_s"]) table.insert(temp, result["p1s_gen_sem_p"]) table.insert(temp, result["p1s_gen_com_s"]) table.insert(temp, result["p1s_gen_com_p"]) table.insert(temp, result["p1s_gen_com_s2"]) table.insert(temp, result["p1s_gen_com_p2"]) local result = table.concat(temp, " ") self:equals(format_input(frame.args), format_output(result), format_output(expected["p1s.gen"])) end if expected["p1s.lqu"] and expected["p1s.lqu"] ~= "" then local temp = {} table.insert(temp, result["p1s_lqu_nom_s"]) table.insert(temp, result["p1s_lqu_nom_p"]) table.insert(temp, result["p1s_lqu_gen_s"]) table.insert(temp, result["p1s_lqu_gen_p"]) table.insert(temp, result["p1s_lqu_acc_s"]) table.insert(temp, result["p1s_lqu_acc_p"]) table.insert(temp, result["p1s_lqu_dat_s"]) table.insert(temp, result["p1s_lqu_dat_p"]) table.insert(temp, result["p1s_lqu_loc_s"]) table.insert(temp, result["p1s_lqu_loc_p"]) table.insert(temp, result["p1s_lqu_abl_s"]) table.insert(temp, result["p1s_lqu_abl_p"]) table.insert(temp, result["p1s_lqu_lqu_s"]) table.insert(temp, result["p1s_lqu_lqu_p"]) table.insert(temp, result["p1s_lqu_lim_s"]) table.insert(temp, result["p1s_lqu_lim_p"]) table.insert(temp, result["p1s_lqu_sem_s"]) table.insert(temp, result["p1s_lqu_sem_p"]) table.insert(temp, result["p1s_lqu_com_s"]) table.insert(temp, result["p1s_lqu_com_p"]) table.insert(temp, result["p1s_lqu_com_s2"]) table.insert(temp, result["p1s_lqu_com_p2"]) local result = table.concat(temp, " ") self:equals(format_input(frame.args), format_output(result), format_output(expected["p1s.lqu"])) end --2nd person singluar if expected["p2s"] and expected["p2s"] ~= "" then local temp = {} table.insert(temp, result["p2s_nom_s"]) table.insert(temp, result["p2s_nom_p"]) table.insert(temp, result["p2s_gen_s"]) table.insert(temp, result["p2s_gen_p"]) table.insert(temp, result["p2s_acc_s"]) table.insert(temp, result["p2s_acc_p"]) table.insert(temp, result["p2s_dat_s"]) table.insert(temp, result["p2s_dat_p"]) table.insert(temp, result["p2s_loc_s"]) table.insert(temp, result["p2s_loc_p"]) table.insert(temp, result["p2s_abl_s"]) table.insert(temp, result["p2s_abl_p"]) table.insert(temp, result["p2s_lqu_s"]) table.insert(temp, result["p2s_lqu_p"]) table.insert(temp, result["p2s_lim_s"]) table.insert(temp, result["p2s_lim_p"]) table.insert(temp, result["p2s_sem_s"]) table.insert(temp, result["p2s_sem_p"]) table.insert(temp, result["p2s_com_s"]) table.insert(temp, result["p2s_com_p"]) table.insert(temp, result["p2s_com_s2"]) table.insert(temp, result["p2s_com_p2"]) local result = table.concat(temp, " ") self:equals(format_input(frame.args), format_output(result), format_output(expected["p2s"])) end if expected["p2s.gen"] and expected["p2s.gen"] ~= "" then local temp = {} table.insert(temp, result["p2s_gen_nom_s"]) table.insert(temp, result["p2s_gen_nom_p"]) table.insert(temp, result["p2s_gen_gen_s"]) table.insert(temp, result["p2s_gen_gen_p"]) table.insert(temp, result["p2s_gen_acc_s"]) table.insert(temp, result["p2s_gen_acc_p"]) table.insert(temp, result["p2s_gen_dat_s"]) table.insert(temp, result["p2s_gen_dat_p"]) table.insert(temp, result["p2s_gen_loc_s"]) table.insert(temp, result["p2s_gen_loc_p"]) table.insert(temp, result["p2s_gen_abl_s"]) table.insert(temp, result["p2s_gen_abl_p"]) table.insert(temp, result["p2s_gen_lqu_s"]) table.insert(temp, result["p2s_gen_lqu_p"]) table.insert(temp, result["p2s_gen_lim_s"]) table.insert(temp, result["p2s_gen_lim_p"]) table.insert(temp, result["p2s_gen_sem_s"]) table.insert(temp, result["p2s_gen_sem_p"]) table.insert(temp, result["p2s_gen_com_s"]) table.insert(temp, result["p2s_gen_com_p"]) table.insert(temp, result["p2s_gen_com_s2"]) table.insert(temp, result["p2s_gen_com_p2"]) local result = table.concat(temp, " ") self:equals(format_input(frame.args), format_output(result), format_output(expected["p2s.gen"])) end if expected["p2s.lqu"] and expected["p2s.lqu"] ~= "" then local temp = {} table.insert(temp, result["p2s_lqu_nom_s"]) table.insert(temp, result["p2s_lqu_nom_p"]) table.insert(temp, result["p2s_lqu_gen_s"]) table.insert(temp, result["p2s_lqu_gen_p"]) table.insert(temp, result["p2s_lqu_acc_s"]) table.insert(temp, result["p2s_lqu_acc_p"]) table.insert(temp, result["p2s_lqu_dat_s"]) table.insert(temp, result["p2s_lqu_dat_p"]) table.insert(temp, result["p2s_lqu_loc_s"]) table.insert(temp, result["p2s_lqu_loc_p"]) table.insert(temp, result["p2s_lqu_abl_s"]) table.insert(temp, result["p2s_lqu_abl_p"]) table.insert(temp, result["p2s_lqu_lqu_s"]) table.insert(temp, result["p2s_lqu_lqu_p"]) table.insert(temp, result["p2s_lqu_lim_s"]) table.insert(temp, result["p2s_lqu_lim_p"]) table.insert(temp, result["p2s_lqu_sem_s"]) table.insert(temp, result["p2s_lqu_sem_p"]) table.insert(temp, result["p2s_lqu_com_s"]) table.insert(temp, result["p2s_lqu_com_p"]) table.insert(temp, result["p2s_lqu_com_s2"]) table.insert(temp, result["p2s_lqu_com_p2"]) local result = table.concat(temp, " ") self:equals(format_input(frame.args), format_output(result), format_output(expected["p2s.lqu"])) end --self:equals(format_input(frame.args), table.show(nouns), table.show(expected)) else if expected ~= "" then local frame={} frame.args={} fill_args(params, frame.args) local word = m.get_word(frame) --result = word local nouns = m.createCases(word) --[				result = nouns.forms --local temp = "" --[				local temp = {} table.insert(temp, result["imp_nom_s"]) table.insert(temp, result["imp_nom_p"]) table.insert(temp, result["imp_gen_s"]) table.insert(temp, result["imp_gen_p"]) table.insert(temp, result["imp_acc_s"]) table.insert(temp, result["imp_acc_p"]) table.insert(temp, result["imp_dat_s"]) table.insert(temp, result["imp_dat_p"]) table.insert(temp, result["imp_loc_s"]) table.insert(temp, result["imp_loc_p"]) table.insert(temp, result["imp_abl_s"]) table.insert(temp, result["imp_abl_p"]) table.insert(temp, result["imp_lqu_s"]) table.insert(temp, result["imp_lqu_p"]) table.insert(temp, result["imp_lim_s"]) table.insert(temp, result["imp_lim_p"]) table.insert(temp, result["imp_sem_s"]) table.insert(temp, result["imp_sem_p"]) table.insert(temp, result["imp_com_s"]) table.insert(temp, result["imp_com_p"]) table.insert(temp, result["imp_com_s2"]) table.insert(temp, result["imp_com_p2"]) --]				for k, v in pairs(result) do					temp = temp .. tostring(k) .. "=>"					if type(v) == "table" then						for tk, tv in pairs(v) do							temp = temp .. tostring(kt) .. "==>" .. tv						end						-- temp = temp .. table.concat(v, " ")					else						temp = temp  .. v .. " "					end				end result = table.concat(temp, " ") --]				--				local word = m.check(frame)				local nouns = m.createCases(word) --local result = table.concat(nouns["imp"], " ") self:equals(format_input(frame.args) ,format_output(result), format_output(expected)) -- self:equals(format_input(frame.args), table.show(nouns), table.show(expected)) end end end end

return p