Module:ApplyLinkAnnotations/testcases
Appearance
![]() | This is the test cases page for the module Module:ApplyLinkAnnotations. Results of the test cases. |
-- Unit tests for [[Module:{{ROOTPAGENAME}}]]. Click talk page to run tests.
local p = require('Module:UnitTests')
local m = require('Module:Sandbox/N8wilson/ApplyLinkAnnotations')
local t_match = {}
t_match["std list item link"] = { "*[[hello]]", "* {{Annotated link |hello}}" }
t_match["pipe list item"] = { "*[[hello|hey]]", "* {{Annotated link |hello|hey}}" }
t_match["escaped spaces"] = { "*[[Afternoon_delight]]", "* {{Annotated link |Afternoon_delight}}" }
t_match["pipe at end"] = { "*[[hello (greeting)|]]", "* {{Annotated link |hello (greeting)|}}" }
t_match["indented list item"] = { ":*[[related]]", ":* {{Annotated link |related}}" }
t_match["piped, indented item"] = { ":*[[related|renamed]]", ":* {{Annotated link |related|renamed}}" }
t_match["accented"] = { "*[[El Niño]]", "* {{Annotated link |El Niño}}" }
t_match["extra spaces"] = { "* [[Dark Matter]]", "* {{Annotated link |Dark Matter}}" }
local t_avoid = {}
t_avoid["manual annotation"] = "*[[hello]] - an English greeting"
t_avoid["link at end"] = "*Alternative theories include [[Nonsense]]"
t_avoid["ordered list"] = "#[[hello]]"
t_avoid["already annotated"] = "* {{Annotated link |hello}}"
t_avoid["section headings"] = "== Section heading =="
t_avoid["stylized links"] = "*''[[Emphasized link]]''"
t_avoid["non-article namespace"] = "*[[File:link_to_file]]"
t_avoid["SEE DOCS: html comments"] = "<!-- wikitext comments -->"
function p:test_lines_to_match()
-- Various lines that should match
for name, case in pairs(t_match) do
self:equals('<b>'..name..'</b><br/><tt><nowiki>'..case[1]..'</nowiki></tt>',m._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('<b>'..name..'</b><br/><tt><nowiki>'..wikitext..'</nowiki></tt>',m._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
*[[hello]]
]==]
local expect = [==[List
* {{Annotated link |hello}}
]==]
self:preprocess_equals('{{#invoke:Sandbox/N8wilson/ApplyLinkAnnotations|bySubstitutionInUnorderedList|'..supply..'}}', expect,{nowiki=1})
end
return p