Modul:etymology languages/testcases

Minden teszt sikeres. (frissítés)

Szöveg Várt Tényleges
test_getCanonicalName:
Sikeres sem-jar Jewish Aramaic Jewish Aramaic
Szöveg Várt Tényleges
test_getOtherNames:
Sikeres sem-jar {"Judeo-Aramaic"} {"Judeo-Aramaic"}
Szöveg Várt Tényleges
test_getParentCode:
Sikeres sem-jar arc arc
Szöveg Várt Tényleges
test_getWikidataItem:
Sikeres sem-jar Q2633045 Q2633045
Sikeres sbr-prk (nil) (nil)
Szöveg Várt Tényleges
test_getWikipediaArticle:
Sikeres sem-jar Judeo-Aramaic languages Judeo-Aramaic languages
Sikeres sbr-prk Sabari Sabari
Szöveg Várt Tényleges
test_makeWikipediaLink:
Sikeres sem-jar [[w:Judeo-Aramaic languages|Jewish Aramaic]] [[w:Judeo-Aramaic languages|Jewish Aramaic]]
Sikeres sbr-prk [[w:Sabari|Sabari]] [[w:Sabari|Sabari]]
Sikeres mkh-okm-A [[w:Khmer language#Historical periods|Angkorian Old Khmer]] [[w:Khmer language#Historical periods|Angkorian Old Khmer]]
Sikeres urj-fpr-pro [[w:Proto-Finno-Permic|Proto-Finno-Permic]] [[w:Proto-Finno-Permic|Proto-Finno-Permic]]

local tests = require("Module:UnitTests")

local getByCode = require("Module:etymology languages").getByCode
local tag = require("Module:script utilities").tag_text

local langs = {}
setmetatable(langs, { -- Auto-create language objects: langs.en -> language object for English.
	__index = function(self, key)
		local lang = getByCode(key) or error("No language with code " .. key .. ".")
		self[key] = lang
		return lang
	end
})

function tests:test_getWikipediaArticle()
	local examples = {
		{"sem-jar", "Judeo-Aramaic languages"},
		{"sbr-prk", "Sabari"},
	}

	self:iterate(examples, function(self, lang, expected)
		self:equals(lang, langs[lang]:getWikipediaArticle(), expected)
	end)
end

function tests:test_getWikidataItem()
	local examples = {
		{"sem-jar", "Q2633045"},
		{"sbr-prk", nil},
	}

	self:iterate(examples, function(self, lang, expected)
		self:equals(lang, langs[lang]:getWikidataItem(), expected)
	end)
end

function tests:test_makeWikipediaLink()
	local examples = {
		{"sem-jar", "[[w:Judeo-Aramaic languages|Jewish Aramaic]]"},
		{"sbr-prk", "[[w:Sabari|Sabari]]"},
		{"mkh-okm-A", "[[w:Khmer language#Historical periods|Angkorian Old Khmer]]"},
		{"urj-fpr-pro", "[[w:Proto-Finno-Permic|Proto-Finno-Permic]]"},
	}
	
	self:iterate(examples, function(self, lang, expected)
		self:equals(lang, langs[lang]:makeWikipediaLink(), expected, {nowiki=1})
	end)
end

function tests:test_getCanonicalName()
	local examples = {
		{"sem-jar", "Jewish Aramaic"},
	}

	self:iterate(examples, function(self, lang, expected)
		self:equals(lang, langs[lang]:getCanonicalName(), expected)
	end)
end

function tests:test_getOtherNames()
	local examples = {
		{"sem-jar", {"Judeo-Aramaic"}},
	}

	self:iterate(examples, function(self, lang, expected)
		self:equals_deep(lang, langs[lang]:getOtherNames(), expected)
	end)
end

function tests:test_getParentCode()
	local examples = {
		{"sem-jar", "arc"},
	}

	self:iterate(examples, function(self, lang, expected)
		self:equals(lang, langs[lang]:getParentCode(), expected)
	end)
end

return tests