Jump to content

Module:Wikt-lang/testcases

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Erutuon (talk | contribs) at 18:39, 23 June 2018 (start testcases). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
-- 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

function p:check_makeEntryName(languageCode, word, expected)
	self:equals(word, m_Language.makeEntryName(word, languageCode), expected)
end

p['test makeEntryName'] = function (self)
	local examples = {
		{ "la", "homō", "homo" },
		{ "grc", "δημοκρᾰτῐ́ᾱ", "δημοκρατία" },
	}
	
	self:iterate(examples, "check_makeEntryName")
end

return p