Module:ApplyLinkAnnotations/testcases explained

-- Unit tests for . 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"] = t_caveat["SEE DOCS: single letter article titles"] =

local t_match = t_match["deep indent with asterisks"] = t_match["std list item link"] = t_match["pipe list item"] = t_match["escaped spaces"] = t_match["section links"] = t_match["indented list item"] = t_match["very indented item"] = t_match["piped, indented item"] = t_match["accented"] = t_match["extra spaces"] =

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"] = "*"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],) self:equals(''..name..' (Sandbox)
'..case[1]..'',s._testline(case[1]),case[2],) endend

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],) self:equals(''..name..' (Sandbox)
'..case[1]..'',s._testline(case[1]),case[2],) endend

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,) self:equals(''..name..' (Sandbox)
'..wikitext..'',s._testline(wikitext),wikitext,) endend

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

function p:test_one_item_list -- Test updating a single un-piped link in a list local supply = [==[List *[[hello]]]

] local expect = [==[List * {{Annotated link |hello}} ]

] self:preprocess_equals('', expect,)end

return p