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_and_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:&'},		{ '&#x3c;', '&#x3c;'},		{ , },		{ '&#x3c;', '&#x3c;'},		{ 'Foo:Bar:&', 'Foo:Bar:&'},		{ 'es:Wikipedia:&', 'es:Wikipedia:&'},		{ '&#x3c;', },		{ 'es:Wikipedia:&', 'es:Wikipedia:&'},		{ '&#x3c;', '&#x3c;'},		{ 'Foo:Bar:Foo', 'Foo:Bar:Foo#&#x3e;'},		{ 'Foo:Bar:Foo&', 'Foo:Bar:Foo&'},		{ 'Foo', 'Foo#Bar&#x3e;#Baz'},		{ 'Foo&', 'Foo&'},		{ 'wikt:es:asdf:&', 'wikt:es:asdf:&'}, { '&', '&'}, -- 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]'},		{ , '&#x3c;foo'},		{ , '"bar'},		{ , },		{ , '&#x3e;foo'},		{ , '&#x3c;bar'},		{ , '&#x3e;bar'},		{ '[http:// foo]', '[http:// foo]'},	}, {nowiki='yes'}) end

function p:test10_nesting self:preprocess_equals_many('', {		{ 'text&&#x3e;stricken&#x3c;/s&#x3e;more text]]', 'text&&#x3e;stricken&#x3c;/s&#x3e;more text]]'},		{ 'text&', '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&#x3c;br&#x3e;two links', 'HTML line breaks between two links'}, { 'HTML line break&#x3c;br /&#x3e;within&#x3c;br/&#x3e;a link', 'HTML line break within a link'}, { 'Double HTML line break&#x3c;br /&#x3e;&#x3c;br /&#x3e;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.&#x3c;ref name=hierarchy&#x3e;&#x3c;/ref&#x3e; In 1937, he earned a Doctor of Canon Law from the Catholic University of America in Washington, D.C.&#x3c;ref name=curtis/&#x3e; 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.&#x3c;ref name=hierarchy&#x3e;&#x3c;/ref&#x3e; In 1937, he earned a Doctor of Canon Law from the Catholic University of America in Washington, D.C.&#x3c;ref name=curtis/&#x3e; 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('', {		{ 'foo&--&#x3e;baz]]', 'foobaz'},		{ 'foo&#x3c;!--bar--&#x3e;baz', 'foobaz'},		{ 'foo&#x3c;!--bar&#x3c;!--baz--&#x3e;bat--&#x3e;bam', 'foobat--&#x3e;bam'},		{ 'foobaz', 'foobaz'},		{ 'foobaz--&#x3e;bat', 'foo'foo[http://ab[[cd]&#x3c;!--barefgh]baz--&#x3e;bat', 'foo'foo[http://ab[[cd&#x3c;!--bar]efgh]baz--&#x3e;bat', 'foo'foo[[bar&#x3c;!--baz--&#x3e;]bam', 'foobarbam'},	}, {nowiki='yes'}) end

function p:test17_nowiki self:preprocess_equals_many('', {		{ '&#x3c;nowiki&#x3e;foo&#x3c;/nowiki&#x3e;', 'foo'},		{ 'foo&#x3c;nowiki&#x3e;bar&#x3c;/nowiki&#x3e;baz', 'foobarbaz'},		{ '&#x3c;nowiki&#x3e;foo&#x3c;/nowiki&#x3e;', 'foo'},		{ 'foo&&#x3c;/nowiki&#x3e;', 'foobar'},		{ '&#x3c;nowiki&#x3e;foo&', 'foobar'},		{ 'foo&#x3c;/nowiki&#x3e;', '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&', 'foo&#x26;bar'},		{ 'foo%25bar', 'foo%25bar'},		{ 'foo&', 'foo&'},		{ 'foo&', 'foo&#x26;bar'},		{ 'foo&', 'foo&'},		{ 'foo&', 'foo&'},		{ 'foo&', 'foo&'},		{ 'foo&', 'foo&'},		{ 'foo&', 'foo&'},		{ 'foo&', 'foo"bar'},		{ 'foo&', 'foo"bar'},		{ 'foo&', 'foo&'},	}, {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&#x26;amp;bar', 'foo&#x26;bar'},		{ 'foo%25bar', 'foo%25bar'},		{ 'foo&#x26;a%6Amp;bar', 'foo&#x26;a%6Amp;bar'},		{ 'foo&#x26;%61mp;bar', 'foo&#x26;%61mp;bar'},		{ 'foo&#x26;%62mp;bar', 'foo&#x26;%62mp;bar'},		{ 'foo&#x26;#x25;bar', 'foo%bar'},		{ 'foo&#x26;#x25;62bar', 'foo%62bar'},		{ 'foo&#x26;#x0000;bar', 'foo&#x26;#x0000;bar'}, { 'foo&#x26;#x00000;bar', 'foo&#x26;#x00000;bar'}, { 'foo&#x26;#x22;bar', 'foo"bar'},		{ 'foo&#x26;#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

return p