local t = require("Modul:UnitTests")
local lk = require("Modul:link")
local mut = require("Modul:grammar-link")
local nowiki = function(s)
return s:gsub('', { = "\n !", = "\r !"})
end
function t:test01a_basic()
self:equals('mut.link("form1", "infl")', mut.link("form1", "infl"), '<span data-grammar-link="infl">' .. lk.link("form1") .. '</span>', {nowiki=1})
self:equals('mut.link(" form1 ", "infl")', mut.link(" form1 ", "infl"), '<span data-grammar-link="infl">' .. lk.link("form1") .. '</span>', {nowiki=1})
self:equals('mut.link("form1", "infl", "sv")', mut.link("form1", "infl", "sv"), '<span data-grammar-link="infl">' .. lk.link("form1", "sv") .. '</span>', {nowiki=1})
self:equals('mut.link("form1", "infl", "sv", "verb)', mut.link("form1", "infl", "sv", "verb"), '<span class="grammar-inline" data-lang="sv" data-h3="verb"><span data-grammar-link="infl">' .. lk.link("form1", "sv") .. '</span></span>', {nowiki=1})
self:equals('mut.link("form1", "adv")', mut.link("form1", "adv"), '<span data-grammar-link="adv">' .. lk.link("form1") .. '</span>', {nowiki=1})
self:equals('mut.link("form1", "adv", "de")', mut.link("form1", "adv", "de"), '<span data-grammar-link="adv">' .. lk.link("form1", "de") .. '</span>', {nowiki=1})
self:equals('mut.link("form1", "adv", "de", "verb)', mut.link("form1", "adv", "de", "verb"), '<span class="grammar-inline" data-lang="de" data-h3="verb"><span data-grammar-link="adv">' .. lk.link("form1", "de") .. '</span></span>', {nowiki=1})
self:equals('mut.link("form1", "perfpart")', mut.link("form1", "perfpart"), '<span data-grammar-link="perfpart">' .. lk.link("form1") .. '</span>', {nowiki=1})
self:equals('mut.link("form1", "perfpart", "en")', mut.link("form1", "perfpart", "en"), '<span data-grammar-link="perfpart">' .. lk.link("form1", "en") .. '</span>', {nowiki=1})
self:equals('mut.link("form1", "perfpart", "en", "verb)', mut.link("form1", "perfpart", "en", "verb"), '<span class="grammar-inline" data-lang="en" data-h3="verb"><span data-grammar-link="perfpart">' .. lk.link("form1", "en") .. '</span></span>', {nowiki=1})
end
function t:test01b_basic_export()
self:equals_deep('mut.linkExport("form1", "infl")', mut.linkExport("form1", "infl"), {"form1"}, {nowiki=1})
self:equals_deep('mut.linkExport("form1", "adv")', mut.linkExport("form1", "adv"), {"form1"}, {nowiki=1})
self:equals_deep('mut.linkExport("form1", "perfpart")', mut.linkExport("form1", "perfpart"), {"form1"}, {nowiki=1})
self:equals_deep('mut.linkExport(" form1 ", "infl")', mut.linkExport(" form1 ", "infl"), {"form1"}, {nowiki=1})
end
function t:test02a_multiple()
self:equals('mut.link("form1, form2", "infl")', mut.link("form1, form2", "infl"), '<span data-grammar-link="infl">' .. lk.link("form1") .. '</span>, <span data-grammar-link="infl">' .. lk.link("form2") .. '</span>', {nowiki=1})
self:equals('mut.link("form1, form2", "infl", "sv")', mut.link("form1, form2", "infl", "sv"), '<span data-grammar-link="infl">' .. lk.link("form1", "sv") .. '</span>, <span data-grammar-link="infl">' .. lk.link("form2", "sv") .. '</span>', {nowiki=1})
self:equals('mut.link("form1, form2", "infl", "sv", "verb)', mut.link("form1, form2", "infl", "sv", "verb"), '<span class="grammar-inline" data-lang="sv" data-h3="verb"><span data-grammar-link="infl">' .. lk.link("form1", "sv") .. '</span>, <span data-grammar-link="infl">' .. lk.link("form2", "sv") .. '</span></span>', {nowiki=1})
self:equals('<nowiki>mut.link("], ]", "infl"</nowiki>)', mut.link("], ]", "infl"), '<span data-grammar-link="infl">' .. lk.link("]") .. '</span>, <span data-grammar-link="infl">' .. lk.link("]") .. '</span>', {nowiki=1})
self:equals('<nowiki>mut.link("], ]", "infl", "sv"</nowiki>)', mut.link("], ]", "infl", "sv"), '<span data-grammar-link="infl">' .. lk.link("]", "sv") .. '</span>, <span data-grammar-link="infl">' .. lk.link("]", "sv") .. '</span>', {nowiki=1})
self:equals('<nowiki>mut.link("], ]", "infl", "sv", "verb"</nowiki>)', mut.link("], ]", "infl", "sv", "verb"), '<span class="grammar-inline" data-lang="sv" data-h3="verb"><span data-grammar-link="infl">' .. lk.link("]", "sv") .. '</span>, <span data-grammar-link="infl">' .. lk.link("]", "sv") .. '</span></span>', {nowiki=1})
self:equals('<nowiki>mut.link("], form2", "infl"</nowiki>)', mut.link("], form2", "infl"), '<span data-grammar-link="infl">' .. lk.link("]") .. '</span>, <span data-grammar-link="infl">' .. lk.link("form2") .. '</span>', {nowiki=1})
self:equals('<nowiki>mut.link("], form2", "infl", "sv"</nowiki>)', mut.link("], form2", "infl", "sv"), '<span data-grammar-link="infl">' .. lk.link("]", "sv") .. '</span>, <span data-grammar-link="infl">' .. lk.link("form2", "sv") .. '</span>', {nowiki=1})
self:equals('<nowiki>mut.link("], form2", "infl", "sv", "verb"</nowiki>)', mut.link("], form2", "infl", "sv", "verb"), '<span class="grammar-inline" data-lang="sv" data-h3="verb"><span data-grammar-link="infl">' .. lk.link("]", "sv") .. '</span>, <span data-grammar-link="infl">' .. lk.link("form2", "sv") .. '</span></span>', {nowiki=1})
self:equals('<nowiki>mut.link("form1, ]", "infl"</nowiki>)', mut.link("form1, ]", "infl"), '<span data-grammar-link="infl">' .. lk.link("form1") .. '</span>, <span data-grammar-link="infl">' .. lk.link("]") .. '</span>', {nowiki=1})
self:equals('<nowiki>mut.link("form1, ]", "infl", "sv"</nowiki>)', mut.link("form1, ]", "infl", "sv"), '<span data-grammar-link="infl">' .. lk.link("form1", "sv") .. '</span>, <span data-grammar-link="infl">' .. lk.link("]", "sv") .. '</span>', {nowiki=1})
self:equals('<nowiki>mut.link("form1, ]", "infl", "sv", "verb"</nowiki>)', mut.link("form1, ]", "infl", "sv", "verb"), '<span class="grammar-inline" data-lang="sv" data-h3="verb"><span data-grammar-link="infl">' .. lk.link("form1", "sv") .. '</span>, <span data-grammar-link="infl">' .. lk.link("]", "sv") .. '</span></span>', {nowiki=1})
end
function t:test02b_multiple_export()
self:equals_deep('mut.linkExport("form1, form2", "infl")', mut.linkExport("form1, form2", "infl"), {"form1", "form2"}, {nowiki=1})
self:equals_deep('<nowiki>mut.linkExport("], ]", "infl"</nowiki>)', mut.linkExport("], ]", "infl"), {"form1", "form2"}, {nowiki=1})
self:equals_deep('<nowiki>mut.linkExport("], form2", "infl"</nowiki>)', mut.linkExport("], form2", "infl"), {"form1", "form2"}, {nowiki=1})
self:equals_deep('<nowiki>mut.linkExport("form1, ]", "infl"</nowiki>)', mut.linkExport("form1, ]", "infl"), {"form1", "form2"}, {nowiki=1})
end
function t:test03a_misc()
self:equals('<nowiki>mut.link("]<sup>1</sup>")</nowiki>', mut.link("]<sup>1</sup>", "infl"), '<span data-grammar-link="infl">' .. lk.link("]") .. '</span><sup>1</sup>', {nowiki=1})
self:equals('<nowiki>mut.link("], vard. ]")</nowiki>', mut.link("], vard. ]", "infl"), '<span data-grammar-link="infl">' .. lk.link("]") .. '</span>, vard. <span data-grammar-link="infl">' .. lk.link("]") .. '</span>', {nowiki=1})
self:equals('<nowiki>mut.link("(])")</nowiki>', mut.link("(])", "infl"), =] .. lk.link("]") .. =], {nowiki=1})
self:equals('<nowiki>mut.link("]")</nowiki>', mut.link("]", "infl"), '<span data-grammar-link="infl">' .. lk.link("]") .. '</span>', {nowiki=1})
self:equals('<nowiki>mut.link("]")</nowiki>', mut.link("]", "infl"), '<span data-grammar-link="infl">' .. lk.link("]") .. '</span>', {nowiki=1})
--self:equals('<nowiki>mut.link("]<ref>]</ref>")</nowiki>', mut.link("]<ref>]</ref>", "infl"), '<span data-grammar-link="infl">' .. lk.link("]") .. '</span><ref>]</ref>', {nowiki=1}) -- inaktiverad tills vi vet hur vi vill ha det
self:equals(], mut.link("<nowiki/>form1, form2", "infl"), '<nowiki/>form1, <span data-grammar-link="infl">' .. lk.link("]") .. '</span>', {nowiki=1})
local uniq_nowiki = "\127\"`UNIQ--nowiki-00000001-QINU`\"'\127"
self:equals(], mut.link(uniq_nowiki .. "form1, form2", "infl"), uniq_nowiki .. 'form1, <span data-grammar-link="infl">' .. lk.link("]") .. '</span>', {nowiki=1})
end
function t:test03b_misc_export()
self:equals_deep('<nowiki>mut.linkExport("]<sup>1</sup>")</nowiki>', mut.linkExport("]<sup>1</sup>", "infl"), {"form1"}, {nowiki=1})
self:equals_deep('<nowiki>mut.linkExport("], vard. ]")</nowiki>', mut.linkExport("], vard. ]", "infl"), {"form1", "form2"}, {nowiki=1})
self:equals_deep('<nowiki>mut.linkExport("(])")</nowiki>', mut.linkExport("(])", "infl"), {"(form1)"}, {nowiki=1})
self:equals_deep('<nowiki>mut.linkExport("]")</nowiki>', mut.linkExport("]", "infl"), {"fōrm1"}, {nowiki=1})
self:equals_deep('<nowiki>mut.linkExport("]")</nowiki>', mut.linkExport("]", "infl"), {"EU:s"}, {nowiki=1})
self:equals_deep(], mut.linkExport("<nowiki/>form1, form2", "infl"), {"form2"}, {nowiki=1})
local uniq_nowiki = "\127\"`UNIQ--nowiki-00000001-QINU`\"'\127"
self:equals_deep(], mut.linkExport(uniq_nowiki .. "form1, form2", "infl"), {"form2"}, {nowiki=1})
end
function t:test04a_do_not_link()
self:equals('mut.link("ord1 ord2", "infl")', mut.link("ord1 ord2", "infl"), "ord1 ord2", {nowiki=1})
self:equals('mut.link("noform", "no-link")', mut.link("noform", "no-link"), "noform", {nowiki=1})
end
function t:test04b_do_not_link_export()
self:equals_deep('mut.linkExport("ord1 ord2", "infl")', mut.linkExport("ord1 ord2", "infl"), {"ord1 ord2"}, {nowiki=1})
self:equals_deep('mut.linkExport("noform", "no-link")', mut.linkExport("noform", "no-link"), {}, {nowiki=1})
end
function t:test05a_link_but_no_tag()
self:equals('<nowiki>mut.link("noform1", "link-only")</nowiki>', mut.link("noform1", "link-only"), lk.link("noform1"), {nowiki=1})
self:equals('<nowiki>mut.link("noform1, noform2", "link-only")</nowiki>', mut.link("noform1, noform2", "link-only"), lk.link("noform1, noform2"), {nowiki=1})
self:equals('<nowiki>mut.link("], noform2", "link-only")</nowiki>', mut.link("], noform2", "link-only"), lk.link("], noform2"), {nowiki=1})
end
function t:test05b_link_but_no_tag_export()
self:equals_deep('<nowiki>mut.linkExport("noform1", "link-only")</nowiki>', mut.linkExport("noform1", "link-only"), {}, {nowiki=1})
self:equals_deep('<nowiki>mut.linkExport("noform1, noform2", "link-only")</nowiki>', mut.linkExport("noform1, noform2", "link-only"), {}, {nowiki=1})
self:equals_deep('<nowiki>mut.linkExport("], noform2", "link-only")</nowiki>', mut.linkExport("], noform2", "link-only"), {}, {nowiki=1})
end
function t:test06a_special_cases()
self:equals('mut.link("", "infl")', mut.link("", "infl"), " ", {nowiki=1})
self:equals('mut.link("", "no-link")', mut.link("", "no-link"), " ", {nowiki=1})
self:equals('mut.link("", "link-only")', mut.link("", "link-only"), " ", {nowiki=1})
self:equals('mut.link("-", "infl")', mut.link("-", "infl"), "–", {nowiki=1})
self:equals('mut.link("-", "no-link")', mut.link("-", "no-link"), "–", {nowiki=1})
self:equals('mut.link("-", "link-only")', mut.link("-", "link-only"), "–", {nowiki=1})
self:equals('mut.link("?", "infl")', mut.link("?", "infl"), "?", {nowiki=1})
self:equals('mut.link("?", "no-link")', mut.link("?", "no-link"), "?", {nowiki=1})
self:equals('mut.link("?", "link-only")', mut.link("?", "link-only"), "?", {nowiki=1})
end
function t:test06b_special_cases_export()
self:equals_deep('mut.linkExport("", "infl")', mut.linkExport("", "infl"), {}, {nowiki=1})
self:equals_deep('mut.linkExport("", "no-link")', mut.linkExport("", "no-link"), {}, {nowiki=1})
self:equals_deep('mut.linkExport("", "link-only")', mut.linkExport("", "link-only"), {}, {nowiki=1})
self:equals_deep('mut.linkExport("-", "infl")', mut.linkExport("-", "infl"), {}, {nowiki=1})
self:equals_deep('mut.linkExport("-", "no-link")', mut.linkExport("-", "no-link"), {}, {nowiki=1})
self:equals_deep('mut.linkExport("-", "link-only")', mut.linkExport("-", "link-only"), {}, {nowiki=1})
self:equals_deep('mut.linkExport("?", "infl")', mut.linkExport("?", "infl"), {}, {nowiki=1})
self:equals_deep('mut.linkExport("?", "no-link")', mut.linkExport("?", "no-link"), {}, {nowiki=1})
self:equals_deep('mut.linkExport("?", "link-only")', mut.linkExport("?", "link-only"), {}, {nowiki=1})
end
function t:test_07a_maybe_slightly()
self:equals('mut.link("(form1)", "infl")', mut.link("(form1)", "infl"), "'''('''" .. mut.link("form1", "infl") .. "''')'''", {nowiki=1})
self:equals('mut.link("form1?", "infl")', mut.link("form1?", "infl"), "'''('''form1''')?'''", {nowiki=1})
self:equals('mut.link(" form1? ", "infl")', mut.link(" form1? ", "infl"), "'''('''form1''')?'''", {nowiki=1})
self:equals('mut.link("(form1), form2", "infl")', mut.link("(form1), form2", "infl"), "'''('''" .. mut.link("form1", "infl") .. "''')''', " .. mut.link("form2", "infl"), {nowiki=1})
self:equals('mut.link("form1?, form2", "infl")', mut.link("form1?, form2", "infl"), "'''('''form1''')?''', " .. mut.link("form2", "infl"), {nowiki=1})
self:equals('<nowiki>mut.link("(form1), ]", "infl")</nowiki>', mut.link("(form1), ]", "infl"), "'''('''" .. mut.link("form1", "infl") .. "''')''', " .. mut.link("form2", "infl"), {nowiki=1})
self:equals('<nowiki>mut.link("form1?, ]", "infl")</nowiki>', mut.link("form1?, ]", "infl"), "'''('''form1''')?''', " .. mut.link("form2", "infl"), {nowiki=1})
end
function t:test_07b_maybe_slightly_export()
self:equals_deep('mut.linkExport("(form1)", "infl")', mut.linkExport("(form1)", "infl"), {"(form1)"}, {nowiki=1})
self:equals_deep('mut.linkExport("form1?", "infl")', mut.linkExport("form1?", "infl"), {"form1?"}, {nowiki=1})
self:equals_deep('mut.linkExport(" form1? ", "infl")', mut.linkExport(" form1? ", "infl"), {"form1?"}, {nowiki=1})
self:equals_deep('mut.linkExport("(form1), form2", "infl")', mut.linkExport("(form1), form2", "infl"), {"(form1)", "form2"}, {nowiki=1})
self:equals_deep('mut.linkExport("form1?, form2", "infl")', mut.linkExport("form1?, form2", "infl"), {"form1?", "form2"}, {nowiki=1})
self:equals_deep('<nowiki>mut.linkExport("(form1), ]", "infl")</nowiki>', mut.linkExport("(form1), ]", "infl"), {"(form1)", "form2"}, {nowiki=1})
self:equals_deep('<nowiki>mut.linkExport("form1?, ]", "infl")</nowiki>', mut.linkExport("form1?, ]", "infl"), {"form1?", "form2"}, {nowiki=1})
end
function t:test_08_do_not_add_anchor_if_pagename_equals_inflection()
self:equals('mut.link("<nowiki>' .. mw.title.getCurrentTitle().text .. '", "infl", "en", "verb</nowiki>")', mut.link(mw.title.getCurrentTitle().text, "infl", "en", "verb"), '<span class="grammar-inline" data-lang="en" data-h3="verb"><span data-grammar-link="infl">]</span></span>', {nowiki=1})
self:equals('mut.link("<nowiki>]", "infl", "en", "verb</nowiki>")', mut.link(mw.title.getCurrentTitle().text, "infl", "en", "verb"), '<span class="grammar-inline" data-lang="en" data-h3="verb"><span data-grammar-link="infl">]</span></span>', {nowiki=1})
self:equals('mut.link("<nowiki>], ]", "infl", "en", "verb</nowiki>")', mut.link(mw.title.getCurrentTitle().text, "infl", "en", "verb"), '<span class="grammar-inline" data-lang="en" data-h3="verb"><span data-grammar-link="infl">]</span></span>', {nowiki=1})
end
return t