Modul:grammar-table/test

Definition från Wiktionary, den fria ordlistan.
Hoppa till navigering Hoppa till sök

All tests passed. (refresh)

Text Expected Actual
test01_basic:
Passed mut.getRow({"!", "rubrik", '|rowspan="2"'}, "form1", "form2", "form3") |-

!|rubrik |rowspan="2"|<span class="infl">[[form1]]</span> ||<span class="infl">[[form2]]</span> ||<span class="infl">[[form3]]</span>

|-

!|rubrik |rowspan="2"|<span class="infl">[[form1]]</span> ||<span class="infl">[[form2]]</span> ||<span class="infl">[[form3]]</span>

Passed mut.getRow({"|", "[[form1]], [[form2]]", type="adv"}, "[[form3]], [[form4]]") |-

||<span class="adv">[[form1]]</span>, <span class="adv">[[form2]]</span> ||<span class="infl">[[form3]]</span>, <span class="infl">[[form4]]</span>

|-

||<span class="adv">[[form1]]</span>, <span class="adv">[[form2]]</span> ||<span class="infl">[[form3]]</span>, <span class="infl">[[form4]]</span>

Passed mut.getRow("form1, form2") |-

||<span class="infl">[[form1]]</span>, <span class="infl">[[form2]]</span>

|-

||<span class="infl">[[form1]]</span>, <span class="infl">[[form2]]</span>

Text Expected Actual
test02_only_content:
Passed mut.getRow("form1", "form2", "form3") |-

||<span class="infl">[[form1]]</span> ||<span class="infl">[[form2]]</span> ||<span class="infl">[[form3]]</span>

|-

||<span class="infl">[[form1]]</span> ||<span class="infl">[[form2]]</span> ||<span class="infl">[[form3]]</span>

Text Expected Actual
test03_only_meta:
Passed mut.getRow({"!"}, {"|rowspan=2"}, {'|class="min"'}) |-

!|&nbsp; |rowspan="2"|&nbsp;[[Kategori:Wiktionary:Sidor med tomma celler]] |class="min"|&nbsp;[[Kategori:Wiktionary:Sidor med tomma celler]]

|-

!|&nbsp; |rowspan="2"|&nbsp;[[Kategori:Wiktionary:Sidor med tomma celler]] |class="min"|&nbsp;[[Kategori:Wiktionary:Sidor med tomma celler]]

Text Expected Actual
test04_only_meta_and_type:
Passed mut.getRow({"!", type="no-link"}, {'|rowspan="2"', type="no-link"}) |-

!|&nbsp; |rowspan="2"|&nbsp;[[Kategori:Wiktionary:Sidor med tomma celler]]

|-

!|&nbsp; |rowspan="2"|&nbsp;[[Kategori:Wiktionary:Sidor med tomma celler]]

Text Expected Actual
test05_no_extra_links:
Passed mut.getRow("[[form1]], form2") |-

||<span class="infl">[[form1]]</span>, <span class="infl">[[form2]]</span>

|-

||<span class="infl">[[form1]]</span>, <span class="infl">[[form2]]</span>

Passed mut.getRow("[[form1]]<sup>1</sup>") |-

||<span class="infl">[[form1]]</span><sup>1</sup>

|-

||<span class="infl">[[form1]]</span><sup>1</sup>

Passed mut.getRow("[[form1]], vard. [[form2]]") |-

||<span class="infl">[[form1]]</span>, vard. <span class="infl">[[form2]]</span>

|-

||<span class="infl">[[form1]]</span>, vard. <span class="infl">[[form2]]</span>

Passed mut.getRow("([[form1]])") |-

||'''('''<span class="infl">[[form1]]</span>''')'''

|-

||'''('''<span class="infl">[[form1]]</span>''')'''

Passed mut.getRow("[[form1|fōrm1]]") |-

||<span class="infl">[[form1|fōrm1]]</span>

|-

||<span class="infl">[[form1|fōrm1]]</span>

Passed mut.getRow("<nowiki/>form1, form2")
Med nowiki i modul
|-

||<nowiki/>form1, <span class="infl">[[form2]]</span>

|-

||<nowiki/>form1, <span class="infl">[[form2]]</span>

Passed mut.getRow("<nowiki/>form1, form2")
Med nowiki i mall
|-

||"`UNIQ--nowiki-00000001-QINU`"'form1, <span class="infl">[[form2]]</span>

|-

||"`UNIQ--nowiki-00000001-QINU`"'form1, <span class="infl">[[form2]]</span>

Text Expected Actual
test06_multiple_words:
Passed mut.getRow("ord1 ord2") |-

||ord1 ord2

|-

||ord1 ord2

Text Expected Actual
test07_special_cases:
Passed mut.getRow(nil) |- |-
Passed mut.getRow("") |-

||&nbsp;[[Kategori:Wiktionary:Sidor med tomma celler]]

|-

||&nbsp;[[Kategori:Wiktionary:Sidor med tomma celler]]

Passed mut.getRow("-") |-

||–

|-

||–

Passed mut.getRow("?") |-

||?

|-

||?

Passed ", type="no-link"})) |-

||&nbsp;[[Kategori:Wiktionary:Sidor med tomma celler]]

|-

||&nbsp;[[Kategori:Wiktionary:Sidor med tomma celler]]

Passed ", "", type="no-link"})) |-

||&nbsp;[[Kategori:Wiktionary:Sidor med tomma celler]]

|-

||&nbsp;[[Kategori:Wiktionary:Sidor med tomma celler]]

Passed ", "-", type="no-link"})) |-

||–

|-

||–

Passed ", "?", type="no-link"})) |-

||?

|-

||?

Text Expected Actual
test_08_words_containg_special_chars:
Passed mut.getRow("e-post") |-

||<span class="infl">[[e-post]]</span>

|-

||<span class="infl">[[e-post]]</span>

Passed mut.getRow("word's") |-

||<span class="infl">[[word's]]</span>

|-

||<span class="infl">[[word's]]</span>

Passed mut.getRow("words'") |-

||<span class="infl">[[words']]</span>

|-

||<span class="infl">[[words']]</span>

Passed mut.getRow("tv:n") |-

||<span class="infl">[[tv:n]]</span>

|-

||<span class="infl">[[tv:n]]</span>

Passed mut.getRow("[[Övriga_uppslagsord#EU:s|EU:s]]") |-

||<span class="infl">[[Övriga_uppslagsord#EU:s|EU:s]]</span>

|-

||<span class="infl">[[Övriga_uppslagsord#EU:s|EU:s]]</span>

Passed mut.getRow("''[[Betula]]''") |-

||''<span class="infl">[[Betula]]</span>''

|-

||''<span class="infl">[[Betula]]</span>''

Text Expected Actual
test_09_basic_with_lang_code:
Passed mut.setLanguage("de") (nil) (nil)
Passed mut.getRow({"!", "rubrik", '|rowspan="2"'}, "form1", "form2", "form3") |-

!|rubrik |rowspan="2"|<span class="infl">[[form1#Tyska|form1]]</span> ||<span class="infl">[[form2#Tyska|form2]]</span> ||<span class="infl">[[form3#Tyska|form3]]</span>

|-

!|rubrik |rowspan="2"|<span class="infl">[[form1#Tyska|form1]]</span> ||<span class="infl">[[form2#Tyska|form2]]</span> ||<span class="infl">[[form3#Tyska|form3]]</span>

Passed mut.getRow({"|", "[[form1]], [[form2]]", type="adv"}, "[[form3]], [[form4]]") |-

||<span class="adv">[[form1#Tyska|form1]]</span>, <span class="adv">[[form2#Tyska|form2]]</span> ||<span class="infl">[[form3#Tyska|form3]]</span>, <span class="infl">[[form4#Tyska|form4]]</span>

|-

||<span class="adv">[[form1#Tyska|form1]]</span>, <span class="adv">[[form2#Tyska|form2]]</span> ||<span class="infl">[[form3#Tyska|form3]]</span>, <span class="infl">[[form4#Tyska|form4]]</span>

Passed mut.getRow("form1, form2") |-

||<span class="infl">[[form1#Tyska|form1]]</span>, <span class="infl">[[form2#Tyska|form2]]</span>

|-

||<span class="infl">[[form1#Tyska|form1]]</span>, <span class="infl">[[form2#Tyska|form2]]</span>

local t = require("Modul:UnitTests")
local mut = require("Modul:grammar-table")

local nowiki = function(s)
	return s:gsub('[\r\n][!]', {["\n!"] = "\n !", ["\r!"] = "\r !"})
end

function t:test01_basic()
	self:equals('<nowiki>mut.getRow({"!", "rubrik", \'|rowspan="2"\'}, "form1", "form2", "form3")</nowiki>', nowiki(mut.getRow({"!", "rubrik"}, {'|rowspan="2"', "form1"}, "form2", "form3")), nowiki('|-\n!|rubrik\n|rowspan="2"|<span class="infl">[[form1]]</span>\n||<span class="infl">[[form2]]</span>\n||<span class="infl">[[form3]]</span>\n'), {nowiki=1})
	self:equals('<nowiki>mut.getRow({"|", "[[form1]], [[form2]]", type="adv"}, "[[form3]], [[form4]]")</nowiki>', mut.getRow({"|", "[[form1]], [[form2]]", type="adv"}, "[[form3]], [[form4]]"), '|-\n||<span class="adv">[[form1]]</span>, <span class="adv">[[form2]]</span>\n||<span class="infl">[[form3]]</span>, <span class="infl">[[form4]]</span>\n', {nowiki=1})
	self:equals('<nowiki>mut.getRow("form1, form2")</nowiki>', nowiki(mut.getRow("form1, form2")), nowiki('|-\n||<span class="infl">[[form1]]</span>, <span class="infl">[[form2]]</span>\n'), {nowiki=1})
end

function t:test02_only_content()
	self:equals('mut.getRow("form1", "form2", "form3")', nowiki(mut.getRow("form1", "form2", "form3")), nowiki('|-\n||<span class="infl">[[form1]]</span>\n||<span class="infl">[[form2]]</span>\n||<span class="infl">[[form3]]</span>\n'), {nowiki=1})
end

function t:test03_only_meta()
	self:equals('<nowiki>mut.getRow({"!"}, {"|rowspan=2"}, {\'|class="min"\'})</nowiki>', nowiki(mut.getRow({"!"}, {'|rowspan="2"'}, {'|class="min"'})), nowiki('|-\n!|&nbsp;\n|rowspan="2"|&nbsp;[[Kategori:Wiktionary:Sidor med tomma celler]]\n|class="min"|&nbsp;[[Kategori:Wiktionary:Sidor med tomma celler]]\n'), {nowiki=1})
end

function t:test04_only_meta_and_type()
	self:equals('<nowiki>mut.getRow({"!", type="no-link"}, {\'|rowspan="2"\', type="no-link"})</nowiki>', nowiki(mut.getRow({"!", type="no-link"}, {'|rowspan="2"', type="no-link"})), nowiki('|-\n!|&nbsp;\n|rowspan="2"|&nbsp;[[Kategori:Wiktionary:Sidor med tomma celler]]\n'), {nowiki=1})
end

function t:test05_no_extra_links()
	self:equals('<nowiki>mut.getRow("[[form1]], form2")</nowiki>', nowiki(mut.getRow("[[form1]], form2")), nowiki('|-\n||<span class="infl">[[form1]]</span>, <span class="infl">[[form2]]</span>\n'), {nowiki=1})
	self:equals('<nowiki>mut.getRow("[[form1]]<sup>1</sup>")</nowiki>', nowiki(mut.getRow("[[form1]]<sup>1</sup>")), nowiki('|-\n||<span class="infl">[[form1]]</span><sup>1</sup>\n'), {nowiki=1})
	self:equals('<nowiki>mut.getRow("[[form1]], vard. [[form2]]")</nowiki>', nowiki(mut.getRow("[[form1]], vard. [[form2]]")), nowiki('|-\n||<span class="infl">[[form1]]</span>, vard. <span class="infl">[[form2]]</span>\n'), {nowiki=1})
	self:equals('<nowiki>mut.getRow("([[form1]])")</nowiki>', nowiki(mut.getRow("([[form1]])")), nowiki("|-\n||'''('''<span class=\"infl\">[[form1]]</span>''')'''\n"), {nowiki=1})
	self:equals('<nowiki>mut.getRow("[[form1|fōrm1]]")</nowiki>', nowiki(mut.getRow("[[form1|fōrm1]]")), nowiki('|-\n||<span class="infl">[[form1|fōrm1]]</span>\n'), {nowiki=1})
--	self:equals('<nowiki>mut.getRow("[[form1]]<ref>[[Källa]]</ref>")</nowiki>', nowiki(mut.getRow("[[form1]]<ref>[[Källa]]</ref>")), nowiki('|-\n||<span class="infl">[[form1]]</span><ref>[[Källa]]</ref>\n'), {nowiki=1}) -- inaktiverad tills vi vet hur vi vill ha det
	self:equals([[<nowiki>mut.getRow("<nowiki/>form1, form2")</nowiki><br>''Med nowiki i modul'']], nowiki(mut.getRow("<nowiki/>form1, form2")), nowiki('|-\n||<nowiki/>form1, <span class="infl">[[form2]]</span>\n'), {nowiki=1})
	
	local uniq_nowiki = "\127\"`UNIQ--nowiki-00000001-QINU`\"'\127"
	self:equals([[<nowiki>mut.getRow("<nowiki/>form1, form2")</nowiki><br>''Med nowiki i mall'']], nowiki(mut.getRow(uniq_nowiki .. "form1, form2")), nowiki('|-\n||' .. uniq_nowiki .. 'form1, <span class="infl">[[form2]]</span>\n'), {nowiki=1})
end

function t:test06_multiple_words()
	-- TODO eller ska dom länkas?
	self:equals('<nowiki>mut.getRow("ord1 ord2")</nowiki>', nowiki(mut.getRow("ord1 ord2")), nowiki('|-\n||ord1 ord2\n'), {nowiki=1})
end

function t:test07_special_cases()
	--self:equals('mut.getRow({})', nowiki(mut.getRow({})), nowiki('|-\n||&nbsp;[[Kategori:Wiktionary:Sidor med tomma celler]]\n'), {nowiki=1})
	self:equals('mut.getRow(nil)', nowiki(mut.getRow(nil)), nowiki('|-\n'), {nowiki=1})
	self:equals('mut.getRow("")', nowiki(mut.getRow("")), nowiki('|-\n||&nbsp;[[Kategori:Wiktionary:Sidor med tomma celler]]\n'), {nowiki=1})
	self:equals('mut.getRow("-")', nowiki(mut.getRow("-")), nowiki('|-\n||–\n'), {nowiki=1})
	self:equals('mut.getRow("?")', nowiki(mut.getRow("?")), nowiki('|-\n||?\n'), {nowiki=1})
	self:equals('mut.getRow({"|", type="no-link"}))', nowiki(mut.getRow({"|", type="no-link"})), nowiki('|-\n||&nbsp;[[Kategori:Wiktionary:Sidor med tomma celler]]\n'), {nowiki=1})
	self:equals('mut.getRow({"|", "", type="no-link"}))', nowiki(mut.getRow({"|", "", type="no-link"})), nowiki('|-\n||&nbsp;[[Kategori:Wiktionary:Sidor med tomma celler]]\n'), {nowiki=1})
	self:equals('mut.getRow({"|", "-", type="no-link"}))', nowiki(mut.getRow({"|", "-", type="no-link"})), nowiki('|-\n||–\n'), {nowiki=1})
	self:equals('mut.getRow({"|", "?", type="no-link"}))', nowiki(mut.getRow({"|", "?", type="no-link"})), nowiki('|-\n||?\n'), {nowiki=1})
end

function t:test_08_words_containg_special_chars()
	self:equals('mut.getRow("e-post")', nowiki(mut.getRow("e-post")), nowiki('|-\n||<span class="infl">[[e-post]]</span>\n'), {nowiki=1})
	self:equals('mut.getRow("word\'s")', nowiki(mut.getRow("word's")), nowiki('|-\n||<span class="infl">[[word\'s]]</span>\n'), {nowiki=1})
	self:equals('mut.getRow("words\'")', nowiki(mut.getRow("words'")), nowiki('|-\n||<span class="infl">[[words\']]</span>\n'), {nowiki=1})
	self:equals('mut.getRow("tv:n")', nowiki(mut.getRow("tv:n")), nowiki('|-\n||<span class="infl">[[tv:n]]</span>\n'), {nowiki=1})
	self:equals('<nowiki>mut.getRow("[[Övriga_uppslagsord#EU:s|EU:s]]</nowiki>")', nowiki(mut.getRow("[[Övriga_uppslagsord#EU:s|EU:s]]")), nowiki('|-\n||<span class="infl">[[Övriga_uppslagsord#EU:s|EU:s]]</span>\n'), {nowiki=1})
	self:equals('<nowiki>mut.getRow("\'\'[[Betula]]\'\'</nowiki>")', nowiki(mut.getRow("''[[Betula]]''")), nowiki('|-\n||\'\'<span class="infl">[[Betula]]</span>\'\'\n'), {nowiki=1})
end

function t:test_09_basic_with_lang_code()
	self:equals('mut.setLanguage("de")', mut.setLanguage("de"), nil, {nowiki=1})
	self:equals('<nowiki>mut.getRow({"!", "rubrik", \'|rowspan="2"\'}, "form1", "form2", "form3")</nowiki>', nowiki(mut.getRow({"!", "rubrik"}, {'|rowspan="2"', "form1"}, "form2", "form3")), nowiki('|-\n!|rubrik\n|rowspan="2"|<span class="infl">[[form1#Tyska|form1]]</span>\n||<span class="infl">[[form2#Tyska|form2]]</span>\n||<span class="infl">[[form3#Tyska|form3]]</span>\n'), {nowiki=1})
	self:equals('<nowiki>mut.getRow({"|", "[[form1]], [[form2]]", type="adv"}, "[[form3]], [[form4]]")</nowiki>', mut.getRow({"|", "[[form1]], [[form2]]", type="adv"}, "[[form3]], [[form4]]"), '|-\n||<span class="adv">[[form1#Tyska|form1]]</span>, <span class="adv">[[form2#Tyska|form2]]</span>\n||<span class="infl">[[form3#Tyska|form3]]</span>, <span class="infl">[[form4#Tyska|form4]]</span>\n', {nowiki=1})
	self:equals('<nowiki>mut.getRow("form1, form2")</nowiki>', nowiki(mut.getRow("form1, form2")), nowiki('|-\n||<span class="infl">[[form1#Tyska|form1]]</span>, <span class="infl">[[form2#Tyska|form2]]</span>\n'), {nowiki=1})
end

return t