Module:ApplyLinkAnnotations/testcases
| 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:ApplyLinkAnnotations')
local s = require('Module:ApplyLinkAnnotations/sandbox')
local t_caveat = {}
t_caveat["SEE DOCS: html comments"] = { "<!-- wikitext comments -->", "<!-- wikitext comments -->" }
t_caveat["SEE DOCS: link extensions"] = { "*[[Flower]]y", "*[[Flower]]y" }
t_caveat["SEE DOCS: single letter article titles"] = { "*[[T]]", "*[[T]]" }
local t_match = {}
t_match["deep indent with asterisks"] = { "** [[Wikitext]]", "** {{Annotated link |Wikitext}}" }
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["section links"] = { "*[[Clowns#On Halloween]]", "* {{Annotated link |Clowns#On Halloween}}" }
t_match["indented list item"] = { ":*[[related]]", ":* {{Annotated link |related}}" }
t_match["very indented item"] = { "::::*[[loosely related|tangential]]", "::::* {{Annotated link |loosely related|tangential}}" }
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["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"] = "* {{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["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('<b>'..name..'</b><br/><kbd><nowiki>'..case[1]..'</nowiki></kbd>',m._testline(case[1]),case[2],{nowiki=1})
self:equals('<b>'..name..' (Sandbox)</b><br/><kbd><nowiki>'..case[1]..'</nowiki></kbd>',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('<b>'..name..'</b><br/><kbd><nowiki>'..case[1]..'</nowiki></kbd>',m._testline(case[1]),case[2],{nowiki=1})
self:equals('<b>'..name..' (Sandbox)</b><br/><kbd><nowiki>'..case[1]..'</nowiki></kbd>',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('<b>'..name..'</b><br/><kbd><nowiki>'..wikitext..'</nowiki></kbd>',m._testline(wikitext),wikitext,{nowiki=1})
self:equals('<b>'..name..' (Sandbox)</b><br/><kbd><nowiki>'..wikitext..'</nowiki></kbd>',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
*[[hello]]
]==]
local expect = [==[List
* {{Annotated link |hello}}
]==]
self:preprocess_equals('{{#invoke:ApplyLinkAnnotations|bySubstitutionInUnorderedList|'..supply..'}}', expect,{nowiki=1})
end
return p
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.