Module:User:Vitalik/inflection-new/testcases

This is a private module sandbox of Vitalik, for their own experimentation. Items in this module may be added and removed at Vitalik's discretion; do not rely on this module's stability.


local tests = require('Module:UnitTests')
local inflection = require('Module:User:Vitalik/inflection-new')
local m_links = require('Module:links')

local data_name = 'ru-noun'
local lang = require('Module:languages').getByCode('ru')

local n = 1

function tests:check_inflection(base_stressed, gender_class, stress, expected, comment)
	local title = base_stressed
	local link = m_links.full_link({lang = lang, term = title, tr = '-'}, nil, true)
	local base = mw.ustring.gsub(base_stressed, '́', '')
	local forms = inflection.main(data_name, base, {base_stressed=base_stressed, gender_class=gender_class, stress=stress})
	local forms_keys = {'nom_sg', 'gen_sg', 'dat_sg', 'acc_sg', 'ins_sg', 'prp_sg', 'nom_pl', 'gen_pl', 'dat_pl', 'acc_pl', 'ins_pl', 'prp_pl'}
	local expected_list = mw.text.split(expected, ' / ')
	for i, form_key in pairs(forms_keys) do
		local zero = i < 10 and '0' or ''
		local text = n .. '.' .. zero .. i .. ') ' .. link .. ' (' .. gender_class .. ', ' .. stress .. ') <b>' .. form_key .. '</b>'
		text = text .. " <small style='color: gray;'>stem type is " .. forms['stem_type'] .. "</small>"
		if comment then
			text = text .. " <small style='color: gray;'>" .. comment .. "</small>"
		end
		actual = forms[form_key]
		expected = expected_list[i]
		self:equals(text, actual, expected)
	end
	n = n + 1
end

return tests