Revision as of 14:33, 4 November 2020 editGonnym (talk | contribs)Autopatrolled, Extended confirmed users, Template editors222,889 editsNo edit summary← Previous edit |
Latest revision as of 13:01, 10 December 2024 edit undoGonnym (talk | contribs)Autopatrolled, Extended confirmed users, Template editors222,889 editsNo edit summary |
(19 intermediate revisions by 2 users not shown) |
Line 1: |
Line 1: |
|
-- Unit tests for ]. Click talk page to run tests. |
|
-- Unit tests for ]. Click talk page to run tests. |
|
local p = require('Module:UnitTests') |
|
local p = require('Module:UnitTests') |
|
local m_Language = require('Module:Language') |
|
local m_Language = require('Module:Wikt-lang') |
|
local name_from_tag = require('Module:Lang/sandbox')._name_from_tag |
|
local name_from_tag = require('Module:Lang')._name_from_tag |
|
|
|
|
|
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:Wikt-lang/sandbox|main|', '}}', '{{#invoke:Wikt-lang|wiktlang|', '}}', |
|
{ |
|
{ |
|
{ "grc|δημοκρᾰτῐ́ᾱ"}, |
|
{"grc|δημοκρᾰτῐ́ᾱ"}, |
|
{ "ha|àzàhàr̃iyyā̀"}, |
|
{"ha|àzàhàr̃iyyā̀"}, |
|
{ "la|coëō"}, |
|
{"la|coëō"}, |
|
{ "nci|Quetzalcōātl"}, |
|
{"nci|Quetzalcōātl"}, |
|
{ "ru|ру́сский язы́к"}, |
|
{"ru|ру́сский язы́к"}, |
|
|
{"he|שלום"}, |
|
{ "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 |
|
|
|
|
|
|
function p:test_2_private_codes() |
|
|
self:preprocess_equals_preprocess_many('{{#invoke:Wikt-lang/sandbox|main|', '}}', '{{#invoke:Wikt-lang|wiktlang|', '}}', |
|
|
{ |
|
|
{"cel-x-proto|*beru"}, -- this private code is taken from Module:Lang's data |
|
|
{"cel-x-bryproto|test"}, |
|
|
{"gem-x-proto|test"}, |
|
|
{"gmw-x-proto|test"}, |
|
|
{"grk-x-proto|test́к"}, |
|
|
{"ine-x-bsproto|test"}, |
|
|
{"ine-x-proto|test"}, |
|
|
{"non-x-proto|test"}, |
|
|
{"poz-x-polproto|test"}, |
|
|
{"sem-x-proto|test"}, |
|
|
{"sla-x-proto|test"}, |
|
|
{"zle-x-ort|test"}, |
|
|
}, {nowiki=1}) |
|
|
end |
|
|
|
|
|
local function test_patterns_get(main) |
|
local function get_test_patterns(main) |
|
local data = require('Module:Language/data/sandbox') |
|
local data = require('Module:Wikt-lang/data/sandbox') |
|
local language_codes = {} |
|
local language_codes = {} |
|
|
|
|
|
|
|
if main then |
|
if main then |
|
for code, values in pairs(data) do |
|
for code, values in pairs(data) do |
|
table.insert(language_codes, {code, values.name}) |
|
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 |
|
end |
|
end |
|
|
|
|
|
|
|
local function comp(a, b) |
|
local function comp(a, b) |
|
return a < b |
|
return a < b |
|
end |
|
end |
|
|
|
|
|
|
|
table.sort(language_codes, comp) |
|
table.sort(language_codes, comp) |
|
return language_codes |
|
return language_codes |
|
end |
|
end |
|
|
|
|
|
function p:test_2_link() |
|
function p:test_3_all_database_links() |
|
local wiktionary_test_patterns = test_patterns_get(true) |
|
local wiktionary_test_patterns = get_test_patterns(true) |
|
local name_from_tag = require('Module:Lang')._name_from_tag |
|
|
local full_test_patterns = {} |
|
local full_test_patterns = {} |
|
|
|
|
Line 59: |
Line 62: |
|
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:Wikt-lang/sandbox|main|', '}}', '{{#invoke:Wikt-lang|wiktlang|no_cat=yes|', '}}', full_test_patterns, {nowiki=1}) |
|
end |
|
end |
|
|
|
|
|
function p:test_3_link_redirects() |
|
function p:test_4_errors() |
|
|
self:preprocess_equals_preprocess_many('{{#invoke:Wikt-lang/sandbox|main|', '}}', '{{#invoke:Wikt-lang|wiktlang|', '}}', |
|
local wiktionary_test_patterns = test_patterns_get(false) |
|
|
|
{ |
|
local name_from_tag = require('Module:Lang')._name_from_tag |
|
|
|
-- not a valid code |
|
local full_test_patterns = {} |
|
|
|
{"abcd|test"}, |
|
|
|
|
|
-- not a valid private code |
|
|
{"abc-x-proto|test"}, |
|
|
|
|
|
|
-- no code |
|
for i = 1, #wiktionary_test_patterns do |
|
|
|
{""}, |
|
local code = wiktionary_test_patterns |
|
|
|
|
|
table.insert(full_test_patterns, {code .. "|test", code .. "|test"}) |
|
|
|
-- text, but no code |
|
end |
|
|
|
{"|test"}, |
|
|
|
|
self:preprocess_equals_preprocess_many('{{#invoke:Language/sandbox|wiktlang|', '}}', '{{#invoke:Language|wiktlang|no_cat=yes|', '}}', full_test_patterns, {nowiki=1}) |
|
|
end |
|
|
|
|
|
|
|
-- display text, but no code |
|
function p:test_4_compare_language_names() |
|
|
|
{"||test"}, |
|
local wiktionary_test_patterns = test_patterns_get(true) |
|
|
|
|
|
local name_from_tag = require('Module:Lang')._name_from_tag |
|
|
|
-- no text |
|
local full_test_patterns = {} |
|
|
|
{"la|"}, |
|
|
|
|
|
-- no link text |
|
|
{"la||test"}, |
|
|
|
|
|
|
-- invalid unnamed |4= |
|
for i = 1, #wiktionary_test_patterns do |
|
|
|
{"la|test|test|number 4"}, |
|
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 |
|
|
|
|
|
|
|
-- invalid parameter (|test=) |
|
self:preprocess_equals_many('', '', full_test_patterns, {nowiki=1}) |
|
|
|
{"la|test|test|test=number 4"}, |
|
|
|
|
|
}, {nowiki=1}) |
|
end |
|
end |
|
|
|
|