Module:links/testcases

Definition from Wiktionary, the free dictionary
Jump to: navigation, search

1 test failed. (refresh)

test_links:
Text Expected Actual
anchor
Passed {{l|en|-er#Etymology 2|-er}} <span class="Latn" lang="en">[[-er#Etymology 2|-er]]</span> <span class="Latn" lang="en">[[-er#Etymology 2|-er]]</span>
Passed {{l|en|[[-er#Etymology 2|-er]]}} <span class="Latn" lang="en">[[-er#Etymology 2|-er]]</span> <span class="Latn" lang="en">[[-er#Etymology 2|-er]]</span>
numeric character references in link target
Passed {{l|nia|wa&#39;a}} <span class="Latn" lang="nia">[[wa'a#Nias|wa'a]]</span> <span class="Latn" lang="nia">[[wa'a#Nias|wa'a]]</span>
Passed {{l|ja|恵&#8204;美|恵&amp;#8204;美}} <span class="Jpan" lang="ja">[[恵‌美#Japanese|恵&amp;#8204;美]]</span> <span class="Jpan" lang="ja">[[恵‌美#Japanese|恵&amp;#8204;美]]</span>
simple linking
Passed {{l|la|verbum}} <span class="Latn" lang="la">[[verbum#Latin|verbum]]</span> <span class="Latn" lang="la">[[verbum#Latin|verbum]]</span>
using wikilinks
Passed {{l|en|[[God]] be [[with]] [[you]]}} <span class="Latn" lang="en">[[God#English|God]] be [[with#English|with]] [[you#English|you]]</span> <span class="Latn" lang="en">[[God#English|God]] be [[with#English|with]] [[you#English|you]]</span>
alternative text
Passed {{l|en|go|went}} <span class="Latn" lang="en">[[go#English|went]]</span> <span class="Latn" lang="en">[[go#English|went]]</span>
Passed {{l|en|to [[go]]|went}} <span class="Latn" lang="en">to [[go#English|go]]</span> <span class="Latn" lang="en">to [[go#English|go]]</span>
sense id
Passed {{l|en|go|id=game}} <span class="Latn" lang="en">[[go#English-game|go]]</span> <span class="Latn" lang="en">[[go#English-game|go]]</span>
constructed terms
Passed {{l|sjn|mithril}} <span class="Latn" lang="sjn">[[Appendix&#x3a;Sindarin/mithril|mithril]]</span> <span class="Latn" lang="sjn">[[Appendix&#x3a;Sindarin/mithril|mithril]]</span>
reconstructed terms
Passed {{l|ine-pro|*bʰréh₂tēr}} <span class="Latinx" lang="ine-pro">[[Reconstruction&#x3a;Proto-Indo-European/bʰréh₂tēr|*bʰréh₂tēr]]</span> <span class="Latinx" lang="ine-pro">[[Reconstruction&#x3a;Proto-Indo-European/bʰréh₂tēr|*bʰréh₂tēr]]</span>
Passed {{#iferror:{{l|ine-pro|bʰréh₂tēr}}|Script error}} Script error Script error
Passed {{l|sla-pro|[[*dьnь]] [[*serda]]}} <span class="Latinx" lang="sla-pro">[[Reconstruction&#x3a;Proto-Slavic/dьnь|*dьnь]] [[Reconstruction&#x3a;Proto-Slavic/serda|*serda]]</span> <span class="Latinx" lang="sla-pro">[[Reconstruction&#x3a;Proto-Slavic/dьnь|*dьnь]] [[Reconstruction&#x3a;Proto-Slavic/serda|*serda]]</span>
Passed {{l|la|verbum .. [[verbum]] .. [[*verbum]] .. [[*verbum|verbum]] .. [[*verbum|*verba]]}} <span class="Latn" lang="la">verbum .. [[verbum#Latin|verbum]] .. [[Reconstruction&#x3a;Latin/verbum|*verbum]] .. [[Reconstruction&#x3a;Latin/verbum|verbum]] .. [[Reconstruction&#x3a;Latin/verbum|*verba]]</span> <span class="Latn" lang="la">verbum .. [[verbum#Latin|verbum]] .. [[Reconstruction&#x3a;Latin/verbum|*verbum]] .. [[Reconstruction&#x3a;Latin/verbum|verbum]] .. [[Reconstruction&#x3a;Latin/verbum|*verba]]</span>
Passed {{l|sla-pro|*[[serda]]}} <span class="Latinx" lang="sla-pro">*[[Reconstruction&#x3a;Proto-Slavic/serda|serda]]</span> <span class="Latinx" lang="sla-pro">*[[Reconstruction&#x3a;Proto-Slavic/serda|serda]]</span>
Failed {{l|sla-pro|*[[*serda]] .. [[*serda]] .. [[serda]] .. [[*serda|serda]] .. [[*serda|*serda]]}} <span class="Latinx" lang="sla-pro">[[Reconstruction&#x3a;Proto-Slavic/serda|*serda]] .. [[Reconstruction&#x3a;Proto-Slavic/serda|*serda]] .. [[Reconstruction&#x3a;Proto-Slavic/serda|serda]] .. [[Reconstruction&#x3a;Proto-Slavic/serda|serda]] .. [[Reconstruction&#x3a;Proto-Slavic/serda|*serda]]</span> <span class="Latinx" lang="sla-pro">[[Reconstruction&#x3a;Proto-Slavic/*serda|*serda]] .. [[Reconstruction&#x3a;Proto-Slavic/*serda|*serda]] .. [[Reconstruction&#x3a;Proto-Slavic/serda|serda]] .. [[Reconstruction&#x3a;Proto-Slavic/*serda|serda]] .. [[Reconstruction&#x3a;Proto-Slavic/*serda|*serda]]</span>
Passed {{l|sla-pro|*[[dьnь|alt1]] [[serda|alt2]]}} <span class="Latinx" lang="sla-pro">*[[Reconstruction&#x3a;Proto-Slavic/dьnь|alt1]] [[Reconstruction&#x3a;Proto-Slavic/serda|alt2]]</span> <span class="Latinx" lang="sla-pro">*[[Reconstruction&#x3a;Proto-Slavic/dьnь|alt1]] [[Reconstruction&#x3a;Proto-Slavic/serda|alt2]]</span>
Passed {{l|und|[[attested]] .. [[*unattested]] .. [[*unattested|unattested-alt]]}} <span class="Zyyy" lang="und">[[attested|attested]] .. *unattested .. unattested-alt</span>[[Category:Undetermined language links]] <span class="Zyyy" lang="und">[[attested|attested]] .. *unattested .. unattested-alt</span>[[Category:Undetermined language links]]
script detection
Passed {{l|sh|српски}} / {{l|sh|srpski}} <span class="Cyrl" lang="sh">[[српски#Serbo-Croatian|српски]]</span> / <span class="Latn" lang="sh">[[srpski#Serbo-Croatian|srpski]]</span> <span class="Cyrl" lang="sh">[[српски#Serbo-Croatian|српски]]</span> / <span class="Latn" lang="sh">[[srpski#Serbo-Croatian|srpski]]</span>
target page's title
Passed {{l|la|verbō}} <span class="Latn" lang="la">[[verbo#Latin|verbō]]</span> <span class="Latn" lang="la">[[verbo#Latin|verbō]]</span>
gender and number
Passed {{l|la|verbum|g=m}} <span class="Latn" lang="la">[[verbum#Latin|verbum]]</span>&nbsp;<span class="gender"><abbr title="masculine gender">m</abbr></span> <span class="Latn" lang="la">[[verbum#Latin|verbum]]</span>&nbsp;<span class="gender"><abbr title="masculine gender">m</abbr></span>
Passed {{l|la|verbum|g=m|g2=f}} <span class="Latn" lang="la">[[verbum#Latin|verbum]]</span>&nbsp;<span class="gender"><abbr title="masculine gender">m</abbr>, <abbr title="feminine gender">f</abbr></span> <span class="Latn" lang="la">[[verbum#Latin|verbum]]</span>&nbsp;<span class="gender"><abbr title="masculine gender">m</abbr>, <abbr title="feminine gender">f</abbr></span>
Passed {{l|la|verbum|g=m-f-p}} <span class="Latn" lang="la">[[verbum#Latin|verbum]]</span>&nbsp;<span class="gender"><abbr title="masculine gender">m</abbr>&nbsp;<abbr title="feminine gender">f</abbr>&nbsp;<abbr title="plural number">pl</abbr></span> <span class="Latn" lang="la">[[verbum#Latin|verbum]]</span>&nbsp;<span class="gender"><abbr title="masculine gender">m</abbr>&nbsp;<abbr title="feminine gender">f</abbr>&nbsp;<abbr title="plural number">pl</abbr></span>
transliteration
Passed {{l|ar|كلمة|tr=kalima}} <span class="Arab" lang="ar">[[كلمة#Arabic|كلمة]]&rlm;</span> <span class="mention-gloss-paren annotation-paren">(</span><span lang="ar-Latn" class="tr Latn">kalima</span><span class="mention-gloss-paren annotation-paren">)</span> <span class="Arab" lang="ar">[[كلمة#Arabic|كلمة]]&rlm;</span> <span class="mention-gloss-paren annotation-paren">(</span><span lang="ar-Latn" class="tr Latn">kalima</span><span class="mention-gloss-paren annotation-paren">)</span>
Passed {{l|ru|русский}} <span class="Cyrl" lang="ru">[[русский#Russian|русский]]</span> <span class="mention-gloss-paren annotation-paren">(</span><span lang="ru-Latn" class="tr Latn">russkij</span><span class="mention-gloss-paren annotation-paren">)</span> <span class="Cyrl" lang="ru">[[русский#Russian|русский]]</span> <span class="mention-gloss-paren annotation-paren">(</span><span lang="ru-Latn" class="tr Latn">russkij</span><span class="mention-gloss-paren annotation-paren">)</span>
gloss
Passed {{l|ru|русский|gloss=Russian}} <span class="Cyrl" lang="ru">[[русский#Russian|русский]]</span> <span class="mention-gloss-paren annotation-paren">(</span><span lang="ru-Latn" class="tr Latn">russkij</span>, <span class="mention-gloss-double-quote">“</span><span class="mention-gloss">Russian</span><span class="mention-gloss-double-quote">”</span><span class="mention-gloss-paren annotation-paren">)</span> <span class="Cyrl" lang="ru">[[русский#Russian|русский]]</span> <span class="mention-gloss-paren annotation-paren">(</span><span lang="ru-Latn" class="tr Latn">russkij</span>, <span class="mention-gloss-double-quote">“</span><span class="mention-gloss">Russian</span><span class="mention-gloss-double-quote">”</span><span class="mention-gloss-paren annotation-paren">)</span>
Wikipedia link
Passed {{l|en|w:word}} <span class="Latn" lang="en">[[w:word|word]]</span> <span class="Latn" lang="en">[[w:word|word]]</span>
Passed {{l|en|[[w:English language]]}} <span class="Latn" lang="en">[[w:English language|w:English language]]</span> <span class="Latn" lang="en">[[w:English language|w:English language]]</span>
Passed {{l|en|[[wikipedia:English language]]}} <span class="Latn" lang="en">[[wikipedia:English language|wikipedia:English language]]</span> <span class="Latn" lang="en">[[wikipedia:English language|wikipedia:English language]]</span>
test_remove_diacritics:
Text Expected Actual
Passed [ru] ба́бушка бабушка бабушка
Passed [mk] ЃѓЌќ - е́а́́ ЃѓЌќ - еа ЃѓЌќ - еа
Passed [sh] Łł ĆćŃńŹź Ŭŭ - ȁàȃáā ȐȒŔ ѝӣ Łł ĆćŃńŹź Ŭŭ - aaaaa RRR ии Łł ĆćŃńŹź Ŭŭ - aaaaa RRR ии
Passed [grc] ᾱ, ᾱ́, ᾰ̓́ α, ά, ἄ α, ά, ἄ

--[=[
	Unit tests for [[Module:links]]. Click talk page to run tests.
]=]

local p = require('Module:UnitTests')
local m_links = require('Module:links')
local m_util = require('Module:utilities')
local get_lang_by_code = require("Module:languages").getByCode
local find_best_script = require("Module:scripts").findBestScript

local function tag(lang_code, sc_code)
	return function (text)
		return '<span class="' .. sc_code .. '" lang="' .. lang_code .. '">' .. text .. '</span>'
	end
end

local options = { nowiki = true }
function p:check_link(example, expected)
	self:preprocess_equals(example, expected, options)
end

function p:test_links()
	local frame = mw.getCurrentFrame()
	local temp = frame.args.temp or "l"
	local compat = frame.args.compat
	local lang = compat and "lang=" or ""
	
local link_examples = {
	'anchor',
	{
		'{{' .. temp .. '|' .. lang .. 'en|-er#Etymology 2|-er}}',
		'<span class="Latn" lang="en">[[-er#Etymology 2|-er]]</span>'
	},
	{
		'{{' .. temp .. '|' .. lang .. 'en|[[-er#Etymology 2|-er]]}}',
		'<span class="Latn" lang="en">[[-er#Etymology 2|-er]]</span>'
	},
	'numeric character references in link target',
	{
		'{{' .. temp .. '|' .. lang .. 'nia|wa&#39;a}}',
		'<span class="Latn" lang="nia">[[wa\'a#Nias|wa\'a]]</span>'
	},
	{
		'{{' .. temp .. '|' .. lang .. 'ja|恵&#8204;美|恵&amp;#8204;美}}',
		'<span class="Jpan" lang="ja">[[恵‌美#Japanese|恵&amp;#8204;美]]</span>'
	},
	'simple linking', -- ([[Module:languages]])
	{
		'{{' .. temp .. '|' .. lang .. 'la|verbum}}',
		'<span class="Latn" lang="la">[[verbum#Latin|verbum]]</span>'
	},

	'using wikilinks',
	{
		'{{' .. temp .. '|' .. lang .. 'en|[[God]] be [[with]] [[you]]}}',
		'<span class="Latn" lang="en">[[God#English|God]] be [[with#English|with]] [[you#English|you]]</span>'
	},

	'alternative text',
	{
		'{{' .. temp .. '|' .. lang .. 'en|go|went}}',
		'<span class="Latn" lang="en">[[go#English|went]]</span>'
	},
	{
		'{{' .. temp .. '|' .. lang .. 'en|to [[go]]|went}}',
		'<span class="Latn" lang="en">to [[go#English|go]]</span>'
	},

	'sense id',
	{
		'{{' .. temp .. '|' .. lang .. 'en|go|id=game}}',
		'<span class="Latn" lang="en">[[go#English-game|go]]</span>'
	},

	'constructed terms', -- ([[Module:languages]])
	{
		'{{' .. temp .. '|' .. lang .. 'sjn|mithril}}',
		'<span class="Latn" lang="sjn">[[Appendix&#x3a;Sindarin/mithril|mithril]]</span>'
	},

	'reconstructed terms', -- ([[Module:languages]])
	{
		'{{' .. temp .. '|' .. lang .. 'ine-pro|*bʰréh₂tēr}}',
		'<span class="Latinx" lang="ine-pro">[[Reconstruction&#x3a;Proto-Indo-European/bʰréh₂tēr|*bʰréh₂tēr]]</span>'
	},
	{
		'{{#iferror:{{' .. temp .. '|' .. lang .. 'ine-pro|bʰréh₂tēr}}|Script error}}',
		'Script error'

	},
	{
		'{{' .. temp .. '|' .. lang .. 'sla-pro|[[*dьnь]] [[*serda]]}}',
		'<span class="Latinx" lang="sla-pro">[[Reconstruction&#x3a;Proto-Slavic/dьnь|*dьnь]] [[Reconstruction&#x3a;Proto-Slavic/serda|*serda]]</span>'
	},

	{
		'{{' .. temp .. '|' .. lang .. 'la|verbum .. [[verbum]] .. [[*verbum]] .. [[*verbum|verbum]] .. [[*verbum|*verba]]}}',
		'<span class="Latn" lang="la">verbum .. [[verbum#Latin|verbum]] .. [[Reconstruction&#x3a;Latin/verbum|*verbum]] .. [[Reconstruction&#x3a;Latin/verbum|verbum]] .. [[Reconstruction&#x3a;Latin/verbum|*verba]]</span>'
	},
	{
		'{{' .. temp .. '|' .. lang .. 'sla-pro|*[[serda]]}}',
		'<span class="Latinx" lang="sla-pro">*[[Reconstruction&#x3a;Proto-Slavic/serda|serda]]</span>'
	},
	{
		'{{' .. temp .. '|' .. lang .. 'sla-pro|*[[*serda]] .. [[*serda]] .. [[serda]] .. [[*serda|serda]] .. [[*serda|*serda]]}}',
		'<span class="Latinx" lang="sla-pro">[[Reconstruction&#x3a;Proto-Slavic/serda|*serda]] .. [[Reconstruction&#x3a;Proto-Slavic/serda|*serda]] .. [[Reconstruction&#x3a;Proto-Slavic/serda|serda]] .. [[Reconstruction&#x3a;Proto-Slavic/serda|serda]] .. [[Reconstruction&#x3a;Proto-Slavic/serda|*serda]]</span>'
	},
	{
		'{{' .. temp .. '|' .. lang .. 'sla-pro|*[[dьnь|alt1]] [[serda|alt2]]}}',
		'<span class="Latinx" lang="sla-pro">*[[Reconstruction&#x3a;Proto-Slavic/dьnь|alt1]] [[Reconstruction&#x3a;Proto-Slavic/serda|alt2]]</span>'
	},
	{
		'{{' .. temp .. '|' .. lang .. 'und|[[attested]] .. [[*unattested]] .. [[*unattested|unattested-alt]]}}',
		'<span class="Zyyy" lang="und">[[attested|attested]] .. *unattested .. unattested-alt</span>[[Category:Undetermined language links]]'
	},

	'script detection', -- ([[Module:scripts]].findBestScript())
	{
		'{{' .. temp .. '|' .. lang .. 'sh|српски}} / {{' .. temp .. '|' .. lang .. 'sh|srpski}}',
		'<span class="Cyrl" lang="sh">[[српски#Serbo-Croatian|српски]]</span> / <span class="Latn" lang="sh">[[srpski#Serbo-Croatian|srpski]]</span>'
	},

	'target page\'s title', -- (Language:makeEntryName())
	{
		'{{' .. temp .. '|' .. lang .. 'la|verbō}}',
		'<span class="Latn" lang="la">[[verbo#Latin|verbō]]</span>'
	},

	'gender and number', -- ([[Module:gender and number]])
	{
		'{{' .. temp .. '|' .. lang .. 'la|verbum|g=m}}',
		'<span class="Latn" lang="la">[[verbum#Latin|verbum]]</span>&nbsp;<span class="gender"><abbr title="masculine gender">m</abbr></span>'
	},
	{
		'{{' .. temp .. '|' .. lang .. 'la|verbum|g=m|g2=f}}',
		'<span class="Latn" lang="la">[[verbum#Latin|verbum]]</span>&nbsp;<span class="gender"><abbr title="masculine gender">m</abbr>, <abbr title="feminine gender">f</abbr></span>'
	},
	{
		'{{' .. temp .. '|' .. lang .. 'la|verbum|g=m-f-p}}',
		'<span class="Latn" lang="la">[[verbum#Latin|verbum]]</span>&nbsp;<span class="gender"><abbr title="masculine gender">m</abbr>&nbsp;<abbr title="feminine gender">f</abbr>&nbsp;<abbr title="plural number">pl</abbr></span>'
	},

	'transliteration',
	{
		'{{' .. temp .. '|' .. lang .. 'ar|كلمة|tr=kalima}}',
		'<span class="Arab" lang="ar">[[كلمة#Arabic|كلمة]]&rlm;</span> <span class="mention-gloss-paren annotation-paren">(</span><span lang="ar-Latn" class="tr Latn">kalima</span><span class="mention-gloss-paren annotation-paren">)</span>'
	},
	{
		'{{' .. temp .. '|' .. lang .. 'ru|русский}}',
		'<span class="Cyrl" lang="ru">[[русский#Russian|русский]]</span> <span class="mention-gloss-paren annotation-paren">(</span><span lang="ru-Latn" class="tr Latn">russkij</span><span class="mention-gloss-paren annotation-paren">)</span>'
	},

	'gloss',
	{
		'{{' .. temp .. '|' .. lang .. 'ru|русский|gloss=Russian}}',
		'<span class="Cyrl" lang="ru">[[русский#Russian|русский]]</span> <span class="mention-gloss-paren annotation-paren">(</span><span lang="ru-Latn" class="tr Latn">russkij</span>, <span class="mention-gloss-double-quote">“</span><span class="mention-gloss">Russian</span><span class="mention-gloss-double-quote">”</span><span class="mention-gloss-paren annotation-paren">)</span>'
	},

	'Wikipedia link',
	{
		'{{' .. temp .. '|' .. lang .. 'en|w:word}}',
		'<span class="Latn" lang="en">[[w:word|word]]</span>'
	},
	{
		'{{' .. temp .. '|' .. lang .. 'en|[[w:English language]]}}',
		'<span class="Latn" lang="en">[[w:English language|w:English language]]</span>'
	},
	{
		'{{' .. temp .. '|' .. lang .. 'en|[[wikipedia:English language]]}}',
		'<span class="Latn" lang="en">[[wikipedia:English language|wikipedia:English language]]</span>'
	},
}
	
	self:iterate(link_examples, 'check_link')
end

function p:check_make_entry_name(lang_code, unstripped, stripped)
	local lang_obj = get_lang_by_code(lang_code)
	local sc_code = find_best_script(unstripped, lang_obj):getCode()
	self:equals(
		('[%s] <i class="mention %s" lang="%s">%s</i>'):format(lang_code, sc_code, lang_code, unstripped),
		lang_obj:makeEntryName(unstripped),
		stripped,
		{ display = tag(lang_code, sc_code) }
	)
end

function p:test_remove_diacritics()
	-- insert here lines of the form:
	local examples = {
		{ 'ru', 'ба́бушка', 'бабушка' },
		{ 'mk', 'ЃѓЌќ - е́а́́', 'ЃѓЌќ - еа' },  -- [[w:Macedonian alphabet]]
		{ 'sh', 'Łł ĆćŃńŹź Ŭŭ - ȁàȃáā ȐȒŔ ѝӣ', 'Łł ĆćŃńŹź Ŭŭ - aaaaa RRR ии' }, -- [[w:Serbian Cyrillic alphabet]] / [[w:Gaj's Latin alphabet]]
		{ 'grc', 'ᾱ, ᾱ́, ᾰ̓́', 'α, ά, ἄ' },
	}
	self:iterate(examples, 'check_make_entry_name')
end

return p