Module:Delink/testcases

From blackwiki
< Module:Delink
Revision as of 08:52, 5 April 2013 by blackwiki>Mr. Stradivarius (Add nowiki for the nowiki options. This will probably break things, but they are broken already, so...)
Jump to navigation Jump to search

Documentation for this module may be created at Module:Delink/testcases/doc

local p = require('Module:UnitTests')

function p:test_basic()
    self:preprocess_equals_many('{{<includeonly>safesubst:</includeonly>#invoke:Delink|delink|', '}}', {
        { '[[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:test_cats_and_interwikis()
    self:preprocess_equals_many('{{<includeonly>safesubst:</includeonly>#invoke:Delink|delink|', '}}', {
        { '[[Category: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:test_colontrick()
    self:preprocess_equals_many('{{<includeonly>safesubst:</includeonly>#invoke:Delink|delink|', '}}', {
        { '[[: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:test_pipetrick()
    self:preprocess_equals_many('{{<includeonly>safesubst:</includeonly>#invoke:Delink|delink|', '}}', {
        { '[[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||]]', '|'},
    }, {nowiki='yes'})
end

function p:test_reverse_pipetrick()
    self:preprocess_equals_many('{{<includeonly>safesubst:</includeonly>#invoke:Delink|delink|', '}}', {
        { '[[|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:test_badlinks()
    self:preprocess_equals_many('{{<includeonly>safesubst:</includeonly>#invoke:Delink|delink|', '}}', {
        { '[[<]]', '[[<]]'},
        { '[[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:test_URI_slashes()
    self:preprocess_equals_many('{{<includeonly>safesubst:</includeonly>#invoke:Delink|delink|', '}}', {
        { '[/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:test_URI_prefixes()
    self:preprocess_equals_many('{{<includeonly>safesubst:</includeonly>#invoke:Delink|delink|', '}}', {
        { '[://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:test_URI_special_characters()
    self:preprocess_equals_many('{{<includeonly>safesubst:</includeonly>#invoke:Delink|delink|', '}}', {
        { '[: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:test_nesting()
    self:preprocess_equals_many('{{<includeonly>safesubst:</includeonly>#invoke:Delink|delink|', '}}', {
        { '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:test_multiple_pipes()
    self:preprocess_equals_many('{{<includeonly>safesubst:</includeonly>#invoke:Delink|delink|', '}}', {
        { '[[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:test_http_links()
    self:preprocess_equals_many('{{<includeonly>safesubst:</includeonly>#invoke:Delink|delink|', '}}', {
        { '[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:test_whitespace()
    self:preprocess_equals_many('{{<includeonly>safesubst:</includeonly>#invoke:Delink|delink|', '}}', {
        { '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]]]=] },
        { [=[[http://www.example.com 
example]]=], '[http://www.example.com example]'},
        { [=[[http://www.example.com

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

example]]=] },
        { '[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:test_full_paragraphs()
    self:preprocess_equals_many('{{<includeonly>safesubst:</includeonly>#invoke:Delink|delink|', '}}', {
        {
            [==[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:test_html_comments()
    self:preprocess_equals_many('{{<includeonly>safesubst:</includeonly>#invoke:Delink|delink|', '}}', {
        { '[[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:test_nowiki()
    self:preprocess_equals_many('{{<includeonly>safesubst:</includeonly>#invoke:Delink|delink|', '}}', {
            { '<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

return p