Module:grc-utilities/testcases

Definition from Wiktionary, the free dictionary
Jump to: navigation, search

All tests passed. (refresh)

testFindAmbig:
Text Expected Actual Differs at
Passed Διονύσια ι, υ, ι, α ι, υ, ι, α
Passed πᾶς
Passed οἵᾳ
Passed μίᾰ ι ι
Passed ἐᾱ́ν
testPronunciationOrder:
Text Expected Actual Differs at
Passed ἐᾱ́ν ἐά¯ν ἐά¯ν
Passed γᾰ́ρ γά˘ρ γά˘ρ
Passed ᾰ̓λλᾰ́ ἀ˘λλά˘ ἀ˘λλά˘
testReorderDiacritics:
Text Expected Actual Differs at
Passed ά̓̆νερ ᾰ̓́νερ ᾰ̓́νερ
Passed ᾰ̓́̄ ᾱ̆̓́ ᾱ̆̓́
Passed ά̓̆̄ ᾱ̆̓́ ᾱ̆̓́
Passed ά̓̄̆ ᾱ̆̓́ ᾱ̆̓́
testStandardDiacritics:
Text Expected Actual Differs at
Passed ἄ˘κρος ἄ̆κρος ἄ̆κρος
testTokenize:
Text Expected Actual Differs at
Passed ἀληθέι ἀ, λ, η, θ, έ, ι ἀ, λ, η, θ, έ, ι
Passed πόλεως (noun) π, ό, λ, εω, ς π, ό, λ, εω, ς
Passed πόλεων (noun) π, ό, λ, εω, ν π, ό, λ, εω, ν
Passed οἷαι οἷ, αι οἷ, αι
Passed ΟἿΑΙ ΟἿ, ΑΙ ΟἿ, ΑΙ
Passed Αἰσχύλος Αἰ, σ, χ, ύ, λ, ο, ς Αἰ, σ, χ, ύ, λ, ο, ς
Passed ἀναῡ̈τέω ἀ, ν, α, ῡ̈, τ, έ, ω ἀ, ν, α, ῡ̈, τ, έ, ω
Passed τούτῳ τ, ού, τ, ῳ τ, ού, τ, ῳ

local tests = require("Module:UnitTests")
local m_utils = require("Module:grc-utilities")

local compose = mw.ustring.toNFC
local tag = m_utils.tag

function tests:checkStandardDiacritics(example, expected)
	self:equals(
		tag(example),
		compose(m_utils.standardDiacritics(example)),
		compose(expected),
		{ display = tag }
	)
end

function tests:testStandardDiacritics()
	local examples = {
		{ "ἄ˘κρος", "ἄ̆κρος" },
	}
	
	tests:iterate(examples, "checkStandardDiacritics")
end

function tests:checkReorderDiacritics(example, expected)
	self:equals(
		tag(example),
		compose(m_utils.reorderDiacritics(example)),
		compose(expected),
		{ display = tag }
	)
end

function tests:testReorderDiacritics()
	local examples = {
		{ "ά̓̆νερ", "ᾰ̓́νερ" },
		{ "ᾰ̓́̄", "ᾱ̆̓́" },
		{ "ά̓̆̄", "ᾱ̆̓́" },
		{ "ά̓̄̆", "ᾱ̆̓́" },
	}
	
	tests:iterate(examples, "checkReorderDiacritics")
end

local function displayFindAmbig(word)
	local vowel_list = m_utils.findAmbig(word, true)
	return compose(table.concat(vowel_list, ", "))
end

function tests:checkFindAmbig(example, expected)
	self:equals(
		tag(example),
		displayFindAmbig(example),
		expected,
		{ display = tag }
	)
end

function tests:testFindAmbig()
	local examples = {
		{ "Διονύσια", "ι, υ, ι, α" },
		{ "πᾶς", "" },
		{ "οἵᾳ", "" },
		{ "μίᾰ", "ι" },
		{ "ἐᾱ́ν", "" },
	}
	
	tests:iterate(examples, "checkFindAmbig")
end

local function displayTokenization(example, isNoun)
	return table.concat(m_utils.tokenize(example, isNoun), ", ")
end

function tests:checkTokenize(example, expected, isNoun)
	self:equals(
		tag(example) .. (isNoun and " (noun)" or ""),
		compose(displayTokenization(example, isNoun)),
		compose(expected),
		{ display = tag }
	)
end

function tests:testTokenize()
	local examples = {
		{ "ἀληθέι", "ἀ, λ, η, θ, έ, ι" },
		{ "πόλεως", "π, ό, λ, εω, ς", true },
		{ "πόλεων", "π, ό, λ, εω, ν", true },
		{ "οἷαι", "οἷ, αι" },
		{ "ΟἿΑΙ", "ΟἿ, ΑΙ" },
		{ "Αἰσχύλος", "Αἰ, σ, χ, ύ, λ, ο, ς" },
		{ "ἀναῡ̈τέω", "ἀ, ν, α, ῡ̈, τ, έ, ω"},
		{ "τούτῳ", "τ, ού, τ, ῳ" },
	}
	
	tests:iterate(examples, "checkTokenize")
end

function tests:checkPronunciationOrder(example, expected)
	self:equals(
		tag(example),
		compose(m_utils.pronunciationOrder(example)),
		compose(expected),
		{ display = tag }
	)
end

function tests:testPronunciationOrder()
	local examples = {
		{ "ἐᾱ́ν", "ἐά¯ν" },
		{ "γᾰ́ρ", "γά˘ρ" },
		{ "ᾰ̓λλᾰ́", "ἀ˘λλά˘" },
	}
	
	tests:iterate(examples, "checkPronunciationOrder")
end

return tests