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