Module:links/testcases

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

11 tests failed. (refresh)

test_links:
Text Expected Actual
Passed {{l|la|verbum}} <span class="Latn" lang="la">[[verbum#Latin|verbum]]</span> <span class="Latn" lang="la">[[verbum#Latin|verbum]]</span>
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>
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>
Failed {{l|sjn|mithril}} <span class="Latn" lang="sjn">[[Appendix:Sindarin/mithril|mithril]]</span> <span class="Latn" lang="sjn">[[Appendix&#x3a;Sindarin/mithril|mithril]]</span>
Failed {{l|ine-pro|*bʰréh₂tēr}} <span class="Latinx" lang="ine-pro">[[Appendix: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
Failed {{l|sla-pro|[[*dьnь]] [[*serda]]}} <span class="Latinx" lang="sla-pro">[[Appendix:Proto-Slavic/dьnь|*dьnь]] [[Appendix: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>
Failed {{l|la|verbum .. [[verbum]] .. [[*verbum]] .. [[*verbum|verbum]] .. [[*verbum|*verba]]}} <span class="Latn" lang="la">verbum .. [[verbum#Latin|verbum]] .. [[Appendix:Latin/verbum|*verbum]] .. [[Appendix:Latin/verbum|verbum]] .. [[Appendix: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>
Failed {{l|sla-pro|*[[serda]]}} <span class="Latinx" lang="sla-pro">*[[Appendix: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">[[Appendix:Proto-Slavic/serda|*serda]] .. [[Appendix:Proto-Slavic/serda|*serda]] .. [[Appendix:Proto-Slavic/serda|serda]] .. [[Appendix:Proto-Slavic/serda|serda]] .. [[Appendix: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>
Failed {{l|sla-pro|*[[dьnь|alt1]] [[serda|alt2]]}} <span class="Latinx" lang="sla-pro">*[[Appendix:Proto-Slavic/dьnь|alt1]] [[Appendix: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>
Failed {{l|und|[[attested]] .. [[*unattested]] .. [[*unattested|unattested-alt]]}} <span class="None" lang="und">[[attested|attested]] .. *unattested .. unattested-alt</span> <span class="None" lang="und">[[attested|attested]] .. *unattested .. unattested-alt</span>[[Category:Undetermined language links]]
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>
Passed {{l|la|verbō}} <span class="Latn" lang="la">[[verbo#Latin|verbō]]</span> <span class="Latn" lang="la">[[verbo#Latin|verbō]]</span>
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>
Failed {{l|ar|كلمة|tr=kalima}} <span class="Arab" lang="ar">[[كلمة#Arabic|كلمة]]</span> (<span lang="" class="tr">kalima</span>) <span class="Arab" lang="ar">[[كلمة#Arabic|كلمة]]</span> &lrm;<span class='mention-gloss-paren'>(</span><span lang="" class="tr">kalima</span><span class='mention-gloss-paren'>)</span>
Failed {{l|ru|русский}} <span class="Cyrl" lang="ru">[[русский#Russian|русский]]</span> (<span lang="" class="tr">russkij</span>) <span class="Cyrl" lang="ru">[[русский#Russian|русский]]</span> &lrm;<span class='mention-gloss-paren'>(</span><span lang="" class="tr">russkij</span><span class='mention-gloss-paren'>)</span>
Failed {{l|ru|русский|gloss=Russian}} <span class="Cyrl" lang="ru">[[русский#Russian|русский]]</span> (<span lang="" class="tr">russkij</span>, <span class="mention-gloss-double-quote">“</span><span class="mention-gloss">Russian</span><span class="mention-gloss-double-quote">”</span>) <span class="Cyrl" lang="ru">[[русский#Russian|русский]]</span> &lrm;<span class='mention-gloss-paren'>(</span><span lang="" class="tr">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'>)</span>
test_remove_diacritics:
Text Expected Actual
Passed [ru] ба́бушка бабушка бабушка
Passed [mk] ЃѓЌќ - е́а́́ ЃѓЌќ - еа ЃѓЌќ - еа
Passed [sh] Łł ĆćŃńŹź Ŭŭ - ȁàȃáā ȐȒŔ ѝӣ Łł ĆćŃńŹź Ŭŭ - aaaaa RRR ии Łł ĆćŃńŹź Ŭŭ - aaaaa RRR ии

--[=[
    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')

function p:test_links()
    p.temp = mw.getCurrentFrame().args.temp or "l"
    local compat = mw.getCurrentFrame().args.compat
    lang = compat and "lang=" or ""

    -- simple linking ([[Module:languages]])
    self:preprocess_equals('{{' .. p.temp .. '|' .. lang .. 'la|verbum}}',
                           '<span class="Latn" lang="la">[[verbum#Latin|verbum]]</span>')

    -- using wikilinks
    self:preprocess_equals('{{' .. p.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
    self:preprocess_equals('{{' .. p.temp .. '|' .. lang .. 'en|go|went}}',
                           '<span class="Latn" lang="en">[[go#English|went]]</span>')
    self:preprocess_equals('{{' .. p.temp .. '|' .. lang .. 'en|to [[go]]|went}}',
                           '<span class="Latn" lang="en">to [[go#English|go]]</span>')

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

    -- reconstructed terms ([[Module:languages]])
    self:preprocess_equals('{{' .. p.temp .. '|' .. lang .. 'ine-pro|*bʰréh₂tēr}}',
                           '<span class="Latinx" lang="ine-pro">[[Appendix:Proto-Indo-European/bʰréh₂tēr|*bʰréh₂tēr]]</span>')
    self:preprocess_equals('{{#iferror:{{' .. p.temp .. '|' .. lang .. 'ine-pro|bʰréh₂tēr}}|Script error}}',
                           'Script error')
    self:preprocess_equals('{{' .. p.temp .. '|' .. lang .. 'sla-pro|[[*dьnь]] [[*serda]]}}',
                           '<span class="Latinx" lang="sla-pro">[[Appendix:Proto-Slavic/dьnь|*dьnь]] [[Appendix:Proto-Slavic/serda|*serda]]</span>')

    self:preprocess_equals('{{' .. p.temp .. '|' .. lang .. 'la|verbum .. [[verbum]] .. [[*verbum]] .. [[*verbum|verbum]] .. [[*verbum|*verba]]}}',
                           '<span class="Latn" lang="la">verbum .. [[verbum#Latin|verbum]] .. [[Appendix:Latin/verbum|*verbum]] .. [[Appendix:Latin/verbum|verbum]] .. [[Appendix:Latin/verbum|*verba]]</span>')
    self:preprocess_equals('{{' .. p.temp .. '|' .. lang .. 'sla-pro|*[[serda]]}}',
                           '<span class="Latinx" lang="sla-pro">*[[Appendix:Proto-Slavic/serda|serda]]</span>')
    self:preprocess_equals('{{' .. p.temp .. '|' .. lang .. 'sla-pro|*[[*serda]] .. [[*serda]] .. [[serda]] .. [[*serda|serda]] .. [[*serda|*serda]]}}',
                           '<span class="Latinx" lang="sla-pro">[[Appendix:Proto-Slavic/serda|*serda]] .. [[Appendix:Proto-Slavic/serda|*serda]] .. [[Appendix:Proto-Slavic/serda|serda]] .. [[Appendix:Proto-Slavic/serda|serda]] .. [[Appendix:Proto-Slavic/serda|*serda]]</span>')
    self:preprocess_equals('{{' .. p.temp .. '|' .. lang .. 'sla-pro|*[[dьnь|alt1]] [[serda|alt2]]}}',
                           '<span class="Latinx" lang="sla-pro">*[[Appendix:Proto-Slavic/dьnь|alt1]] [[Appendix:Proto-Slavic/serda|alt2]]</span>')
    self:preprocess_equals('{{' .. p.temp .. '|' .. lang .. 'und|[[attested]] .. [[*unattested]] .. [[*unattested|unattested-alt]]}}',
                           '<span class="None" lang="und">[[attested|attested]] .. *unattested .. unattested-alt</span>')

    -- script detection ([[Module:utilities]].detect_script())
    self:preprocess_equals('{{' .. p.temp .. '|' .. lang .. 'sh|српски}} / {{' .. p.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 (prepare_title())
    self:preprocess_equals('{{' .. p.temp .. '|' .. lang .. 'la|verbō}}',
                           '<span class="Latn" lang="la">[[verbo#Latin|verbō]]</span>')

    -- gender and number ([[Module:gender and number]])
    self:preprocess_equals('{{' .. p.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>')
    self:preprocess_equals('{{' .. p.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>')
    self:preprocess_equals('{{' .. p.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
    self:preprocess_equals('{{' .. p.temp .. '|' .. lang .. 'ar|كلمة|tr=kalima}}',
                           '<span class="Arab" lang="ar">[[كلمة#Arabic|كلمة]]</span> (<span lang="" class="tr">kalima</span>)')
    self:preprocess_equals('{{' .. p.temp .. '|' .. lang .. 'ru|русский}}',
                           '<span class="Cyrl" lang="ru">[[русский#Russian|русский]]</span> (<span lang="" class="tr">russkij</span>)')

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

end

function p:check_remove_diacr(lang, unstripped, stripped)
	self:equals(
		('[%s] <i class="mention %s" lang="%s">%s</i>'):format(lang:getCode(), require("Module:scripts").findBestScript(unstripped, lang):getCode(), lang:getCode(), unstripped),
		lang:makeEntryName(unstripped),
		stripped
	)	
end

function p:test_remove_diacritics()
	local m_languages = require("Module:languages")
	-- insert here lines of the form:
	self:check_remove_diacr(m_languages.getByCode("ru"), 'ба́бушка', 'бабушка')
	self:check_remove_diacr(m_languages.getByCode("mk"), 'ЃѓЌќ - е́а́́', 'ЃѓЌќ - еа')  -- [[w:Macedonian alphabet]]
	self:check_remove_diacr(m_languages.getByCode("sh"), 'Łł ĆćŃńŹź Ŭŭ - ȁàȃáā ȐȒŔ ѝӣ', 'Łł ĆćŃńŹź Ŭŭ - aaaaa RRR ии') -- [[w:Serbian Cyrillic alphabet]] / [[w:Gaj's Latin alphabet]]
end

return p