Jump to content

Module:Ancient Greek/typing/testcases: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
 
m fix
Line 46: Line 46:


-- from [[wikt:Module:UnitTests]]
-- from [[wikt:Module:UnitTests]]
function p:iterate(examples, func)
function tests:iterate(examples, func)
if type(examples) ~= 'table' then
if type(examples) ~= 'table' then
error('First argument of iterate should be a table, not ' .. type(examples) .. '.')
error('First argument of iterate should be a table, not ' .. type(examples) .. '.')

Revision as of 21:13, 22 November 2017

local tests = require("Module:UnitTests")
local tag = mw.text.tag
local decompose = mw.ustring.toNFD
local Latin_to_Greek = require("Module:Ancient Greek/typing").to_Greek

local function tag_Greek(text)
	return tag("span", { lang = "grc" }, text)
end

local function code(text)
	return tag("code", nil, text)
end

local options = { display = tag_Greek, show_difference = true }
function tests:check(example, expected)
	self:equals(code(example),
		decompose(Latin_to_Greek(example)),
		decompose(expected),
		options)
end

function tests:test()
	local examples = {
		{ "a__i", "ᾱͅ" },
		{ "a)lhqh/s", "ἀληθής" },
		{ "a)lhqhs*", "ἀληθησ" },
		{ "a)lhqhs-", "ἀληθησ-" },
		{ "a^)nh/r", "ᾰ̓νήρ" },
		{ "Phlhi+a/dhs", "Πηληϊάδης" },
		{ "Phlhi^+a^/dhs", "Πηληῐ̈ᾰ́δης" },
		{ "Πηληϊ^ά^δης", "Πηληῐ̈ᾰ́δης" },
		{ "e)a_/n", "ἐᾱ́ν" },
		{ "ἐά_ν", "ἐᾱ́ν" },
		{ "pa=sa^", "πᾶσᾰ" },
		{ "u_(mei=s", "ῡ̔μεῖς" },
		{ "a/)^ner", "ᾰ̓́νερ" },
		{ "a/^)ner", "ᾰ̓́νερ" },
		{ "a)/^ner", "ᾰ̓́νερ" },
		{ "a)^/ner", "ᾰ̓́νερ" },
		{ "dai+/frwn", "δαΐφρων" },
		{ "dai/+frwn", "δαΐφρων" },
	}
	
	self:iterate(examples, "check")
end

-- from [[wikt:Module:UnitTests]]
function tests: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))
			elseif type(example) == 'string' then
				self:heading(example)
			else
				error('iterate does not know what to do with example number ' .. i .. ', whose type is ' .. type(example) .. '.')
			end
		end
	elseif type(func) == 'function' then -- used in [[Module:he-translit/testcases]]
		for i, example in ipairs(examples) do
			if type(example) == 'table' then
				func(self, unpack(example))
			elseif type(example) == 'string' then
				self:heading(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 function or a string, not ' .. type(func) .. '.')
	end
end

return tests