Difference between revisions of "Module:Delink/testcases"

From blackwiki
Jump to navigation Jump to search
blackwiki>Mr. Stradivarius
(try setting the nowiki option)
blackwiki>Mr. Stradivarius
(simplify and use nowiki=yes for all test cases)
Line 2: Line 2:
  
 
function p:test_basic()
 
function p:test_basic()
     self:preprocess_equals('{{#invoke:Delink|delink|[[Apple]]}}', 'Apple')
+
     self:preprocess_equals_many('{{#invoke:Delink|delink|', '}}', {
    self:preprocess_equals('{{#invoke:Delink|delink|[[Orange]]s are dissimilar to [[Apple]]s}}', 'Oranges are dissimilar to Apples')
+
        { '[[Apple]]', 'Apple'},
  self:preprocess_equals('{{#invoke:Delink|delink|[[Apple]]s and [[orange]]s and [[fruit salad|other kinds of fruit]]}}', 'Apples and oranges and other kinds of fruit')
+
        { '[[Orange]]s are dissimilar to [[Apple]]s', 'Oranges are dissimilar to Apples'},
    self:preprocess_equals('{{#invoke:Delink|delink|All [[Gone]] [[wikt:to|]] [[Bed]] [[Now]]}}', 'All Gone to Bed Now')
+
        { '[[Apple]]s and [[orange]]s and [[fruit salad|other kinds of fruit]]', 'Apples and oranges and other kinds of fruit'},
    self:preprocess_equals('{{#invoke:Delink|delink|[[Survey]] of [http://books.google.com Google Books] on [[UK|Britain]]}}', 'Survey of Google Books on Britain')
+
        { '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
 
end
  
 
function p:test_cats_and_interwikis()
 
function p:test_cats_and_interwikis()
     self:preprocess_equals('{{#invoke:Delink|delink|[[Category:Foo]]}}', '')
+
     self:preprocess_equals_many('{{#invoke:Delink|delink|', '}}', {
    self:preprocess_equals('{{#invoke:Delink|delink|[[es:Foo]]}}', '')
+
        { '[[Category:Foo]]', ''},
    self:preprocess_equals('{{#invoke:Delink|delink|[[wikt:Foo]]}}', 'wikt:Foo')
+
        { '[[es:Foo]]', ''},
    self:preprocess_equals('{{#invoke:Delink|delink|[[es:Wikipedia:Políticas]]}}', '')
+
        { '[[wikt:Foo]]', 'wikt:Foo'},
    self:preprocess_equals('{{#invoke:Delink|delink|[[abcd:efgh:ijkl]]}}', 'abcd:efgh:ijkl')
+
        { '[[es:Wikipedia:Políticas]]', ''},
    self:preprocess_equals('{{#invoke:Delink|delink|[[cbk-zam:abcd:efgh]]}}', '')
+
        { '[[abcd:efgh:ijkl]]', 'abcd:efgh:ijkl'},
 +
        { '[[cbk-zam:abcd:efgh]]', ''},
 +
    }, {nowiki='yes'})
 
end
 
end
 
      
 
      
 
function p:test_colontrick()
 
function p:test_colontrick()
     self:preprocess_equals('{{#invoke:Delink|delink|[[:Category:Foo]]}}', 'Category:Foo')
+
     self:preprocess_equals_many('{{#invoke:Delink|delink|', '}}', {
    self:preprocess_equals('{{#invoke:Delink|delink|[[:es:Foo]]}}', 'es:Foo')
+
        { '[[:Category:Foo]]', 'Category:Foo'},
    self:preprocess_equals('{{#invoke:Delink|delink|[[:wikt:Foo]]}}', 'wikt:Foo')
+
        { '[[:es:Foo]]', 'es:Foo'},
    self:preprocess_equals('{{#invoke:Delink|delink|[[:es:Wikipedia:Políticas]]}}', 'es:Wikipedia:Políticas')
+
        { '[[:wikt:Foo]]', 'wikt:Foo'},
    self:preprocess_equals('{{#invoke:Delink|delink|[[:abcd:efgh:ijkl]]}}', 'abcd:efgh:ijkl')
+
        { '[[:es:Wikipedia:Políticas]]', 'es:Wikipedia:Políticas'},
    self:preprocess_equals('{{#invoke:Delink|delink|[[:cbk-zam:abcd:efgh]]}}', 'cbk-zam:abcd:efgh')
+
        { '[[:abcd:efgh:ijkl]]', 'abcd:efgh:ijkl'},
 +
        { '[[:cbk-zam:abcd:efgh]]', 'cbk-zam:abcd:efgh'},
 +
    }, {nowiki='yes'})
 
end
 
end
  
 
function p:test_pipetrick()
 
function p:test_pipetrick()
     self:preprocess_equals('{{#invoke:Delink|delink|[[Pipe (computing)|]]}}', 'Pipe')
+
     self:preprocess_equals_many('{{#invoke:Delink|delink|', '}}', {
    self:preprocess_equals('{{#invoke:Delink|delink|[[Boston, Massachusetts|]]}}', 'Boston')
+
        { '[[Pipe (computing)|]]', 'Pipe'},
    self:preprocess_equals('{{#invoke:Delink|delink|[[Wikipedia:Verifiability|]]}}', 'Verifiability')
+
        { '[[Boston, Massachusetts|]]', 'Boston'},
    self:preprocess_equals('{{#invoke:Delink|delink|[[User:Example|]]}}', 'Example')
+
        { '[[Wikipedia:Verifiability|]]', 'Verifiability'},
    self:preprocess_equals('{{#invoke:Delink|delink|[[Template:Welcome|]]}}', 'Welcome')
+
        { '[[User:Example|]]', 'Example'},
    self:preprocess_equals('{{#invoke:Delink|delink|[[Yours, Mine and Ours (1968 film)|]]}}', 'Yours, Mine and Ours')
+
        { '[[Template:Welcome|]]', 'Welcome'},
    self:preprocess_equals('{{#invoke:Delink|delink|[[:es:Wikipedia:Políticas|]]}}', 'Wikipedia:Políticas')
+
        { '[[Yours, Mine and Ours (1968 film)|]]', 'Yours, Mine and Ours'},
    self:preprocess_equals('{{#invoke:Delink|delink|[[Il Buono, il Brutto, il Cattivo|]]}}', 'Il Buono')
+
        { '[[:es:Wikipedia:Políticas|]]', 'Wikipedia:Políticas'},
    self:preprocess_equals('{{#invoke:Delink|delink|[[Wikipedia:Manual of Style (Persian)|]]}}', 'Manual of Style')
+
        { '[[Il Buono, il Brutto, il Cattivo|]]', 'Il Buono'},
    self:preprocess_equals('{{#invoke:Delink|delink|[[Wikipedia:Manual of Style(Persian)|]]}}', 'Manual of Style')
+
        { '[[Wikipedia:Manual of Style (Persian)|]]', 'Manual of Style'},
    self:preprocess_equals('{{#invoke:Delink|delink|[[foo|bar|]]}}', 'bar|')
+
        { '[[Wikipedia:Manual of Style(Persian)|]]', 'Manual of Style'},
    self:preprocess_equals('{{#invoke:Delink|delink|[[foo||]]}}', '|')
+
        { '[[foo|bar|]]', 'bar|'},
 +
        { '[[foo||]]', '|'},
 +
    }, {nowiki='yes'})
 
end
 
end
  
 
function p:test_reverse_pipetrick()
 
function p:test_reverse_pipetrick()
     self:preprocess_equals('{{#invoke:Delink|delink|[[|foo]]}}', 'foo')
+
     self:preprocess_equals_many('{{#invoke:Delink|delink|', '}}', {
    self:preprocess_equals('{{#invoke:Delink|delink|[[|multiple|pipes]]}}', '[[|multiple|pipes]]')
+
        { '[[|foo]]', 'foo'},
    self:preprocess_equals('{{#invoke:Delink|delink|[[|foo (bar)]]}}', 'foo (bar)')
+
        { '[[|multiple|pipes]]', '[[|multiple|pipes]]'},
    self:preprocess_equals('{{#invoke:Delink|delink|[[|foo, bar (baz)]]}}', 'foo, bar (baz)')
+
        { '[[|foo (bar)]]', 'foo (bar)'},
    self:preprocess_equals('{{#invoke:Delink|delink|[[|simultaneous pipe trick|]]}}', '[[|simultaneous pipe trick|]]')
+
        { '[[|foo, bar (baz)]]', 'foo, bar (baz)'},
 +
        { '[[|simultaneous pipe trick|]]', '[[|simultaneous pipe trick|]]'},
 +
    }, {nowiki='yes'})
 
end
 
end
  
 
function p:test_badlinks()
 
function p:test_badlinks()
     self:preprocess_equals('{{#invoke:Delink|delink|[[<]]}}', '[[<]]')
+
     self:preprocess_equals_many('{{#invoke:Delink|delink|', '}}', {
    self:preprocess_equals('{{#invoke:Delink|delink|[[Category:<]]}}', '[[Category:<]]')
+
        { '[[<]]', '[[<]]'},
    self:preprocess_equals('{{#invoke:Delink|delink|[[:Category:<]]}}', '[[:Category:<]]')
+
        { '[[Category:<]]', '[[Category:<]]'},
    self:preprocess_equals('{{#invoke:Delink|delink|[[:Category:<|Foo]]}}', '[[:Category:<|Foo]]')
+
        { '[[:Category:<]]', '[[:Category:<]]'},
    self:preprocess_equals('{{#invoke:Delink|delink|[[:Category:<|]]}}', '[[:Category:<|]]')
+
        { '[[:Category:<|Foo]]', '[[:Category:<|Foo]]'},
    self:preprocess_equals('{{#invoke:Delink|delink|[[:Category:Foo|<]]}}', '<')
+
        { '[[:Category:<|]]', '[[:Category:<|]]'},
    self:preprocess_equals('{{#invoke:Delink|delink|[[Category:Foo|<]]}}', '')
+
        { '[[:Category:Foo|<]]', '<'},
    self:preprocess_equals('{{#invoke:Delink|delink|[[Foo:Bar|<]]}}', '<')
+
        { '[[Category:Foo|<]]', ''},
    self:preprocess_equals('{{#invoke:Delink|delink|[[Foo:Bar:>]]}}', '[[Foo:Bar:>]]')
+
        { '[[Foo:Bar|<]]', '<'},
    self:preprocess_equals('{{#invoke:Delink|delink|[[es:Wikipedia:<]]}}', '[[es:Wikipedia:<]]')
+
        { '[[Foo:Bar:>]]', '[[Foo:Bar:>]]'},
    self:preprocess_equals('{{#invoke:Delink|delink|[[es:Wikipedia:Foo|<]]}}', '')
+
        { '[[es:Wikipedia:<]]', '[[es:Wikipedia:<]]'},
    self:preprocess_equals('{{#invoke:Delink|delink|[[:es:Wikipedia:<]]}}', '[[:es:Wikipedia:<]]')
+
        { '[[es:Wikipedia:Foo|<]]', ''},
    self:preprocess_equals('{{#invoke:Delink|delink|[[:es:Wikipedia:Foo|<]]}}', '<')
+
        { '[[:es:Wikipedia:<]]', '[[:es:Wikipedia:<]]'},
    self:preprocess_equals('{{#invoke:Delink|delink|[[Foo:Bar:Foo#>]]}}', 'Foo:Bar:Foo#>')
+
        { '[[:es:Wikipedia:Foo|<]]', '<'},
    self:preprocess_equals('{{#invoke:Delink|delink|[[Foo:Bar:Foo>#Baz]]}}', '[[Foo:Bar:Foo>#Baz]]')
+
        { '[[Foo:Bar:Foo#>]]', 'Foo:Bar:Foo#>'},
    self:preprocess_equals('{{#invoke:Delink|delink|[[Foo#Bar>#Baz]]}}', 'Foo#Bar>#Baz')
+
        { '[[Foo:Bar:Foo>#Baz]]', '[[Foo:Bar:Foo>#Baz]]'},
    self:preprocess_equals('{{#invoke:Delink|delink|[[Foo>#Bar#Baz]]}}', '[[Foo>#Bar#Baz]]')
+
        { '[[Foo#Bar>#Baz]]', 'Foo#Bar>#Baz'},
    self:preprocess_equals('{{#invoke:Delink|delink|[[wikt:es:asdf:&#x0000;Template:title#Fragment]]}}', '[[wikt:es:asdf:&#x0000;Template:title#Fragment]]')
+
        { '[[Foo>#Bar#Baz]]', '[[Foo>#Bar#Baz]]'},
 +
        { '[[wikt:es:asdf:&#x0000;Template:title#Fragment]]', '[[wikt:es:asdf:&#x0000;Template:title#Fragment]]'},
 +
    }, {nowiki='yes'})
 
end
 
end
  
 
function p:test_URI_slashes()
 
function p:test_URI_slashes()
     self:preprocess_equals('{{#invoke:Delink|delink|[/foo]}}', '[/foo]')
+
     self:preprocess_equals_many('{{#invoke:Delink|delink|', '}}', {
    self:preprocess_equals('{{#invoke:Delink|delink|[/foo bar]}}', '[/foo bar]')
+
        { '[/foo]', '[/foo]'},
    self:preprocess_equals('{{#invoke:Delink|delink|[//foo]}}', '')
+
        { '[/foo bar]', '[/foo bar]'},
    self:preprocess_equals('{{#invoke:Delink|delink|[//foo bar]}}', 'bar')
+
        { '[//foo]', ''},
    self:preprocess_equals('{{#invoke:Delink|delink|[///foo]}}', '')
+
        { '[//foo bar]', 'bar'},
    self:preprocess_equals('{{#invoke:Delink|delink|[///foo bar]}}', 'bar')
+
        { '[///foo]', ''},
    self:preprocess_equals('{{#invoke:Delink|delink|[////foo]}}', '')
+
        { '[///foo bar]', 'bar'},
    self:preprocess_equals('{{#invoke:Delink|delink|[////foo bar]}}', 'bar')
+
        { '[////foo]', ''},
    self:preprocess_equals('{{#invoke:Delink|delink|[///////////////////////////////////foo]}}', '')
+
        { '[////foo bar]', 'bar'},
    self:preprocess_equals('{{#invoke:Delink|delink|[///////////////////////////////////foo bar]}}', 'bar')
+
        { '[///////////////////////////////////foo]', ''},
 +
        { '[///////////////////////////////////foo bar]', 'bar'},
 +
    }, {nowiki='yes'})
 
end
 
end
  
 
function p:test_URI_prefixes()
 
function p:test_URI_prefixes()
     self:preprocess_equals('{{#invoke:Delink|delink|[://foo]}}', '[://foo]')
+
     self:preprocess_equals_many('{{#invoke:Delink|delink|', '}}', {
    self:preprocess_equals('{{#invoke:Delink|delink|[:://foo]}}', '[:://foo]')
+
        { '[://foo]', '[://foo]'},
    self:preprocess_equals('{{#invoke:Delink|delink|[abcd://]}}', '[abcd://]')
+
        { '[:://foo]', '[:://foo]'},
    self:preprocess_equals('{{#invoke:Delink|delink|[abcd://foo]}}', '[abcd://foo]')
+
        { '[abcd://]', '[abcd://]'},
    self:preprocess_equals('{{#invoke:Delink|delink|[http://]}}', '[http://]')
+
        { '[abcd://foo]', '[abcd://foo]'},
    self:preprocess_equals('{{#invoke:Delink|delink|[http://foo]}}', '')
+
        { '[http://]', '[http://]'},
    self:preprocess_equals('{{#invoke:Delink|delink|[https://]}}', '[https://]')
+
        { '[http://foo]', ''},
    self:preprocess_equals('{{#invoke:Delink|delink|[https://foo]}}', '')
+
        { '[https://]', '[https://]'},
    self:preprocess_equals('{{#invoke:Delink|delink|[ftp://]}}', '[ftp://]')
+
        { '[https://foo]', ''},
    self:preprocess_equals('{{#invoke:Delink|delink|[ftp://foo]}}', '')
+
        { '[ftp://]', '[ftp://]'},
    self:preprocess_equals('{{#invoke:Delink|delink|[gopher://]}}', '[gopher://]')
+
        { '[ftp://foo]', ''},
    self:preprocess_equals('{{#invoke:Delink|delink|[gopher://foo]}}', '')
+
        { '[gopher://]', '[gopher://]'},
    self:preprocess_equals('{{#invoke:Delink|delink|[mailto:]}}', '[mailto:]')
+
        { '[gopher://foo]', ''},
    self:preprocess_equals('{{#invoke:Delink|delink|[mailto:foo]}}', '')
+
        { '[mailto:]', '[mailto:]'},
    self:preprocess_equals('{{#invoke:Delink|delink|[news]}}', '[news]')
+
        { '[mailto:foo]', ''},
    self:preprocess_equals('{{#invoke:Delink|delink|[news at ten]}}', '[news at ten]')
+
        { '[news]', '[news]'},
    self:preprocess_equals('{{#invoke:Delink|delink|[news:]}}', '[news:]')
+
        { '[news at ten]', '[news at ten]'},
    self:preprocess_equals('{{#invoke:Delink|delink|[news: at ten]}}', '[news: at ten]')
+
        { '[news:]', '[news:]'},
    self:preprocess_equals('{{#invoke:Delink|delink|[news:/]}}', '')
+
        { '[news: at ten]', '[news: at ten]'},
    self:preprocess_equals('{{#invoke:Delink|delink|[news:/ at ten]}}', 'at ten')
+
        { '[news:/]', ''},
    self:preprocess_equals('{{#invoke:Delink|delink|[news://]}}', '')
+
        { '[news:/ at ten]', 'at ten'},
    self:preprocess_equals('{{#invoke:Delink|delink|[news://foo]}}', '')
+
        { '[news://]', ''},
    self:preprocess_equals('{{#invoke:Delink|delink|[news://foo at ten]}}', 'at ten')
+
        { '[news://foo]', ''},
    self:preprocess_equals('{{#invoke:Delink|delink|[irc://]}}', '[irc://]')
+
        { '[news://foo at ten]', 'at ten'},
    self:preprocess_equals('{{#invoke:Delink|delink|[irc://foo]}}', '')
+
        { '[irc://]', '[irc://]'},
 +
        { '[irc://foo]', ''},
 +
    }, {nowiki='yes'})
 
end
 
end
  
 
function p:test_URI_special_characters()
 
function p:test_URI_special_characters()
     self:preprocess_equals('{{#invoke:Delink|delink|[:http://foo]}}', '[:http://foo]')
+
     self:preprocess_equals_many('{{#invoke:Delink|delink|', '}}', {
    self:preprocess_equals('{{#invoke:Delink|delink|[http://<foo]}}', '<foo')
+
        { '[:http://foo]', '[:http://foo]'},
    self:preprocess_equals('{{#invoke:Delink|delink|[http://foo"bar]}}', '"bar')
+
        { '[http://<foo]', '<foo'},
    self:preprocess_equals('{{#invoke:Delink|delink|[http://"foo]}}', '[http://"foo]')
+
        { '[http://foo"bar]', '"bar'},
    self:preprocess_equals('{{#invoke:Delink|delink|[http://>foo]}}', '>foo')
+
        { '[http://"foo]', '[http://"foo]'},
    self:preprocess_equals('{{#invoke:Delink|delink|[http://foo<bar]}}', '<bar')
+
        { '[http://>foo]', '>foo'},
    self:preprocess_equals('{{#invoke:Delink|delink|[http://foo>bar]}}', '>bar')
+
        { '[http://foo<bar]', '<bar'},
    self:preprocess_equals('{{#invoke:Delink|delink|[http:// foo]}}', '[http:// foo]')
+
        { '[http://foo>bar]', '>bar'},
 +
        { '[http:// foo]', '[http:// foo]'},
 +
    }, {nowiki='yes'})
 
end
 
end
  
 
function p:test_nesting()
 
function p:test_nesting()
     self:preprocess_equals_preprocess('{{#invoke:Delink|delink|text[[<s name=]]>stricken</s>more text]]}}', 'text[[<s name=]]>stricken</s>more text]]')
+
     self:preprocess_equals_many('{{#invoke:Delink|delink|', '}}', {
    self:preprocess_equals_preprocess('{{#invoke:Delink|delink|text[[<s>stricken</s>more text]]}}', 'text[[<s>stricken</s>more text]]')
+
        { 'text[[<s name=]]>stricken</s>more text]]', 'text[[<s name=]]>stricken</s>more text]]'},
    self:preprocess_equals_preprocess('{{#invoke:Delink|delink|[[outer[[inner]]outer]]}}', '[[outerinnerouter]]')
+
        { 'text[[<s>stricken</s>more text]]', 'text[[<s>stricken</s>more text]]'},
    self:preprocess_equals_preprocess('{{#invoke:Delink|delink|[http://outer outer [[inner]] outer]}}', 'outer inner outer')
+
        { '[[outer[[inner]]outer]]', '[[outerinnerouter]]'},
    self:preprocess_equals_preprocess('{{#invoke:Delink|delink|[[outer[http://inner inner]outer]]}}', '[[outerinnerouter]]')
+
        { '[http://outer outer [[inner]] outer]', 'outer inner outer'},
    self:preprocess_equals_preprocess('{{#invoke:Delink|delink|[[outer[http://inner]outer]]]}}', '[[outerouter]]]')
+
        { '[[outer[http://inner inner]outer]]', '[[outerinnerouter]]'},
 +
        { '[[outer[http://inner]outer]]]', '[[outerouter]]]'},
 +
    }, {nowiki='yes'})
 
end
 
end
  
 
function p:test_multiple_pipes()
 
function p:test_multiple_pipes()
     self:preprocess_equals_preprocess('{{#invoke:Delink|delink|[[foo|bar|baz]]}}', 'bar|baz', {nowiki = 'yes'})
+
     self:preprocess_equals_many('{{#invoke:Delink|delink|', '}}', {
    self:preprocess_equals_preprocess('{{#invoke:Delink|delink|[[foo|bar|baz|]]}}', 'bar|baz|', {nowiki = 'yes'})
+
        { '[[foo|bar|baz]]', 'bar|baz'},
    self:preprocess_equals_preprocess('{{#invoke:Delink|delink|[[|foo|bar|baz]]}}', '[[|foo|bar|baz]]', {nowiki = 'yes'})
+
        { '[[foo|bar|baz|]]', 'bar|baz|'},
    self:preprocess_equals_preprocess('{{#invoke:Delink|delink|[[|foo|bar|baz|]]}}', '[[|foo|bar|baz|]]', {nowiki = 'yes'})
+
        { '[[|foo|bar|baz]]', '[[|foo|bar|baz]]'},
    self:preprocess_equals_preprocess('{{#invoke:Delink|delink|[[foo|bar|baz||]]}}', 'bar|baz||', {nowiki = 'yes'})
+
        { '[[|foo|bar|baz|]]', '[[|foo|bar|baz|]]'},
    self:preprocess_equals_preprocess('{{#invoke:Delink|delink|[[||foobarbaz]]}}', '[[||foobarbaz]]', {nowiki = 'yes'})
+
        { '[[foo|bar|baz||]]', 'bar|baz||'},
    self:preprocess_equals_preprocess('{{#invoke:Delink|delink|[[foobarbaz||]]}}', '|', {nowiki = 'yes'})
+
        { '[[||foobarbaz]]', '[[||foobarbaz]]'},
 +
        { '[[foobarbaz||]]', '|'},
 +
    }, {nowiki='yes'})
 
end
 
end
  
 
function p:test_http_links()
 
function p:test_http_links()
     self:preprocess_equals('{{#invoke:Delink|delink|[http]}}', '[http]')
+
     self:preprocess_equals_many('{{#invoke:Delink|delink|', '}}', {
    self:preprocess_equals('{{#invoke:Delink|delink|[http:foo]}}', '[http:foo]')
+
        { '[http]', '[http]'},
    self:preprocess_equals('{{#invoke:Delink|delink|[http:]}}', '[http:]')
+
        { '[http:foo]', '[http:foo]'},
    self:preprocess_equals('{{#invoke:Delink|delink|[http:foo]}}', '[http:foo]')
+
        { '[http:]', '[http:]'},
    self:preprocess_equals('{{#invoke:Delink|delink|[http:/]}}', '[http:/]')
+
        { '[http:foo]', '[http:foo]'},
    self:preprocess_equals('{{#invoke:Delink|delink|[http:/foo]}}', '[http:/foo]')
+
        { '[http:/]', '[http:/]'},
    self:preprocess_equals('{{#invoke:Delink|delink|[http://]}}', '[http://]')
+
        { '[http:/foo]', '[http:/foo]'},
    self:preprocess_equals('{{#invoke:Delink|delink|[http://foo]}}', '')
+
        { '[http://]', '[http://]'},
 +
        { '[http://foo]', ''},
 +
    }, {nowiki='yes'})
 
end
 
end
  
 
return p
 
return p

Revision as of 19:07, 3 April 2013

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('{{#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('{{#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]]', ''},
    }, {nowiki='yes'})
end
    
function p:test_colontrick()
    self:preprocess_equals_many('{{#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'},
    }, {nowiki='yes'})
end

function p:test_pipetrick()
    self:preprocess_equals_many('{{#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('{{#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('{{#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]]'},
    }, {nowiki='yes'})
end

function p:test_URI_slashes()
    self:preprocess_equals_many('{{#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('{{#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('{{#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('{{#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('{{#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('{{#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

return p