Misplaced Pages

Module:Wikt-lang/testcases: Difference between revisions

Article snapshot taken from Wikipedia with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.
< Module:Wikt-lang Browse history interactively← Previous editNext edit →Content deleted Content added
Revision as of 14:30, 4 November 2020 editGonnym (talk | contribs)Autopatrolled, Extended confirmed users, Template editors222,872 editsNo edit summary← Previous edit Revision as of 14:33, 4 November 2020 edit undoGonnym (talk | contribs)Autopatrolled, Extended confirmed users, Template editors222,872 editsNo edit summaryNext edit →
Line 5: Line 5:


function p:test_1_link() function p:test_1_link()
self:preprocess_equals_preprocess_many('{{#invoke:Language/sandbox|wiktlang|', '}}', '{{#invoke:Language|wiktlang|', '}}', self:preprocess_equals_preprocess_many('{{#invoke:Language/sandbox|wiktlang|', '}}', '{{#invoke:Language|wiktlang|', '}}',
{ {
{ "grc|δημοκρᾰτῐ́ᾱ"}, { "grc|δημοκρᾰτῐ́ᾱ"},
{ "ha|àzàhàr̃iyyā̀"}, { "ha|àzàhàr̃iyyā̀"},
Line 12: Line 12:
{ "nci|Quetzalcōātl"}, { "nci|Quetzalcōātl"},
{ "ru|ру́сский язы́к"}, { "ru|ру́сский язы́к"},
{ "sh|ćá|ća" }, -- fake word with c-acute and tonal acute; add a real word if you know one { "sh|ćá|ća" }, -- fake word with c-acute and tonal acute; add a real word if you know one
},{nowiki=1})
}
,{nowiki=1})
end end


Line 60: Line 59:
end end
self:preprocess_equals_preprocess_many('{{#invoke:Language/sandbox|wiktlang|', '}}', '{{#invoke:Language|wiktlang|no_cat=yes|', '}}', full_test_patterns, {nowiki=1}) self:preprocess_equals_preprocess_many('{{#invoke:Language/sandbox|wiktlang|', '}}', '{{#invoke:Language|wiktlang|no_cat=yes|', '}}', full_test_patterns, {nowiki=1})
end end


Line 73: Line 72:
end end
self:preprocess_equals_preprocess_many('{{#invoke:Language/sandbox|wiktlang|', '}}', '{{#invoke:Language|wiktlang|no_cat=yes|', '}}', full_test_patterns, {nowiki=1}) self:preprocess_equals_preprocess_many('{{#invoke:Language/sandbox|wiktlang|', '}}', '{{#invoke:Language|wiktlang|no_cat=yes|', '}}', full_test_patterns, {nowiki=1})
end end


Line 89: Line 88:
end end
end end

mw.logObject(full_test_patterns) self:preprocess_equals_many('', '', full_test_patterns, {nowiki=1})
self:preprocess_equals_many('', '', full_test_patterns, {nowiki=1})
end end


Line 112: Line 110:
}) })
end end

mw.logObject(full_test_patterns) self:preprocess_equals_many('', '', full_test_patterns, {nowiki=1})
self:preprocess_equals_many('', '', full_test_patterns, {nowiki=1})
end end



Revision as of 14:33, 4 November 2020

This is the test cases page for the module Module:Wikt-lang. Results of the test cases.
-- Unit tests for ]. Click talk page to run tests.
local p = require('Module:UnitTests')
local m_Language = require('Module:Language')
local name_from_tag = require('Module:Lang/sandbox')._name_from_tag

function p:test_1_link()
	self:preprocess_equals_preprocess_many('{{#invoke:Language/sandbox|wiktlang|', '}}', '{{#invoke:Language|wiktlang|', '}}',
		{
			{ "grc|δημοκρᾰτῐ́ᾱ"},
			{ "ha|àzàhàr̃iyyā̀"},
			{ "la|coëō"},
			{ "nci|Quetzalcōātl"},
			{ "ru|ру́сский язы́к"},
			{ "sh|ćá|ća" },														-- fake word with c-acute and tonal acute; add a real word if you know one
		},{nowiki=1})
end


local function test_patterns_get(main)
	local data = require('Module:Language/data/sandbox')
	local language_codes = {}
	
	if main then
		for code, values in pairs(data) do
			table.insert(language_codes, {code, values.name})
		end
		
	else
		for code, redirect_code in pairs(data) do
			local redirect_name
			if data and data.name then
				redirect_name = data.name
			else
				redirect_name = name_from_tag({code})
				if not redirect_name or redirect_name:find("error") then
					redirect_name = mw.language.fetchLanguageName(redirect_code, 'en')
				end
			end
			table.insert(language_codes, {code, redirect_name, redirect_code, redirect_name})
		end
	end
	
	local function comp(a, b)
		return a < b
	end
	
	table.sort(language_codes, comp)
	return language_codes
end

function p:test_2_link()
	local wiktionary_test_patterns = test_patterns_get(true)
	local name_from_tag = require('Module:Lang')._name_from_tag
	local full_test_patterns = {}

	for i = 1, #wiktionary_test_patterns do
		local code = wiktionary_test_patterns
		table.insert(full_test_patterns, {code .. "|test", code .. "|test"})
	end
	
	self:preprocess_equals_preprocess_many('{{#invoke:Language/sandbox|wiktlang|', '}}', '{{#invoke:Language|wiktlang|no_cat=yes|', '}}', full_test_patterns, {nowiki=1})
end

function p:test_3_link_redirects()
	local wiktionary_test_patterns = test_patterns_get(false)
	local name_from_tag = require('Module:Lang')._name_from_tag
	local full_test_patterns = {}

	for i = 1, #wiktionary_test_patterns do
		local code = wiktionary_test_patterns
		table.insert(full_test_patterns, {code .. "|test", code .. "|test"})
	end
	
	self:preprocess_equals_preprocess_many('{{#invoke:Language/sandbox|wiktlang|', '}}', '{{#invoke:Language|wiktlang|no_cat=yes|', '}}', full_test_patterns, {nowiki=1})
end

function p:test_4_compare_language_names()
	local wiktionary_test_patterns = test_patterns_get(true)
	local name_from_tag = require('Module:Lang')._name_from_tag
	local full_test_patterns = {}

	for i = 1, #wiktionary_test_patterns do
		local code = wiktionary_test_patterns
		local en_wiki_name = name_from_tag({code})
		local wiktionary_name = wiktionary_test_patterns
		if wiktionary_name then
			table.insert(full_test_patterns, {code .. ': ' .. wiktionary_name, code .. ': ' .. en_wiki_name})
		end
	end

	self:preprocess_equals_many('', '', full_test_patterns, {nowiki=1})
end

function p:test_5_compare_language_names_redirects()
	local wiktionary_test_patterns = test_patterns_get(false)
	local name_from_tag = require('Module:Lang')._name_from_tag
	local full_test_patterns = {}

	for i = 1, #wiktionary_test_patterns do
		local code = wiktionary_test_patterns
		local wiktionary_name = wiktionary_test_patterns
		local redirect_code = wiktionary_test_patterns	

		local en_wiki_name = name_from_tag({code})
		local en_wiki_redirect_name = name_from_tag({redirect_code})

		table.insert(full_test_patterns, {
				code .. ': ' .. wiktionary_name .. " / " .. redirect_code .. ": " .. wiktionary_name,
				code .. ': ' .. en_wiki_name .. " / " .. redirect_code .. ": " .. en_wiki_redirect_name,
			})
	end

	self:preprocess_equals_many('', '', full_test_patterns, {nowiki=1})
end

return p
Category: