Jump to content

Module:Delink/testcases: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
No edit summary
Tag: Reverted
Not what module testcases pages are for
Line 1: Line 1:
local p = require('Module:UnitTests')
-- This module de-links most wikitext.


function p:test01_basic()
require('Module:No globals/testcases')
self:preprocess_equals_many('{{delink/sandbox|', '}}', {
{ '[[Apple]]', 'Apple'},
{ '[[Orange]]s are dissimilar to [[Apple]]s', 'Oranges are dissimilar to Apples'},
{ '[[Apple]]s and [[orange]]s and [[fruit salad|other kinds of fruit]]', 'Apples and oranges and other kinds of fruit'},
{ 'All [[Gone]] [[wikt:to|]] [[Bed]] [[Now]]', 'All Gone to Bed Now'},
{ '[[Survey]] of [http://books.google.com Google Books] on [[UK|Britain]]', 'Survey of Google Books on Britain'}
}, {nowiki='yes'})
end


function p:test02_cats_and_interwikis()
local p = {}
self:preprocess_equals_many('{{delink/sandbox|', '}}', {
{ '[[Category:Foo]]', ''},
{ '[[category:Foo]]', ''},
{ '[[Image:Foo]]', ''},
{ '[[es:Foo]]', ''},
{ '[[wikt:Foo]]', 'wikt:Foo'},
{ '[[es:Wikipedia:Políticas]]', ''},
{ '[[abcd:efgh:ijkl]]', 'abcd:efgh:ijkl'},
{ '[[cbk-zam:abcd:efgh]]', ''},
{ '[[meatball:WikiPedia]]', 'meatball:WikiPedia' },
}, {nowiki='yes'})
end


function p:test03_colontrick()
local getArgs
self:preprocess_equals_many('{{delink/sandbox|', '}}', {
{ '[[:Category:Foo]]', 'Category:Foo'},
{ '[[:es:Foo]]', 'es:Foo'},
{ '[[:wikt:Foo]]', 'wikt:Foo'},
{ '[[:es:Wikipedia:Políticas]]', 'es:Wikipedia:Políticas'},
{ '[[:abcd:efgh:ijkl]]', 'abcd:efgh:ijkl'},
{ '[[:cbk-zam:abcd:efgh]]', 'cbk-zam:abcd:efgh'},
{ '[[:meatball:WikiPedia]]', 'meatball:WikiPedia'},
}, {nowiki='yes'})
end


local function delinkReversePipeTrick(s)
function p:test04_pipetrick()
self:preprocess_equals_many('{{delink/sandbox|', '}}', {
if s:match("^%[%[|.*[|\n]") then -- Check for newlines or multiple pipes.
{ '[[Pipe (computing)|]]', 'Pipe'},
return s
{ '[[Boston, Massachusetts|]]', 'Boston'},
else
{ '[[Wikipedia:Verifiability|]]', 'Verifiability'},
return s:match("%[%[|(.*)%]%]")
{ '[[User:Example|]]', 'Example'},
end
{ '[[Template:Welcome|]]', 'Welcome'},
{ '[[Yours, Mine and Ours (1968 film)|]]', 'Yours, Mine and Ours'},
{ '[[:es:Wikipedia:Políticas|]]', 'Wikipedia:Políticas'},
{ '[[Il Buono, il Brutto, il Cattivo|]]', 'Il Buono'},
{ '[[Wikipedia:Manual of Style (Persian)|]]', 'Manual of Style'},
{ '[[Wikipedia:Manual of Style(Persian)|]]', 'Manual of Style'},
{ '[[foo|bar|]]', 'bar|'},
{ '[[foo||]]', '|'},
{ 'xx[[foo bar (baz)|]]xx', 'xxfoo bar xx'},
}, {nowiki='yes'})
end
end


local function delinkPipeTrick(s)
function p:test05_reverse_pipetrick()
self:preprocess_equals_many('{{delink/sandbox|', '}}', {
local linkarea, display = "", ""
{ '[[|foo]]', 'foo'},
-- We need to deal with colons, brackets, and commas, per [[Help:Pipe trick]].
{ '[[|multiple|pipes]]', '[[|multiple|pipes]]'},
{ '[[|foo (bar)]]', 'foo (bar)'},
-- First, remove the text before the first colon, if any.
{ '[[|foo, bar (baz)]]', 'foo, bar (baz)'},
if s:match(":") then
{ '[[|simultaneous pipe trick|]]', '[[|simultaneous pipe trick|]]'},
s = s:match("%[%[.-:(.*)|%]%]")
}, {nowiki='yes'})
-- If there are no colons, grab all of the text apart from the square brackets and the pipe.
else
s = s:match("%[%[(.*)|%]%]")
end
-- Next up, brackets and commas.
if s:match("%(.-%)$") then -- Brackets trump commas.
s = s:match("(.-) ?%(.-%)$")
elseif s:match(",") then -- If there are no brackets, display only the text before the first comma.
s = s:match("(.-),.*$")
end
return s
end
end


local function delinkWikilink(s)
function p:test06_badlinks()
self:preprocess_equals_many('{{delink/sandbox|', '}}', {
local result = s
{ '[[<]]', '[[<]]'},
-- Deal with the reverse pipe trick.
{ '[[Category:<]]', '[[Category:<]]'},
if result:match("%[%[|") then
{ '[[:Category:<]]', '[[:Category:<]]'},
return delinkReversePipeTrick(result)
{ '[[:Category:<|Foo]]', '[[:Category:<|Foo]]'},
end
{ '[[:Category:<|]]', '[[:Category:<|]]'},
{ '[[:Category:Foo|<]]', '<'},
result = mw.uri.decode(result, "PATH") -- decode percent-encoded entities. Leave underscores and plus signs.
{ '[[Category:Foo|<]]', ''},
result = mw.text.decode(result, true) -- decode HTML entities.
{ '[[Foo:Bar|<]]', '<'},
{ '[[Foo:Bar:>]]', '[[Foo:Bar:>]]'},
-- Check for bad titles. To do this we need to find the
{ '[[es:Wikipedia:<]]', '[[es:Wikipedia:<]]'},
-- title area of the link, i.e. the part before any pipes.
{ '[[es:Wikipedia:Foo|<]]', ''},
local titlearea
{ '[[:es:Wikipedia:<]]', '[[:es:Wikipedia:<]]'},
if result:match("|") then -- Find if we're dealing with a piped link.
{ '[[:es:Wikipedia:Foo|<]]', '<'},
titlearea = result:match("^%[%[(.-)|.*%]%]")
{ '[[Foo:Bar:Foo#>]]', 'Foo:Bar:Foo#>'},
else
{ '[[Foo:Bar:Foo>#Baz]]', '[[Foo:Bar:Foo>#Baz]]'},
titlearea = result:match("^%[%[(.-)%]%]")
{ '[[Foo#Bar>#Baz]]', 'Foo#Bar>#Baz'},
end
{ '[[Foo>#Bar#Baz]]', '[[Foo>#Bar#Baz]]'},
-- Check for bad characters.
{ '[[wikt:es:asdf:&#x0000;Template:title#Fragment]]', '[[wikt:es:asdf:&#x0000;Template:title#Fragment]]'},
if mw.ustring.match(titlearea, "[%[%]<>{}%%%c\n]") then
{ '[[foo]]', '[[foo]]'}, -- ASCII delete character
return s
}, {nowiki='yes'})
end
end

-- Check for categories, interwikis, and files.
function p:test07_URI_slashes()
local colonprefix = result:match("%[%[(.-):.*%]%]") or "" -- Get the text before the first colon.
self:preprocess_equals_many('{{delink/sandbox|', '}}', {
local ns = mw.site.namespaces[colonprefix] -- see if this is a known namespace
{ '[/foo]', '[/foo]'},
if mw.language.isKnownLanguageTag(colonprefix)
{ '[/foo bar]', '[/foo bar]'},
or ( ns and ( ns.canonicalName == "File" or ns.canonicalName == "Category" ) ) then
{ '[//foo]', ''},
return ""
{ '[//foo bar]', 'bar'},
end
{ '[///foo]', ''},
{ '[///foo bar]', 'bar'},
-- Remove the colon if the link is using the [[Help:Colon trick]].
{ '[////foo]', ''},
if result:match("%[%[:") then
{ '[////foo bar]', 'bar'},
result = "[[" .. result:match("%[%[:(.*%]%])")
{ '[///////////////////////////////////foo]', ''},
end
{ '[///////////////////////////////////foo bar]', 'bar'},
}, {nowiki='yes'})
-- Deal with links using the [[Help:Pipe trick]].
end
if mw.ustring.match(result, "^%[%[[^|]*|%]%]") then

return delinkPipeTrick(result)
function p:test08_URI_prefixes()
end
self:preprocess_equals_many('{{delink/sandbox|', '}}', {
{ '[://foo]', '[://foo]'},
-- Find the display area of the wikilink
{ '[:://foo]', '[:://foo]'},
if result:match("|") then -- Find if we're dealing with a piped link.
{ '[abcd://]', '[abcd://]'},
result = result:match("^%[%[.-|(.+)%]%]")
{ '[abcd://foo]', '[abcd://foo]'},
-- Remove new lines from the display of multiline piped links,
{ '[http://]', '[http://]'},
-- where the pipe is before the first new line.
{ '[http://foo]', ''},
result = result:gsub("\n", "")
{ '[https://]', '[https://]'},
else
{ '[https://foo]', ''},
result = result:match("^%[%[(.-)%]%]")
{ '[ftp://]', '[ftp://]'},
end
{ '[ftp://foo]', ''},
{ '[gopher://]', '[gopher://]'},
{ '[gopher://foo]', ''},
{ '[mailto:]', '[mailto:]'},
{ '[mailto:foo]', ''},
{ '[news]', '[news]'},
{ '[news at ten]', '[news at ten]'},
{ '[news:]', '[news:]'},
{ '[news: at ten]', '[news: at ten]'},
{ '[news:/]', ''},
{ '[news:/ at ten]', 'at ten'},
{ '[news://]', ''},
{ '[news://foo]', ''},
{ '[news://foo at ten]', 'at ten'},
{ '[irc://]', '[irc://]'},
{ '[irc://foo]', ''},
}, {nowiki='yes'})
end

function p:test09_URI_special_characters()
self:preprocess_equals_many('{{delink/sandbox|', '}}', {
{ '[:http://foo]', '[:http://foo]'},
{ '[http://<foo]', '<foo'},
{ '[http://foo"bar]', '"bar'},
{ '[http://"foo]', '[http://"foo]'},
{ '[http://>foo]', '>foo'},
{ '[http://foo<bar]', '<bar'},
{ '[http://foo>bar]', '>bar'},
{ '[http:// foo]', '[http:// foo]'},
}, {nowiki='yes'})
end

function p:test10_nesting()
self:preprocess_equals_many('{{delink/sandbox|', '}}', {
{ 'text[[<s name=]]>stricken</s>more text]]', 'text[[<s name=]]>stricken</s>more text]]'},
{ 'text[[<s>stricken</s>more text]]', 'text[[<s>stricken</s>more text]]'},
{ '[[outer[[inner]]outer]]', '[[outerinnerouter]]'},
{ '[http://outer outer [[inner]] outer]', 'outer inner outer'},
{ '[[outer[http://inner inner]outer]]', '[[outerinnerouter]]'},
{ '[[outer[http://inner]outer]]]', '[[outerouter]]]'},
}, {nowiki='yes'})
end

function p:test11_multiple_pipes()
self:preprocess_equals_many('{{delink/sandbox|', '}}', {
{ '[[foo|bar|baz]]', 'bar|baz'},
{ '[[foo|bar|baz|]]', 'bar|baz|'},
{ '[[|foo|bar|baz]]', '[[|foo|bar|baz]]'},
{ '[[|foo|bar|baz|]]', '[[|foo|bar|baz|]]'},
{ '[[foo|bar|baz||]]', 'bar|baz||'},
{ '[[||foobarbaz]]', '[[||foobarbaz]]'},
{ '[[foobarbaz||]]', '|'},
}, {nowiki='yes'})
end

function p:test12_http_links()
self:preprocess_equals_many('{{delink/sandbox|', '}}', {
{ '[http]', '[http]'},
{ '[http:foo]', '[http:foo]'},
{ '[http:]', '[http:]'},
{ '[http:foo]', '[http:foo]'},
{ '[http:/]', '[http:/]'},
{ '[http:/foo]', '[http:/foo]'},
{ '[http://]', '[http://]'},
{ '[http://foo]', ''},
}, {nowiki='yes'})
end

function p:test13_whitespace()
self:preprocess_equals_many('{{delink/sandbox|', '}}', {
{ 'xx[[ fruit salad | many kinds of fruit ]]xx', 'xx many kinds of fruit xx'},
{ '[http://www.example.com example]', 'example'},
{ [=[[[link with
a line break in]]]=], '[[link with a line break in]]'},
{ [=[[[link with

two line breaks in]]]=], [=[[[link with

two line breaks in]]]=] },
{ [=[an [http://www.example.com
example].]=], 'an [http://www.example.com example].'},
{ [=[an [http://www.example.com

example].]=], [=[an [http://www.example.com

example].]=] },
{ '[http://www.example.com HTML line breaks] between<br>two [http://www.example.com links]', 'HTML line breaks between two links'},
{ '[http://www.example.com HTML line break<br />within<br/>a link]', 'HTML line break within a link'},
{ '[http://www.example.com Double HTML line break<br /><br />within a link]', [=[Double HTML line break

within a link]=]},
{ '[http://www.example.com non-breaking spaces]', 'non-breaking spaces'},
{ '[http://www.example.com tab characters]', 'tab characters'},
{ '[http://www.example.com multiple non-breaking spaces]', 'multiple non-breaking spaces'},
{ '[http://www.example.com multiple tab characters]', 'multiple tab characters'},
}, {nowiki='yes'})
end

function p:test14_full_paragraphs()
self:preprocess_equals_many('{{delink/sandbox|', '}}', {
{
[==[He then studied at [[Saint Patrick Seminary, Menlo Park|St. Patrick's Seminary]] in [[Menlo Park, California|Menlo Park]]. He was [[Holy Orders|ordained]] to the [[Priesthood (Catholic Church)|priesthood]] on June 10, 1933.<ref name=hierarchy>{{cite news|work=Catholic-Hierarchy.org|title=Bishop Merlin Joseph Guilfoyle|url=http://www.catholic-hierarchy.org/bishop/bguimj.html}}</ref> In 1937, he earned a [[Doctor of Canon Law]] from the [[The Catholic University of America|Catholic University of America]] in [[Washington, D.C.]]<ref name=curtis/> He became a [[Monsignor|Domestic Prelate]] in 1949, and was co-founder and [[chaplain]] of [http://www.stthomasmore-sf.org/ St. Thomas More Society].]==],
[==[He then studied at St. Patrick's Seminary in Menlo Park. He was ordained to the priesthood on June 10, 1933. In 1937, he earned a Doctor of Canon Law from the Catholic University of America in Washington, D.C. He became a Domestic Prelate in 1949, and was co-founder and chaplain of St. Thomas More Society.]==],
},
})
end

function p:test15_full_paragraphs_removing_ref_strip_markers()
self:preprocess_equals_many('{{delink/sandbox|refs=yes|', '}}', {
{
[==[He then studied at [[Saint Patrick Seminary, Menlo Park|St. Patrick's Seminary]] in [[Menlo Park, California|Menlo Park]]. He was [[Holy Orders|ordained]] to the [[Priesthood (Catholic Church)|priesthood]] on June 10, 1933.<ref name=hierarchy>{{cite news|work=Catholic-Hierarchy.org|title=Bishop Merlin Joseph Guilfoyle|url=http://www.catholic-hierarchy.org/bishop/bguimj.html}}</ref> In 1937, he earned a [[Doctor of Canon Law]] from the [[The Catholic University of America|Catholic University of America]] in [[Washington, D.C.]]<ref name=curtis/> He became a [[Monsignor|Domestic Prelate]] in 1949, and was co-founder and [[chaplain]] of [http://www.stthomasmore-sf.org/ St. Thomas More Society].]==],
[==[He then studied at St. Patrick's Seminary in Menlo Park. He was ordained to the priesthood on June 10, 1933. In 1937, he earned a Doctor of Canon Law from the Catholic University of America in Washington, D.C. He became a Domestic Prelate in 1949, and was co-founder and chaplain of St. Thomas More Society.]==],
},
})
end


function p:test16_html_comments()
return result
self:preprocess_equals_many('{{delink/sandbox|', '}}', {
{ '[[foo<!--bar]]-->baz]]', 'foobaz'},
{ 'foo<!--bar-->baz', 'foobaz'},
{ 'foo<!--bar<!--baz-->bat-->bam', 'foobat-->bam'},
{ 'foo[http://abcd<!--bar-->efgh]baz', 'foobaz'},
{ 'foo[http://abcd<!--barefgh]baz-->bat', 'foo[http://abcdbat'},
{ 'foo[http://ab[[cd]]<!--barefgh]baz-->bat', 'foo[http://abcdbat'},
{ 'foo[http://ab{{!((}}cd<!--bar]]efgh]baz-->bat', 'foo[http://ab[[cdbat'},
{ 'foo[[bar<!--baz-->]]bam', 'foobarbam'},
}, {nowiki='yes'})
end
end


local function delinkURL(s)
function p:test17_nowiki()
self:preprocess_equals_many('{{delink/sandbox|', '}}', {
-- Assume we have already delinked internal wikilinks, and that
{ '<nowiki>[[foo]]</nowiki>', '[[foo]]'},
-- we have been passed some text between two square brackets [foo].
{ '[[foo]]<nowiki>[[bar]]</nowiki>[[baz]]', 'foo[[bar]]baz'},
{ '<nowiki>[http://www.example.com foo]</nowiki>', '[http://www.example.com foo]'},
-- If the text contains a line break it is not formatted as a URL, regardless of other content.
{ '{{!((}}foo<nowiki>bar]]</nowiki>', '[[foobar]]'},
if s:match("\n") then
{ '<nowiki>[[foo</nowiki>bar]]', '[[foobar]]'},
return s
{ '[http://www.exa<nowiki>mple.com foo]</nowiki>', '[http://www.example.com foo]'},
end
}, {nowiki='yes'})
-- Check if the text has a valid URL prefix and at least one valid URL character.
local valid_url_prefixes = {"//", "http://", "https://", "ftp://", "gopher://", "mailto:", "news:", "irc://"}
local url_prefix
for i,v in ipairs(valid_url_prefixes) do
if mw.ustring.match(s, '^%[' .. v ..'[^"%s].*%]' ) then
url_prefix = v
break
end
end
-- Get display text
if not url_prefix then
return s
end
s = s:match("^%[" .. url_prefix .. "(.*)%]") -- Grab all of the text after the URL prefix and before the final square bracket.
s = s:match('^.-(["<> ].*)') or "" -- Grab all of the text after the first URL separator character ("<> ).
s = mw.ustring.match(s, "^%s*(%S.*)$") or "" -- If the separating character was a space, trim it off.
local s_decoded = mw.text.decode(s, true)
if mw.ustring.match(s_decoded, "%c") then
return s
else
return s_decoded
end
end
end


function p:test18_decoding()
local function delinkLinkClass(s, pattern, delinkFunction)
self:preprocess_equals_many('{{delink/sandbox|', '}}', {
if not type(s) == "string" then
{ '[[foo%25 bar]]', 'foo% bar'},
error("Attempt to de-link non-string input.", 2)
{ '[[foo%25bar]]', '[[foo%25bar]]'},
end
{ '[[foo%24bar]]', 'foo$bar'},
if not ( type(pattern) == "string" and mw.ustring.sub(pattern, 1, 1) == "^" ) then
{ '[[foo%88bar]]', '[[foo%88bar]]'},
error('Invalid pattern detected. Patterns must begin with "^".', 2)
{ '[[foo%6Abar]]', 'foojbar'},
end
{ '[[foo%11bar]]', '[[foo%11bar]]'},
-- Iterate over the text string, and replace any matched text. using the
{ '[[foo&amp;bar]]', 'foo&bar'},
-- delink function. We need to iterate character by character rather
{ '[[foo%25bar]]', '[[foo%25bar]]'},
-- than just use gsub, otherwise nested links aren't detected properly.
{ '[[foo&a%6Amp;bar]]', '[[foo&a%6Amp;bar]]'},
local result = ""
{ '[[foo&%61mp;bar]]', 'foo&bar'},
while s ~= '' do
{ '[[foo&%62mp;bar]]', '[[foo&%62mp;bar]]'},
-- Replace text using one iteration of gsub.
{ '[[foo&#x25;bar]]', '[[foo&#x25;bar]]'},
s = mw.ustring.gsub(s, pattern, delinkFunction, 1)
{ '[[foo&#x25;62bar]]', '[[foo&#x25;62bar]]'},
-- Append the left-most character to the result string.
{ '[[foo&#x0000;bar]]', '[[foo&#x0000;bar]]'},
result = result .. mw.ustring.sub(s, 1, 1)
{ '[[foo&#x00000;bar]]', '[[foo&#x00000;bar]]'},
s = mw.ustring.sub(s, 2, -1)
{ '[[foo&#x22;bar]]', 'foo"bar'},
end
{ '[[foo&#x0000022;bar]]', 'foo"bar'},
return result
{ '[[foo&amp;amp;bar]]', '[[foo&amp;amp;bar]]'},
}, {nowiki='yes'})
end
end


function p._delink(args)
function p:test19_URL_decoding()
self:preprocess_equals_many('{{delink/sandbox|', '}}', {
local text = args[1] or ""
{ '[http://www.example.com foo%25 bar]', 'foo%25 bar'},
if args.refs == "yes" then
{ '[http://www.example.com foo%25bar]', 'foo%25bar'},
-- Remove any [[Help:Strip markers]] representing ref tags. In most situations
{ '[http://www.example.com foo%24bar]', 'foo%24bar'},
-- this is not a good idea - only use it if you know what you are doing!
{ '[http://www.example.com foo%88bar]', 'foo%88bar'},
text = mw.ustring.gsub(text, "UNIQ%w*%-ref%-%d*%-QINU", "")
{ '[http://www.example.com foo%6Abar]', 'foo%6Abar'},
end
{ '[http://www.example.com foo%11bar]', 'foo%11bar'},
if not (args.comments == "no") then
{ '[http://www.example.com foo&amp;bar]', 'foo&bar'},
text = text:gsub("<!%-%-.-%-%->", "") -- Remove html comments.
{ '[http://www.example.com foo%25bar]', 'foo%25bar'},
end
{ '[http://www.example.com foo&a%6Amp;bar]', 'foo&a%6Amp;bar'},
if not (args.wikilinks == "no") then
{ '[http://www.example.com foo&%61mp;bar]', 'foo&%61mp;bar'},
text = delinkLinkClass(text, "^%[%[.-%]%]", delinkWikilink) -- De-link wikilinks.
{ '[http://www.example.com foo&%62mp;bar]', 'foo&%62mp;bar'},
end
{ '[http://www.example.com foo&#x25;bar]', 'foo%bar'},
if not (args.urls == "no") then
{ '[http://www.example.com foo&#x25;62bar]', 'foo%62bar'},
text = delinkLinkClass(text, "^%[.-%]", delinkURL) -- De-link URLs.
{ '[http://www.example.com foo&#x0000;bar]', 'foo&#x0000;bar'},
end
{ '[http://www.example.com foo&#x00000;bar]', 'foo&#x00000;bar'},
if not (args.whitespace == "no") then
{ '[http://www.example.com foo&#x22;bar]', 'foo"bar'},
-- Replace single new lines with a single space, but leave double new lines
{ '[http://www.example.com foo&#x0000022;bar]', 'foo"bar'},
-- and new lines only containing spaces or tabs before a second new line.
}, {nowiki='yes'})
text = mw.ustring.gsub(text, "([^\n \t][ \t]*)\n([ \t]*[^\n \t])", "%1 %2")
text = text:gsub("[ \t]+", " ") -- Remove extra tabs and spaces.
end
return text
end
end


function p.delink(frame)
function p:test20_no_link()
self:preprocess_equals_many('{{delink/sandbox|', '}}', {
if not getArgs then
{ '#Foo', '#Foo' },
getArgs = require('Module:Arguments/testcases').getArgs
{ 'Foo#Bar', 'Foo#Bar' },
end
}, {nowiki='yes'})
return p._delink(getArgs(frame, {wrappers = 'Template:Delink'}))
end
end



Revision as of 03:47, 30 March 2021

local p = require('Module:UnitTests')

function p:test01_basic()
	self:preprocess_equals_many('{{delink/sandbox|', '}}', {
		{ '[[Apple]]', 'Apple'},
		{ '[[Orange]]s are dissimilar to [[Apple]]s', 'Oranges are dissimilar to Apples'},
		{ '[[Apple]]s and [[orange]]s and [[fruit salad|other kinds of fruit]]', 'Apples and oranges and other kinds of fruit'},
		{ 'All [[Gone]] [[wikt:to|]] [[Bed]] [[Now]]', 'All Gone to Bed Now'},
		{ '[[Survey]] of [http://books.google.com Google Books] on [[UK|Britain]]', 'Survey of Google Books on Britain'}
	}, {nowiki='yes'})
end

function p:test02_cats_and_interwikis()
	self:preprocess_equals_many('{{delink/sandbox|', '}}', {
		{ '[[Category:Foo]]', ''},
		{ '[[category:Foo]]', ''},
		{ '[[Image:Foo]]', ''},
		{ '[[es:Foo]]', ''},
		{ '[[wikt:Foo]]', 'wikt:Foo'},
		{ '[[es:Wikipedia:Políticas]]', ''},
		{ '[[abcd:efgh:ijkl]]', 'abcd:efgh:ijkl'},
		{ '[[cbk-zam:abcd:efgh]]', ''},
		{ '[[meatball:WikiPedia]]', 'meatball:WikiPedia' },
	}, {nowiki='yes'})
end

function p:test03_colontrick()
	self:preprocess_equals_many('{{delink/sandbox|', '}}', {
		{ '[[:Category:Foo]]', 'Category:Foo'},
		{ '[[:es:Foo]]', 'es:Foo'},
		{ '[[:wikt:Foo]]', 'wikt:Foo'},
		{ '[[:es:Wikipedia:Políticas]]', 'es:Wikipedia:Políticas'},
		{ '[[:abcd:efgh:ijkl]]', 'abcd:efgh:ijkl'},
		{ '[[:cbk-zam:abcd:efgh]]', 'cbk-zam:abcd:efgh'},
		{ '[[:meatball:WikiPedia]]', 'meatball:WikiPedia'},
	}, {nowiki='yes'})
end

function p:test04_pipetrick()
	self:preprocess_equals_many('{{delink/sandbox|', '}}', {
		{ '[[Pipe (computing)|]]', 'Pipe'},
		{ '[[Boston, Massachusetts|]]', 'Boston'},
		{ '[[Wikipedia:Verifiability|]]', 'Verifiability'},
		{ '[[User:Example|]]', 'Example'},
		{ '[[Template:Welcome|]]', 'Welcome'},
		{ '[[Yours, Mine and Ours (1968 film)|]]', 'Yours, Mine and Ours'},
		{ '[[:es:Wikipedia:Políticas|]]', 'Wikipedia:Políticas'},
		{ '[[Il Buono, il Brutto, il Cattivo|]]', 'Il Buono'},
		{ '[[Wikipedia:Manual of Style (Persian)|]]', 'Manual of Style'},
		{ '[[Wikipedia:Manual of Style(Persian)|]]', 'Manual of Style'},
		{ '[[foo|bar|]]', 'bar|'},
		{ '[[foo||]]', '|'},
		{ 'xx[[foo bar   (baz)|]]xx', 'xxfoo bar xx'},
	}, {nowiki='yes'})
end

function p:test05_reverse_pipetrick()
	self:preprocess_equals_many('{{delink/sandbox|', '}}', {
		{ '[[|foo]]', 'foo'},
		{ '[[|multiple|pipes]]', '[[|multiple|pipes]]'},
		{ '[[|foo (bar)]]', 'foo (bar)'},
		{ '[[|foo, bar (baz)]]', 'foo, bar (baz)'},
		{ '[[|simultaneous pipe trick|]]', '[[|simultaneous pipe trick|]]'},
	}, {nowiki='yes'})
end

function p:test06_badlinks()
	self:preprocess_equals_many('{{delink/sandbox|', '}}', {
		{ '[[<]]', '[[<]]'},
		{ '[[Category:<]]', '[[Category:<]]'},
		{ '[[:Category:<]]', '[[:Category:<]]'},
		{ '[[:Category:<|Foo]]', '[[:Category:<|Foo]]'},
		{ '[[:Category:<|]]', '[[:Category:<|]]'},
		{ '[[:Category:Foo|<]]', '<'},
		{ '[[Category:Foo|<]]', ''},
		{ '[[Foo:Bar|<]]', '<'},
		{ '[[Foo:Bar:>]]', '[[Foo:Bar:>]]'},
		{ '[[es:Wikipedia:<]]', '[[es:Wikipedia:<]]'},
		{ '[[es:Wikipedia:Foo|<]]', ''},
		{ '[[:es:Wikipedia:<]]', '[[:es:Wikipedia:<]]'},
		{ '[[:es:Wikipedia:Foo|<]]', '<'},
		{ '[[Foo:Bar:Foo#>]]', 'Foo:Bar:Foo#>'},
		{ '[[Foo:Bar:Foo>#Baz]]', '[[Foo:Bar:Foo>#Baz]]'},
		{ '[[Foo#Bar>#Baz]]', 'Foo#Bar>#Baz'},
		{ '[[Foo>#Bar#Baz]]', '[[Foo>#Bar#Baz]]'},
		{ '[[wikt:es:asdf:&#x0000;Template:title#Fragment]]', '[[wikt:es:asdf:&#x0000;Template:title#Fragment]]'},
		{ '[[foo]]', '[[foo]]'}, -- ASCII delete character
	}, {nowiki='yes'})
end

function p:test07_URI_slashes()
	self:preprocess_equals_many('{{delink/sandbox|', '}}', {
		{ '[/foo]', '[/foo]'},
		{ '[/foo bar]', '[/foo bar]'},
		{ '[//foo]', ''},
		{ '[//foo bar]', 'bar'},
		{ '[///foo]', ''},
		{ '[///foo bar]', 'bar'},
		{ '[////foo]', ''},
		{ '[////foo bar]', 'bar'},
		{ '[///////////////////////////////////foo]', ''},
		{ '[///////////////////////////////////foo bar]', 'bar'},
	}, {nowiki='yes'})
end

function p:test08_URI_prefixes()
	self:preprocess_equals_many('{{delink/sandbox|', '}}', {
		{ '[://foo]', '[://foo]'},
		{ '[:://foo]', '[:://foo]'},
		{ '[abcd://]', '[abcd://]'},
		{ '[abcd://foo]', '[abcd://foo]'},
		{ '[http://]', '[http://]'},
		{ '[http://foo]', ''},
		{ '[https://]', '[https://]'},
		{ '[https://foo]', ''},
		{ '[ftp://]', '[ftp://]'},
		{ '[ftp://foo]', ''},
		{ '[gopher://]', '[gopher://]'},
		{ '[gopher://foo]', ''},
		{ '[mailto:]', '[mailto:]'},
		{ '[mailto:foo]', ''},
		{ '[news]', '[news]'},
		{ '[news at ten]', '[news at ten]'},
		{ '[news:]', '[news:]'},
		{ '[news: at ten]', '[news: at ten]'},
		{ '[news:/]', ''},
		{ '[news:/ at ten]', 'at ten'},
		{ '[news://]', ''},
		{ '[news://foo]', ''},
		{ '[news://foo at ten]', 'at ten'},
		{ '[irc://]', '[irc://]'},
		{ '[irc://foo]', ''},
	}, {nowiki='yes'})
end

function p:test09_URI_special_characters()
	self:preprocess_equals_many('{{delink/sandbox|', '}}', {
		{ '[:http://foo]', '[:http://foo]'},
		{ '[http://<foo]', '<foo'},
		{ '[http://foo"bar]', '"bar'},
		{ '[http://"foo]', '[http://"foo]'},
		{ '[http://>foo]', '>foo'},
		{ '[http://foo<bar]', '<bar'},
		{ '[http://foo>bar]', '>bar'},
		{ '[http:// foo]', '[http:// foo]'},
	}, {nowiki='yes'})
end

function p:test10_nesting()
	self:preprocess_equals_many('{{delink/sandbox|', '}}', {
		{ 'text[[<s name=]]>stricken</s>more text]]', 'text[[<s name=]]>stricken</s>more text]]'},
		{ 'text[[<s>stricken</s>more text]]', 'text[[<s>stricken</s>more text]]'},
		{ '[[outer[[inner]]outer]]', '[[outerinnerouter]]'},
		{ '[http://outer outer [[inner]] outer]', 'outer inner outer'},
		{ '[[outer[http://inner inner]outer]]', '[[outerinnerouter]]'},
		{ '[[outer[http://inner]outer]]]', '[[outerouter]]]'},
	}, {nowiki='yes'})
end

function p:test11_multiple_pipes()
	self:preprocess_equals_many('{{delink/sandbox|', '}}', {
		{ '[[foo|bar|baz]]', 'bar|baz'},
		{ '[[foo|bar|baz|]]', 'bar|baz|'},
		{ '[[|foo|bar|baz]]', '[[|foo|bar|baz]]'},
		{ '[[|foo|bar|baz|]]', '[[|foo|bar|baz|]]'},
		{ '[[foo|bar|baz||]]', 'bar|baz||'},
		{ '[[||foobarbaz]]', '[[||foobarbaz]]'},
		{ '[[foobarbaz||]]', '|'},
	}, {nowiki='yes'})
end

function p:test12_http_links()
	self:preprocess_equals_many('{{delink/sandbox|', '}}', {
		{ '[http]', '[http]'},
		{ '[http:foo]', '[http:foo]'},
		{ '[http:]', '[http:]'},
		{ '[http:foo]', '[http:foo]'},
		{ '[http:/]', '[http:/]'},
		{ '[http:/foo]', '[http:/foo]'},
		{ '[http://]', '[http://]'},
		{ '[http://foo]', ''},
	}, {nowiki='yes'})
end

function p:test13_whitespace()
	self:preprocess_equals_many('{{delink/sandbox|', '}}', {
		{ 'xx[[   fruit salad   |   many kinds of fruit   ]]xx', 'xx many kinds of fruit xx'},
		{ '[http://www.example.com        example]', 'example'},
		{ [=[[[link with
		a line break in]]]=], '[[link with a line break in]]'},
		{ [=[[[link with

		two line breaks in]]]=], [=[[[link with

 two line breaks in]]]=] },
		{ [=[an [http://www.example.com 
		example].]=], 'an [http://www.example.com example].'},
		{ [=[an [http://www.example.com

		example].]=], [=[an [http://www.example.com

 example].]=] },
		{ '[http://www.example.com HTML line breaks] between<br>two [http://www.example.com links]', 'HTML line breaks between two links'},
		{ '[http://www.example.com HTML line break<br />within<br/>a link]', 'HTML line break within a link'},
		{ '[http://www.example.com Double HTML line break<br /><br  />within a link]', [=[Double HTML line break

within a link]=]},
		{ '[http://www.example.com non-breaking spaces]', 'non-breaking spaces'},
		{ '[http://www.example.com tab characters]', 'tab characters'},
		{ '[http://www.example.com     multiple    non-breaking      spaces]', 'multiple non-breaking spaces'},
		{ '[http://www.example.com     multiple    tab      characters]', 'multiple tab characters'},
	}, {nowiki='yes'})
end

function p:test14_full_paragraphs()
	self:preprocess_equals_many('{{delink/sandbox|', '}}', {
		{
			[==[He then studied at [[Saint Patrick Seminary, Menlo Park|St. Patrick's Seminary]] in [[Menlo Park, California|Menlo Park]]. He was [[Holy Orders|ordained]] to the [[Priesthood (Catholic Church)|priesthood]] on June 10, 1933.<ref name=hierarchy>{{cite news|work=Catholic-Hierarchy.org|title=Bishop Merlin Joseph Guilfoyle|url=http://www.catholic-hierarchy.org/bishop/bguimj.html}}</ref> In 1937, he earned a [[Doctor of Canon Law]] from the [[The Catholic University of America|Catholic University of America]] in [[Washington, D.C.]]<ref name=curtis/> He became a [[Monsignor|Domestic Prelate]] in 1949, and was co-founder and [[chaplain]] of [http://www.stthomasmore-sf.org/ St. Thomas More Society].]==],
			[==[He then studied at St. Patrick's Seminary in Menlo Park. He was ordained to the priesthood on June 10, 1933. In 1937, he earned a Doctor of Canon Law from the Catholic University of America in Washington, D.C. He became a Domestic Prelate in 1949, and was co-founder and chaplain of St. Thomas More Society.]==],
		},
	})
end

function p:test15_full_paragraphs_removing_ref_strip_markers()
	self:preprocess_equals_many('{{delink/sandbox|refs=yes|', '}}', {
		{
			[==[He then studied at [[Saint Patrick Seminary, Menlo Park|St. Patrick's Seminary]] in [[Menlo Park, California|Menlo Park]]. He was [[Holy Orders|ordained]] to the [[Priesthood (Catholic Church)|priesthood]] on June 10, 1933.<ref name=hierarchy>{{cite news|work=Catholic-Hierarchy.org|title=Bishop Merlin Joseph Guilfoyle|url=http://www.catholic-hierarchy.org/bishop/bguimj.html}}</ref> In 1937, he earned a [[Doctor of Canon Law]] from the [[The Catholic University of America|Catholic University of America]] in [[Washington, D.C.]]<ref name=curtis/> He became a [[Monsignor|Domestic Prelate]] in 1949, and was co-founder and [[chaplain]] of [http://www.stthomasmore-sf.org/ St. Thomas More Society].]==],
			[==[He then studied at St. Patrick's Seminary in Menlo Park. He was ordained to the priesthood on June 10, 1933. In 1937, he earned a Doctor of Canon Law from the Catholic University of America in Washington, D.C. He became a Domestic Prelate in 1949, and was co-founder and chaplain of St. Thomas More Society.]==],
		},
	})
end

function p:test16_html_comments()
	self:preprocess_equals_many('{{delink/sandbox|', '}}', {
		{ '[[foo<!--bar]]-->baz]]', 'foobaz'},
		{ 'foo<!--bar-->baz', 'foobaz'},
		{ 'foo<!--bar<!--baz-->bat-->bam', 'foobat-->bam'},
		{ 'foo[http://abcd<!--bar-->efgh]baz', 'foobaz'},
		{ 'foo[http://abcd<!--barefgh]baz-->bat', 'foo[http://abcdbat'},
		{ 'foo[http://ab[[cd]]<!--barefgh]baz-->bat', 'foo[http://abcdbat'},
		{ 'foo[http://ab{{!((}}cd<!--bar]]efgh]baz-->bat', 'foo[http://ab[[cdbat'},
		{ 'foo[[bar<!--baz-->]]bam', 'foobarbam'},
	}, {nowiki='yes'})
end

function p:test17_nowiki()
	self:preprocess_equals_many('{{delink/sandbox|', '}}', {
		{ '<nowiki>[[foo]]</nowiki>', '[[foo]]'},
		{ '[[foo]]<nowiki>[[bar]]</nowiki>[[baz]]', 'foo[[bar]]baz'},
		{ '<nowiki>[http://www.example.com foo]</nowiki>', '[http://www.example.com foo]'},
		{ '{{!((}}foo<nowiki>bar]]</nowiki>', '[[foobar]]'},
		{ '<nowiki>[[foo</nowiki>bar]]', '[[foobar]]'},
		{ '[http://www.exa<nowiki>mple.com foo]</nowiki>', '[http://www.example.com foo]'},
	}, {nowiki='yes'})
end

function p:test18_decoding()
	self:preprocess_equals_many('{{delink/sandbox|', '}}', {
		{ '[[foo%25 bar]]', 'foo% bar'},
		{ '[[foo%25bar]]', '[[foo%25bar]]'},
		{ '[[foo%24bar]]', 'foo$bar'},
		{ '[[foo%88bar]]', '[[foo%88bar]]'},
		{ '[[foo%6Abar]]', 'foojbar'},
		{ '[[foo%11bar]]', '[[foo%11bar]]'},
		{ '[[foo&amp;bar]]', 'foo&bar'},
		{ '[[foo%25bar]]', '[[foo%25bar]]'},
		{ '[[foo&a%6Amp;bar]]', '[[foo&a%6Amp;bar]]'},
		{ '[[foo&%61mp;bar]]', 'foo&bar'},
		{ '[[foo&%62mp;bar]]', '[[foo&%62mp;bar]]'},
		{ '[[foo&#x25;bar]]', '[[foo&#x25;bar]]'},
		{ '[[foo&#x25;62bar]]', '[[foo&#x25;62bar]]'},
		{ '[[foo&#x0000;bar]]', '[[foo&#x0000;bar]]'},
		{ '[[foo&#x00000;bar]]', '[[foo&#x00000;bar]]'},
		{ '[[foo&#x22;bar]]', 'foo"bar'},
		{ '[[foo&#x0000022;bar]]', 'foo"bar'},
		{ '[[foo&amp;amp;bar]]', '[[foo&amp;amp;bar]]'},
	}, {nowiki='yes'})
end

function p:test19_URL_decoding()
	self:preprocess_equals_many('{{delink/sandbox|', '}}', {
		{ '[http://www.example.com foo%25 bar]', 'foo%25 bar'},
		{ '[http://www.example.com foo%25bar]', 'foo%25bar'},
		{ '[http://www.example.com foo%24bar]', 'foo%24bar'},
		{ '[http://www.example.com foo%88bar]', 'foo%88bar'},
		{ '[http://www.example.com foo%6Abar]', 'foo%6Abar'},
		{ '[http://www.example.com foo%11bar]', 'foo%11bar'},
		{ '[http://www.example.com foo&amp;bar]', 'foo&bar'},
		{ '[http://www.example.com foo%25bar]', 'foo%25bar'},
		{ '[http://www.example.com foo&a%6Amp;bar]', 'foo&a%6Amp;bar'},
		{ '[http://www.example.com foo&%61mp;bar]', 'foo&%61mp;bar'},
		{ '[http://www.example.com foo&%62mp;bar]', 'foo&%62mp;bar'},
		{ '[http://www.example.com foo&#x25;bar]', 'foo%bar'},
		{ '[http://www.example.com foo&#x25;62bar]', 'foo%62bar'},
		{ '[http://www.example.com foo&#x0000;bar]', 'foo&#x0000;bar'},
		{ '[http://www.example.com foo&#x00000;bar]', 'foo&#x00000;bar'},
		{ '[http://www.example.com foo&#x22;bar]', 'foo"bar'},
		{ '[http://www.example.com foo&#x0000022;bar]', 'foo"bar'},
	}, {nowiki='yes'})
end

function p:test20_no_link()
	self:preprocess_equals_many('{{delink/sandbox|', '}}', {
		{ '#Foo', '#Foo' },
		{ 'Foo#Bar', 'Foo#Bar' },
	}, {nowiki='yes'})
end

return p