Jump to content

Module:ro-pronunciation/testcases

From Wiktionary, the free dictionary


local tests = require "Module:UnitTests"

setmetatable(_G, { __index = require "Module:ro-pronunciation" })

local function tag_IPA(transcription)
	if transcription:find "^Error" then
		return transcription
	else
		return '<span class="IPA">' .. transcription .. '</span>'
	end
end

local examples = {
		{ 'copíl'    , 'koˈpil',''	},
		{ 'copíi'   , 'koˈpij',''     },
		{ 'copíii'   , 'koˈpi.ji',''     },
		{ 'lupi'   , "lupʲ",''     },
		{ 'șárpe'   , "ˈʃar.pe",''     },
		{ 'țáră'   , "ˈt͡sa.rə",''     },
		{ 'înăuntru'   , "ɨ.nəˈun.tru",''     },
		{ 'xilofón'   , "ksi.loˈfon",''     },
		{ 'quarc'   , "kwark",''     },
		{ 'fiert'   , "fjert",''     },
		{ 'viteză'   , "viˈte.zə",''     },
		{ 'viteáză'   , "viˈte̯a.zə",''     },
		{ 'minge'   , "ˈmin.d͡ʒe",''     },
		{ 'mingeac'   , "minˈd͡ʒe̯ak",''     },
		{ 'ghețár'   , "ɡeˈt͡sar",''     },
		{ 'ghíndă'   , "ˈɡin.də",''     },
		{ 'jargón'   , "ʒarˈɡon",''     },
		{ 'cireáșă'   , "t͡ʃiˈre̯a.ʃə",''     },
		{ 'cétină'   , "ˈt͡ʃe.ti.nə",''     },
		{ 'chiar'   , "kjar",''     },
		{ 'chestie'   , "ˈkes.ti.e",''     },
		{ 'mlădíță'   , "mləˈdi.t͡sə",''     },
		{ 'târșă'   , "ˈtɨr.ʃə",''     },
		{ 'oaie'   , "ˈo̯a.je",''     },
		{ 'râu'   , "rɨw",''     },
		{ 'continuu'   , "konˈti.nuw",''     },
		{ 'câine'   , "ˈkɨj.ne",''     },
		{ 'mea'   , "me̯a",''     },
		{ 'socoteai'   , "so.koˈte̯aj",''     },
		{ 'leoaică'   , "leˈo̯aj.kə",''     },
		{ 'accelerasem', "ak.t͡ʃe.leˈra.sem",''},
		{ 'creează', "kreˈe̯a.zə",''},
		{ 'crează', "ˈkre̯a.zə",''},
		{ 'beau'   , "be̯aw",''     },
		{ 'suiau'   , "suˈjaw",''     },
		{ 'piei'   , "pjej",''     },
		{ 'pleoape'   , "ˈple̯o̯a.pe",''     },
		{ 'creioane'   , "kreˈjo̯a.ne",''     },
		{ 'sculptură'   , "skulpˈtu.rə",''     },
		{ 'poezíe'   , "po.eˈzi.e",''     },
		
}

function tests:test_to_phonemic()
	self:iterate(examples,
		function (self, example, expected, _, voiced_z)
			local success, result = pcall(to_phonemic, example, voiced_z)
			if not success then
				result = ("Error: %s"):format(result)
			end
			
			local voiced_text
			if not voiced_z then
				voiced_text = ""
			elseif type(voiced_z) == "boolean" then
				if voiced_z then
					voiced_text = " (all z sequences are voiced)"
				else
					voiced_text = " (no z sequences are voiced)"
				end
			else
				voiced_text = (" (z sequence%s %s %s voiced)"):format(
					voiced_z[2] and "s" or "",
					table.concat(voiced_z, ", "),
					voiced_z[2] and "are" or "is")
			end
			
			self:equals(example .. voiced_text, result, expected, { display = tag_IPA })
		end)
end

function tests:test_to_phonetic()
	self:iterate(examples,
		function (self, example, _, expected, voiced_z)
			if expected == "" then
				return
			end
			
			local success, result = pcall(to_phonetic, example, voiced_z)
			if not success then
				result = ("Error: %s"):format(result)
			end
			
			local voiced_text
			if not voiced_z then
				voiced_text = ""
			elseif type(voiced_z) == "boolean" then
				if voiced_z then
					voiced_text = " (all z sequences are voiced)"
				else
					voiced_text = " (no z sequences are voiced)"
				end
			else
				voiced_text = (" (z sequence%s %s %s voiced)"):format(
					voiced_z[2] and "s" or "",
					table.concat(voiced_z, ", "),
					voiced_z[2] and "are" or "is")
			end
			
			self:equals(example .. voiced_text, result, expected, { display = tag_IPA })
		end)
end

return tests