Jump to content

Module:ApplyLinkAnnotations/testcases

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by N8wilson (talk | contribs) at 15:49, 12 June 2021 (fix missed identifier; add test case). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
-- 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"] = { "*[[hello]]", "* {{Annotated link |hello}}" }
t_match["pipe list item"] = { "*[[hello|hey]]", "* {{Annotated link |hello|hey}}" }

function p:test_pattern_lines_to_match()
	-- Various lines that should match
	for name, case in pairs(t_match) do
		self:equals(name,m._testline(case[1]),case[2],{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