Difference between revisions of "Module:Language/testcases"

From blackwiki
Jump to navigation Jump to search
blackwiki>Erutuon
(fix normalization issue)
blackwiki>Erutuon
(more)
Line 31: Line 31:
 
p['test makeEntryName'] = function (self)
 
p['test makeEntryName'] = function (self)
 
local examples = {
 
local examples = {
{ "la", "homō", "homo" },
+
{ "ar", "العَرَبِيَّة", "العربية" },
 
{ "grc", "δημοκρᾰτῐ́ᾱ", "δημοκρατία" },
 
{ "grc", "δημοκρᾰτῐ́ᾱ", "δημοκρατία" },
 +
{ "ha", "àzàhàr̃iyyā̀", "azahariyya" },
 +
{ "la", "coëō", "coeo" },
 +
{ "nci", "Quetzalcōātl", "Quetzalcoatl" },
 +
{ "ru", "ру́сский язы́к", "русский язык" },
 +
{ "sh", "ćá", "ća" }, -- fake word with c-acute and tonal acute; add a real word if you know one
 
}
 
}
 
 

Revision as of 18:54, 23 June 2018

Documentation for this module may be created at Module:Language/testcases/doc

-- Example Unit tests for [[Module:Bananas]]. Click talk page to run tests.
local p = require 'Module:UnitTests'
local m_Language = require 'Module:Language'

function p:iterate(examples, func)
	if type(examples) ~= 'table' then
		error('First argument of iterate should be a table, not ' .. type(examples) .. '.')
	end
	if type(func) == 'string' then
		func = self[func]
		for i, example in ipairs(examples) do
			if type(example) == 'table' then
				func(self, unpack(example))
			else
				error('iterate does not know what to do with example number ' .. i .. ', whose type is ' .. type(example) .. '.')
			end
		end
	else
		error('Second argument of iterate should be a string, not ' .. type(func) .. '.')
	end
end

local decompose = mw.ustring.toNFD
function p:check_makeEntryName(languageCode, word, expected)
	self:equals(
		word,
		decompose(m_Language.makeEntryName(word, languageCode)),
		decompose(expected))
end

p['test makeEntryName'] = function (self)
	local examples = {
		{ "ar", "العَرَبِيَّة", "العربية" },
		{ "grc", "δημοκρᾰτῐ́ᾱ", "δημοκρατία" },
		{ "ha", "àzàhàr̃iyyā̀", "azahariyya" },
		{ "la", "coëō", "coeo" },
		{ "nci", "Quetzalcōātl", "Quetzalcoatl" },
		{ "ru", "ру́сский язы́к", "русский язык" },
		{ "sh", "ćá", "ća" }, -- fake word with c-acute and tonal acute; add a real word if you know one
	}
	
	self:iterate(examples, "check_makeEntryName")
end

return p