local tests = require("Module:UnitTests")
local getByCode = require("Module:families").getByCode
local families = {}
setmetatable(families, { -- Auto-create family objects: families.roa -> family object for Romance.
__index = function(self, key)
local family = getByCode(key) or error("No language with code " .. key .. ".")
self[key] = family
return family
end
})
function tests:test_getCanonicalName()
local examples = {
{"roa", "Romance"},
{"gem", "Germanic"},
}
self:iterate(examples, function(self, code, expected)
self:equals(code, families[code]:getCanonicalName(), expected)
end)
end
function tests:test_makeWikipediaLink()
local examples = {
{"roa", "[[w:Romance languages|Romance]]"},
{"gem", "[[w:Germanic languages|Germanic]]"},
{"sgn-jsl", "[[w:Japanese Sign Language family|Japanese Sign Languages]]"},
}
self:iterate(examples, function(self, code, expected)
self:equals(code, families[code]:makeWikipediaLink(), expected, {nowiki=1})
end)
end
function tests:test_getWikidataItem()
local examples = {
{"roa", "Q19814"},
{"gem", "Q21200"},
}
self:iterate(examples, function(self, code, expected)
self:equals(code, families[code]:getWikidataItem(), expected)
end)
end
function tests:test_toJSON()
self:equals('roa-JSON', families.roa:toJSON(), [[{"type" : "family", "wikidataItem" : "Q19814", "code" : "roa", "canonicalName" : "Romance", "otherNames" : ["Romanic", "Latin", "Neolatin", "Neo-Latin"], "categoryName" : "Romance languages", "family" : "itc"}]])
end
return tests