Module:Delink/testcases

local p = require('Module:UnitTests')

function p:test01_basic()

self:preprocess_equals_many('{{delink/sandbox|', '}}', {

{ '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 Bed Now', 'All Gone to Bed Now'},

{ 'Survey of [http://books.google.com 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('{{delink/sandbox|', '}}', {

{ 'Category:Foo', ''},

{ 'category:Foo', ''},

{ 'File: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'},

{ '', 'Boston'},

{ '', 'Verifiability'},

{ '', 'Example'},

{ '', 'Welcome'},

{ '', 'Yours, Mine and Ours'},

{ '', 'Wikipedia:Políticas'},

{ '', 'Il Buono'},

{ '', 'Manual of Style'},

{ '', 'Manual of Style'},

{ 'foo', 'bar|'},

{ 'foo', '|'},

{ 'xxxx', 'xxfoo bar xx'},

}, {nowiki='yes'})

end

function p:test05_reverse_pipetrick()

self:preprocess_equals_many('{{delink/sandbox|', '}}', {

{ 'foo', 'foo'},

{ '', ''},

{ 'foo (bar)', 'foo (bar)'},

{ 'foo, bar (baz)', 'foo, bar (baz)'},

{ '', ''},

}, {nowiki='yes'})

end

function p:test06_badlinks()

self:preprocess_equals_many('{{delink/sandbox|', '}}', {

{ '<', '<'},

{ 'Category:<', 'Category:<'},

{ ':Category:<', ':Category:<'},

{ 'Foo', 'Foo'},

{ '', ''},

{ '<', '<'},

{ '<', ''},

{ '<', '<'},

{ 'Foo:Bar:>', 'Foo:Bar:>'},

{ 'es:Wikipedia:<', 'es:Wikipedia:<'},

{ '<', ''},

{ ':es:Wikipedia:<', ':es:Wikipedia:<'},

{ '<', '<'},

{ '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:�Template:title#Fragment', 'wikt:es:asdf:�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://

{ '[http://foo"bar]', '"bar'},

{ '[http://"foo]', '[http://"foo]'},

{ '[http://>foo]', '>foo'},

{ '[http://foo

{ '[http://foo>bar]', '>bar'},

{ '[http:// foo]', '[http:// foo]'},

}, {nowiki='yes'})

end

function p:test10_nesting()

self:preprocess_equals_many('{{delink/sandbox|', '}}', {

{ 'text>strickenmore text]]', 'text>strickenmore text]]'},

{ 'textstrickenmore text', 'textstrickenmore text'},

{ 'outer[[innerouter]]', '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'},

{ 'foo', 'bar|baz|'},

{ '', ''},

{ '', ''},

{ 'foo', 'bar|baz||'},

{ '', ''},

{ '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 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
two [http://www.example.com 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]=]},

{ '[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 St. Patrick's Seminary in Menlo Park. He was ordained to the priesthood on June 10, 1933.{{cite news|work=Catholic-Hierarchy.org|title=Bishop Merlin Joseph Guilfoyle|url=http://www.catholic-hierarchy.org/bishop/bguimj.html}} 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 [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 St. Patrick's Seminary in Menlo Park. He was ordained to the priesthood on June 10, 1933.{{cite news|work=Catholic-Hierarchy.org|title=Bishop Merlin Joseph Guilfoyle|url=http://www.catholic-hierarchy.org/bishop/bguimj.html}} 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 [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|', '}}', {

{ 'foobaz]]', 'foobaz'},

{ 'foobaz', 'foobaz'},

{ 'foobat-->bam', 'foobat-->bam'},

{ 'foo[http://abcdefgh]baz', 'foobaz'},

{ 'foo[http://abcdbat', 'foo[http://abcdbat'},

{ 'foo[http://abcdbat', 'foo[http://abcdbat'},

{ 'foo[http://ab{{!((}}cdbat', 'foo[http://ab[[cdbat'},

{ 'foobarbam', 'foobarbam'},

}, {nowiki='yes'})

end

function p:test17_nowiki()

self:preprocess_equals_many('{{delink/sandbox|', '}}', {

{ 'foo', 'foo'},

{ 'foobarbaz', 'foobarbaz'},

{ '[http://www.example.com foo]', '[http://www.example.com foo]'},

{ '{{!((}}foobar]]', 'foobar'},

{ 'foobar', 'foobar'},

{ '[http://www.example.com foo]', '[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&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%bar', 'foo%bar'},

{ 'foo%62bar', 'foo%62bar'},

{ 'foo�bar', 'foo�bar'},

{ 'foo�bar', 'foo�bar'},

{ 'foo"bar', 'foo"bar'},

{ 'foo"bar', 'foo"bar'},

{ 'foo&amp;bar', 'foo&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&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%bar]', 'foo%bar'},

{ '[http://www.example.com foo%62bar]', 'foo%62bar'},

{ '[http://www.example.com foo�bar]', 'foo�bar'},

{ '[http://www.example.com foo�bar]', 'foo�bar'},

{ '[http://www.example.com foo"bar]', 'foo"bar'},

{ '[http://www.example.com foo"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

function p:test21_exotic()

self:preprocess_equals_many('{{delink/sandbox|', '}}', {

{ 'some text Apple]]', 'some text apples and pears' },

{ 'some text Apple]]', 'some text pears' },

{ 'some text Apple]]', 'some text pears' },

{ 'some text Apple]]', 'some text apples and pears' },

{ 'some text Category:fred applespears', 'some text applespears' },

{ 'some text Category:fred applespears', '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