Pergi ke kandungan

Modul:families/testcases

Daripada Wikikamus
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 = {
		{"map", "Austronesia"},
		{"gem", "Jermanik"},
	}

	self:iterate(examples, function(self, code, expected)
		self:equals(code, families[code]:getCanonicalName(), expected)
	end)
end

function tests:test_makeWikipediaLink()
	local examples = {
		{"map", "[[w:Bahasa-bahasa Austronesia|Austronesia]]"},
		{"gem", "[[w:Bahasa-bahasa Jermanik|Jermanik]]"},
		{"sgn-jsl", "[[w:Keluarga Bahasa Isyarat Jepun|Bahasa Isyarat Jepun]]"},
	}
	
	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