Difference between revisions of "Module:Delink/testcases"
Jump to navigation
Jump to search
blackwiki>Mr. Stradivarius (simplify and use nowiki=yes for all test cases) |
blackwiki>Mr. Stradivarius (whitespace test) |
||
Line 174: | Line 174: | ||
{ '[http://]', '[http://]'}, | { '[http://]', '[http://]'}, | ||
{ '[http://foo]', ''}, | { '[http://foo]', ''}, | ||
+ | }, {nowiki='yes'}) | ||
+ | end | ||
+ | |||
+ | function p:test_whitespace() | ||
+ | self:preprocess_equals_many('{{#invoke:Delink|delink|', '}}', { | ||
+ | { 'xx[[ fruit salad | many kinds of fruit ]]xx', 'xx many kinds of fruit xx'}, | ||
}, {nowiki='yes'}) | }, {nowiki='yes'}) | ||
end | end | ||
return p | return p |
Revision as of 22:15, 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:�Template:title#Fragment]]', '[[wikt:es:asdf:�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
function p:test_whitespace()
self:preprocess_equals_many('{{#invoke:Delink|delink|', '}}', {
{ 'xx[[ fruit salad | many kinds of fruit ]]xx', 'xx many kinds of fruit xx'},
}, {nowiki='yes'})
end
return p