Module:Delink/testcases

local p = require('Module:UnitTests')

function p:test01_basic self:preprocess_equals_many('', {		{ 'Apple', 'Apple'},		{ 'Oranges are dissimilar to Apples', 'Oranges are dissimilar to Apples'},		{ 'Apples and oranges and other kinds of fruit', 'Apples and oranges and other kinds of fruit'},		{ 'All Gone to Bed Now', 'All Gone to Bed Now'},		{ 'Survey of Google Books on Britain', 'Survey of Google Books on Britain'},		{ 'What If...?', 'What If...?' },	}, {nowiki='yes'}) end

function p:test02_cats_files_interwikis self:preprocess_equals_many(, {		{ , },		{ , },		{ , },		{ , },		{ 'Foo', },		{ 'Foo', 'wikt:Foo'},		{ 'es:Wikipedia:Políticas', },		{ 'abcd:efgh:ijkl', 'abcd:efgh:ijkl'},		{ 'cbk-zam:abcd:efgh', },		{ 'WikiPedia', 'meatball:WikiPedia' },	}, {nowiki='yes'}) end

function p:test03_colontrick self:preprocess_equals_many('', {		{ '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('', {		{ 'Pipe (computing)', 'Pipe'},		{ 'Boston, Massachusetts', 'Boston'},		{ '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'},		{ 'Manual of Style (Persian)', 'Manual of Style'},		{ 'Manual of Style(Persian)', 'Manual of Style'},		{ 'bar|', 'bar|'},		{ '|', '|'},		{ 'xxfoo bar  (baz)xx', 'xxfoo bar xx'},	}, {nowiki='yes'}) end

function p:test05_reverse_pipetrick self:preprocess_equals_many('', {		{ '|foo', 'foo'},		{ 'pipes', '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(, {		{ '<', '<'},		{ },		{ 'Category:<', 'Category:<'},		{ 'Foo', 'Foo'},		{ 'Category:<', 'Category:<'},		{ '<', '<'},		{ , },		{ '<', '<'},		{ 'Foo:Bar:>', 'Foo:Bar:>'},		{ 'es:Wikipedia:<', 'es:Wikipedia:<'},		{ '<', ''},		{ 'es:Wikipedia:<', 'es:Wikipedia:<'},		{ '<', '<'},		{ 'Foo:Bar:Foo', 'Foo:Bar:Foo#>'},		{ 'Foo:Bar:Foo>', 'Foo:Bar:Foo>'},		{ 'Foo', 'Foo#Bar>#Baz'},		{ 'Foo>', 'Foo>'},		{ 'wikt:es:asdf:&', 'wikt:es:asdf:&'},		{ 'foo', 'foo'}, -- ASCII delete character	}, {nowiki='yes'}) end

function p:test07_URI_slashes self:preprocess_equals_many(, {		{ '[/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(, {		{ '[://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(, {		{ '[:http://foo]', '[:http://foo]'},		{ , 'foo'},		{ , 'bar'},		{ '[http:// foo]', '[http:// foo]'},	}, {nowiki='yes'}) end

function p:test10_nesting self:preprocess_equals_many('', {		{ 'textstricken more text]]', 'textstricken more text]]'},		{ 'text stricken more text', 'text stricken more text'},		{ 'outer[[innerouter]]', 'outerinnerouter'},		{ 'outer [[inner] outer]', 'outer inner outer'},		{ 'outerinnerouter', '[[outerinnerouter]]'},		{ 'outerouter]', '[[outerouter]]]'},	}, {nowiki='yes'}) end

function p:test11_multiple_pipes self:preprocess_equals_many('', {		{ 'bar|baz', 'bar|baz'},		{ 'bar|baz|', 'bar|baz|'},		{ 'bar|baz', 'bar|baz'},		{ 'bar|baz|', 'bar|baz|'},		{ 'bar|baz||', 'bar|baz||'},		{ '||foobarbaz', '||foobarbaz'},		{ '|', '|'},	}, {nowiki='yes'}) end

function p:test12_http_links self:preprocess_equals_many(, {		{ '[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('', {		{ 'xx  many kinds of fruit   xx', 'xx many kinds of fruit xx'},		{ '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 example.'}, { [=[an [http://www.example.com

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

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

within a link]=]}, { 'non-breaking spaces', 'non-breaking spaces'}, { 'tab characters', 'tab characters'}, { 'multiple   non-breaking      spaces', 'multiple non-breaking spaces'}, { 'multiple   tab      characters', 'multiple tab characters'}, }, {nowiki='yes'}) end

function p:test14_full_paragraphs self:preprocess_equals_many('', {		{			[==[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.]==],			[==[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('', {		{			[==[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.]==],			[==[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('', {		{ 'foobaz', 'foobaz'},		{ 'foobaz', 'foobaz'},		{ 'foobat-->bam', 'foobat-->bam'},		{ 'foobaz', 'foobaz'},		{ 'foo'foo[http://abcdbat'},		{ 'foo[http://ab[[cd]bat', 'foo'foo[http://ab[[cdbat', 'foo[http://ab[[cdbat'},		{ 'foo[[bar]bam', 'foobarbam'},	}, {nowiki='yes'}) end

function p:test17_nowiki self:preprocess_equals_many('', {		{ ' foo ', 'foo'},		{ 'foo bar baz', 'foobarbaz'},		{ ' foo ', 'foo'},		{ 'foo bar ', 'foobar'},		{ ' foo bar', 'foobar'},		{ 'mple.com foo ', 'foo'},	}, {nowiki='yes'}) end

function p:test18_decoding self:preprocess_equals_many('', {		{ '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&', 'foo&'},		{ 'foo&', 'foo&'},		{ 'foo&', 'foo&'},		{ 'foo&', 'foo&'},		{ 'foo&', 'foo"bar'},		{ 'foo&', 'foo"bar'},		{ 'foo&amp;amp;bar', 'foo&amp;amp;bar'},	}, {nowiki='yes'}) end

function p:test19_URL_decoding self:preprocess_equals_many('', {		{ 'foo%25 bar', 'foo%25 bar'},		{ 'foo%25bar', 'foo%25bar'},		{ 'foo%24bar', 'foo%24bar'},		{ 'foo%88bar', 'foo%88bar'},		{ 'foo%6Abar', 'foo%6Abar'},		{ '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&%61mp;bar'},		{ 'foo&%62mp;bar', 'foo&%62mp;bar'},		{ 'foo&#x25;bar', 'foo%bar'},		{ 'foo&#x25;62bar', 'foo%62bar'},		{ 'foo&#x0000;bar', 'foo&#x0000;bar'},		{ 'foo&#x00000;bar', 'foo&#x00000;bar'}, { 'foo&#x22;bar', 'foo"bar'},		{ 'foo&#x0000022;bar', 'foo"bar'}, }, {nowiki='yes'}) end

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

function p:test21_exotic self:preprocess_equals_many('', {		{ 'some text apples and [[Pear|pears]]', 'some text apples and pears' },		{ 'some text [[Pear|pears]]', 'some text pears' },		{ 'some text  [[Pear|pears]]', 'some text pears' },		{ 'some text  apples and pears', 'some text apples and pears' },		{ 'some text  applespears', 'some text applespears' },		{ 'some text   apples[[:Pear|pears]]', 'some text applespears' },		{			[==[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.]==],			[==[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.]==], },	}, {nowiki='yes'}) end

return p