Open main menu

Module:languages/sandbox/testcases

4 tests failed. (refresh)

Text Expected Actual
testcases for getCategoryName:
Passed en English language English language
Passed af Afrikaans language Afrikaans language
Passed av Avar language Avar language
Passed ht Haitian Creole language Haitian Creole language
Passed ase American Sign Language American Sign Language
Text Expected Actual
testcases for getFamily:
Passed en gmw gmw
Passed ht crp crp
Passed ase sgn sgn
Text Expected Actual
testcases for getOtherNames:
Failed ht {"Creole", "Haitian", "Kreyòl"} {}
Failed ase {"Ameslan", "ASL"} {}
Text Expected Actual
testcases for getScriptCodes:
Passed en {"Latn", "Brai", "Shaw", "Dsrt"} {"Latn", "Brai", "Shaw", "Dsrt"}
Passed ht {"Latn"} {"Latn"}
Passed ase {"Sgnw"} {"Sgnw"}
Text Expected Actual
testcases for getWikidataItem:
Passed en Q1860 Q1860
Passed eo Q143 Q143
Passed aql-pro Q18389588 Q18389588
Passed mkh-ban-pro (nil) (nil)
Text Expected Actual
testcases for getWikipediaArticle:
Passed en English language English language
Passed af Afrikaans Afrikaans
Passed ae Avestan Avestan
Passed ht Haitian Creole Haitian Creole
Passed ase American Sign Language American Sign Language
Passed dv Maldivian language Maldivian language
Passed eo Esperanto Esperanto
Passed goh Old High German Old High German
Text Expected Actual
testcases for makeEntryName:
Passed hūmānitās (Latin, la) humanitas humanitas
Passed coëō (Latin, la) coeo coeo
Passed àzàhàr̃iyyā̀ (Hausa, ha) azahariyya azahariyya
Passed ¿cómo te llamas? (Spanish, es) cómo te llamas cómo te llamas
Passed ¿ ? (Spanish, es) ¿ ? ¿ ?
Passed ¡ ! (Spanish, es) ¡ ! ¡ !
Passed ¡ (Translingual, mul) ¡ ¡
Passed Πηληῐ̈ᾰ́δης (Ancient Greek, grc) Πηληϊάδης Πηληϊάδης
Passed العَرَبِيَّة (Arabic, ar) العربية العربية
Passed ٱ (Arabic, ar) ٱ ٱ
Passed ـُ (Arabic, ar) ـُ ـُ
Text Expected Actual
testcases for makeSortKey:
diacritic removal
Failed Πηληῐ̈ᾰ́δης (Ancient Greek, grc) ΠΗΛΗΙΑΔΗΣ ΠΗΛΗῘᾸΔΗΣ
Passed shį́į́dą́ą́ʼ (Navajo, nv) SHIIDAA SHIIDAA
dedicated sortkey modules
Passed Tuyên ngôn toàn thế giới về nhân quyền của Liên Hợp Quốc (Vietnamese, vi) TUYE₂N NGO₂N TOAN1 THE₂4 GIO₃I4 VE₂1 NHA₂N QUYE₂N1 CUA2 LIE₂N HO₃P5 QUO₂C4 TUYE₂N NGO₂N TOAN1 THE₂4 GIO₃I4 VE₂1 NHA₂N QUYE₂N1 CUA2 LIE₂N HO₃P5 QUO₂C4
Passed 命裡有時終須有,命裡無時莫強求 (Chinese, zh) 口05衣07月02日06糸05頁03月02,口05衣07火08日06艸07弓08水02 口05衣07月02日06糸05頁03月02,口05衣07火08日06艸07弓08水02
Passed ⿺辶⿳穴⿲月⿱⿲幺言幺⿲長馬長刂心⿺辶⿳穴⿲月⿱⿲幺言幺⿲長馬長刂心麵 (Chinese, zh) 辵54辵54麥09 辵54辵54麥09
dotted and dotless i
Passed İzmir (Turkish, tr) İZMİR İZMİR
Passed ışık (Turkish, tr) IŞIK IŞIK
Text Expected Actual
testcases for makeWikipediaLink:
Passed en [[w:English language|English]] [[w:English language|English]]
Passed af [[w:Afrikaans|Afrikaans]] [[w:Afrikaans|Afrikaans]]
Passed ae [[w:Avestan|Avestan]] [[w:Avestan|Avestan]]
Text Expected Actual
testcases for toJSON:
Failed en-toJSON {"ancestors" : ["enm"], "code" : "en", "canonicalName" : "English", "wikimediaLanguages" : ["en", "simple"], "wikidataItem" : "Q1860", "scripts" : ["Latn", "Brai", "Shaw", "Dsrt"], "family" : "gmw", "otherNames" : ["Modern English", "New English", "Hawaiian Creole English", "Hawai'ian Creole English", "Hawaiian Creole", "Hawai'ian Creole", "Polari", "Yinglish"], "categoryName" : "English language", "type" : "regular"} {"ancestors" : ["enm"], "code" : "en", "canonicalName" : "English", "wikimediaLanguages" : ["en", "simple"], "wikidataItem" : "Q1860", "scripts" : ["Latn", "Brai", "Shaw", "Dsrt"], "family" : "gmw", "otherNames" : [], "categoryName" : "English language", "type" : "regular"}

local tests = require("Module:UnitTests")

local tag = require("Module:script utilities").tag_text
local m_languages = require("Module:languages/sandbox")

-- Auto-create language objects: langs.en -> language object for English.
local langs = require("Module:languages/cache/sandbox")

function tests:check(funcName)
	-- Use English language object to test for existence of function.
	func = langs.en[funcName] or error("No function named " .. funcName .. " in language object.")
	local options = {}
	return function(self, lang, example, expected, ...)
		function options.display(text)
			return tag(text, lang)
		end
		self:equals(tag(example, lang) .. " (" .. lang:getCanonicalName() .. ", <code>" .. lang:getCode() .. "</code>)",
			func(lang, example, ...),
			expected,
			options)
	end
end

function tests:test_makeEntryName()
	local examples = {
		{ langs.la, "hūmānitās", "humanitas" },
		{ langs.la, "coëō", "coeo" },
		{ langs.ha, "àzàhàr̃iyyā̀", "azahariyya" },
		{ langs.es, "¿cómo te llamas?", "cómo te llamas" },
		{ langs.es, "¿ ?", "¿ ?" },
		{ langs.es, "¡ !", "¡ !" },
		{ langs.mul, "¡", "¡" },
		{ langs.grc, "Πηληῐ̈ᾰ́δης", "Πηληϊάδης" },
		{ langs.ar, "العَرَبِيَّة", "العربية" },
		{ langs.ar, "ٱ", "ٱ" }, -- special case: alif waṣla
		{ langs.ar, "ـُ", "ـُ" }, -- special case: taṭwīl with vowel diacritic
	}
	
	self:iterate(examples, self:check("makeEntryName"))
end

function tests:test_makeSortKey()
	local examples = {
		"diacritic removal",
		{ langs.grc, "Πηληῐ̈ᾰ́δης", "ΠΗΛΗΙΑΔΗΣ" },
		{ langs.nv, "shį́į́dą́ą́ʼ", "SHIIDAA" },
		"dedicated sortkey modules",
		{ langs.vi, "Tuyên ngôn toàn thế giới về nhân quyền của Liên Hợp Quốc", "TUYE₂N NGO₂N TOAN1 THE₂4 GIO₃I4 VE₂1 NHA₂N QUYE₂N1 CUA2 LIE₂N HO₃P5 QUO₂C4" },
		{ langs.zh, "命裡有時終須有,命裡無時莫強求", "口05衣07月02日06糸05頁03月02,口05衣07火08日06艸07弓08水02" },
		{ langs.zh, "⿺辶⿳穴⿲月⿱⿲幺言幺⿲長馬長刂心⿺辶⿳穴⿲月⿱⿲幺言幺⿲長馬長刂心麵", "辵54辵54麥09" },
		"dotted and dotless i",
		{ langs.tr, "İzmir", "İZMİR" },
		{ langs.tr, "ışık", "IŞIK" }
	}
	self:iterate(examples, self:check("makeSortKey"))
end

function tests:test_getWikipediaArticle()
	local examples = {
		{"en", "English language"},
		{"af", "Afrikaans"},
		{"ae", "Avestan"},
		{"ht", "Haitian Creole"},
		{"ase", "American Sign Language"},
		{"dv", "Maldivian language"},
		{"eo", "Esperanto"},
		{"goh", "Old High German"},
	}

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

function tests:test_makeWikipediaLink()
	local examples = {
		{"en", "[[w:English language|English]]"},
		{"af", "[[w:Afrikaans|Afrikaans]]"},
		{"ae", "[[w:Avestan|Avestan]]"},
	}
	
	self:iterate(examples, function(self, lang, expected)
		self:equals(lang, langs[lang]:makeWikipediaLink(), expected, {nowiki=1})
	end)
end

function tests:test_getFamily()
	local examples = {
		{"en", "gmw"},
		{"ht", "crp"},
		{"ase", "sgn"}
	}

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

function tests:test_getScriptCodes()
	local examples = {
		{"en", {"Latn", "Brai", "Shaw", "Dsrt"}},
		{"ht", {"Latn"}},
		{"ase", {"Sgnw"}}
	}

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

function tests:test_getOtherNames()
	local examples = {
		{"ht", {"Creole", "Haitian", "Kreyòl"}},
		{"ase", {"Ameslan", "ASL"}}
	}

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

function tests:test_getCategoryName()
	local examples = {
		{"en", "English language"},
		{"af", "Afrikaans language"},
		{"av", "Avar language"},
		{"ht", "Haitian Creole language"},
		{"ase", "American Sign Language"}
	}

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

function tests:test_getWikidataItem()
	local examples = {
		{"en", "Q1860"},
		{"eo", "Q143"},
		{"aql-pro", "Q18389588"},
		{"mkh-ban-pro", nil},
		
	}

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

function tests:test_toJSON() 
	self:equals('en-toJSON', langs.en:toJSON(), [[{"ancestors" : ["enm"], "code" : "en", "canonicalName" : "English", "wikimediaLanguages" : ["en", "simple"], "wikidataItem" : "Q1860", "scripts" : ["Latn", "Brai", "Shaw", "Dsrt"], "family" : "gmw", "otherNames" : ["Modern English", "New English", "Hawaiian Creole English", "Hawai'ian Creole English", "Hawaiian Creole", "Hawai'ian Creole", "Polari", "Yinglish"], "categoryName" : "English language", "type" : "regular"}]])
end

for k, v in require "Module:table".sortedPairs(tests) do
	if type(k) == "string" and k:sub(1, 5) == "test_" then
		local new_key = k:gsub('^test_(.+)$', 'testcases for <code>%1</code>')
		tests[new_key], tests[k] = v, nil
	end
end

return tests