Module:ApplyLinkAnnotations/testcases

-- Unit tests for Module:. Click talk page to run tests. local p = require('Module:UnitTests') local m = require('Module:ApplyLinkAnnotations') local s = require('Module:ApplyLinkAnnotations/sandbox')

local t_caveat = {} t_caveat["SEE DOCS: html comments"] = { "", "" } t_caveat["SEE DOCS: link extensions"] = { "*Flowery", "*Flowery" } t_caveat["SEE DOCS: single letter article titles"] = { "*T", "*T" }

local t_match = {} t_match["deep indent with asterisks"] = { "** Wikitext", "** " } t_match["std list item link"] = { "*hello", "* " } t_match["pipe list item"] = { "*hey", "* " } t_match["escaped spaces"] = { "*Afternoon_delight", "* " } t_match["section links"] = { "*Clowns", "* " } t_match["indented list item"] = { ":*related", ":* " } t_match["very indented item"] = { "::::*tangential", "::::* " } t_match["piped, indented item"] = { ":*renamed", ":* " } t_match["accented"] = { "*El Niño", "* " } t_match["extra spaces"] = { "*  Dark Matter", "* " }

local t_avoid = {} t_avoid["manual annotation"] = "*hello - an English greeting" t_avoid["non-listed link"] = "Mexico" t_avoid["indented but non-listed"] = ":Cancun" t_avoid["link at end"] = "*Alternative theories include Nonsense" t_avoid["ordered list"] = "#hello" t_avoid["already annotated"] = "* " t_avoid["section headings"] = "== Section heading ==" t_avoid["stylized links"] = "*Emphasized link" t_avoid["non-article namespace"] = "*" t_avoid["pipe trick"] = "*hello (greeting)" t_avoid["reverse pipe trick"] = "*|Moscow, Russia"

function p:test_lines_to_match -- Various lines that should match for name, case in pairs(t_match) do		self:equals(''..name..' '..case[1]..' ',m._testline(case[1]),case[2],{nowiki=1}) self:equals(''..name..' (Sandbox) '..case[1]..' ',s._testline(case[1]),case[2],{nowiki=1}) end end

function p:test_known_caveats -- Lines with known behaviour that probably isn't what you think/hope it is	for name, case in pairs(t_caveat) do		self:equals(''..name..' '..case[1]..' ',m._testline(case[1]),case[2],{nowiki=1}) self:equals(''..name..' (Sandbox) '..case[1]..' ',s._testline(case[1]),case[2],{nowiki=1}) end end

function p:test_lines_to_avoid -- Various lines that should NOT match for name, wikitext in pairs(t_avoid) do		self:equals(''..name..' '..wikitext..' ',m._testline(wikitext),wikitext,{nowiki=1}) self:equals(''..name..' (Sandbox) '..wikitext..' ',s._testline(wikitext),wikitext,{nowiki=1}) end end

function p:test_same_line -- Test passing a link with no line breaks self:equals('same line',m.replaceLinksInUnorderedList('*hello'),'*hello',{nowiki=1}) end

function p:test_one_item_list -- Test updating a single un-piped link in a list local supply = [==[List ]==]	local expect = [==[List ]==]	self:preprocess_equals('', expect,{nowiki=1}) end
 * hello

return p