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 = 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:getCanonicalName(), expected)
end)
end
function tests:test_makeWikipediaLink()
local examples = {
{"roa", "]"},
{"gem", "]"},
{"sgn-jsl", "]"},
}
self:iterate(examples, function(self, code, expected)
self:equals(code, families: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:getWikidataItem(), expected)
end)
end
function tests:test_toJSON()
self:equals('roa-JSON', families.roa:toJSON(), , "categoryName" : "Romance languages", "family" : "itc"}]])
end
return tests