Jump to content

Module:Urltowiki/testcases

From Wikipedia, the free encyclopedia
-- Unit tests for [[Module:Urltowiki]]. Click talk page to run tests.
local p = require('Module:UnitTests')

function p:test_simple()
    self:preprocess_equals_many('{{#invoke:Urltowiki/sandbox|urlToWiki|', '}}', {
        {'http://en.wiki.x.io/wiki/Banana', '[[Banana]]'},
        {'http://en.wiki.x.io/wiki/English_language', '[[English language]]'},
        {'http://en.wiki.x.io/wiki/Module:UnitTests', '[[Module:UnitTests]]'},
        {'http://en.wiki.x.io/wiki/Wikipedia_talk:Articles_for_deletion', '[[Wikipedia talk:Articles for deletion]]'},
    })
end

function p:test_index_php()
    self:preprocess_equals_many('{{#invoke:Urltowiki/sandbox|urlToWiki|', '}}', {
        {'1=http://en.wiki.x.io/w/index.php?title=Banana', '[[Banana]]'},
        {'1=http://en.wiki.x.io/w/index.php?title=English_language', '[[English language]]'},
        {'1=http://en.wiki.x.io/w/index.php?title=Module:UnitTests', '[[Module:UnitTests]]'},
        {'1=http://en.wiki.x.io/w/index.php?title=Wikipedia_talk:Articles_for_deletion', '[[Wikipedia talk:Articles for deletion]]'},
    })
end

function p:test_url_parameter()
    self:preprocess_equals_many('{{#invoke:Urltowiki/sandbox|urlToWiki|', '}}', {
        {'url=http://en.wiki.x.io/w/index.php?title=Banana', '[[Banana]]'},
        {'url=http://en.wiki.x.io/w/index.php?title=English_language', '[[English language]]'},
        {'url=http://en.wiki.x.io/w/index.php?title=Module:UnitTests', '[[Module:UnitTests]]'},
        {'url=http://en.wiki.x.io/w/index.php?title=Wikipedia_talk:Articles_for_deletion', '[[Wikipedia talk:Articles for deletion]]'},
    })
end

function p:test_partial_urls()
    self:preprocess_equals_many('{{#invoke:Urltowiki/sandbox|urlToWiki|', '}}', {
        {'Banana', '[[Banana]]'},
        {'English_language', '[[English language]]'},
        {'Module:UnitTests', '[[Module:UnitTests]]'},
        {'Wikipedia_talk:Articles_for_deletion', '[[Wikipedia talk:Articles for deletion]]'},
    })
end

function p:test_fragments()
    self:preprocess_equals_many('{{#invoke:Urltowiki/sandbox|urlToWiki|', '}}', {
        {'http://en.wiki.x.io/wiki/Banana#Etymology', '[[Banana#Etymology]]'},
        {'http://en.wiki.x.io/wiki/English_language#Classification_and_related_languages', '[[English language#Classification and related languages]]'},
        {'http://en.wiki.x.io/wiki/Module:UnitTests#preprocess_equals_many', '[[Module:UnitTests#preprocess equals many]]'},
        {'http://en.wiki.x.io/wiki/Wikipedia_talk:Articles_for_deletion#Foo_bar', '[[Wikipedia talk:Articles for deletion#Foo bar]]'},
        {'http://en.wiki.x.io/wiki/Wikipedia_talk:Articles_for_deletion/Archive_1#Proposed_reorganization', '[[Wikipedia talk:Articles for deletion/Archive 1#Proposed reorganization]]'},
        {'1=http://en.wiki.x.io/w/index.php?title=Banana#Etymology', '[[Banana#Etymology]]'},
        {'1=http://en.wiki.x.io/w/index.php?title=English_language#Classification_and_related_languages', '[[English language#Classification and related languages]]'},
        {'1=http://en.wiki.x.io/w/index.php?title=Module:UnitTests#preprocess_equals_many', '[[Module:UnitTests#preprocess equals many]]'},
        {'1=http://en.wiki.x.io/w/index.php?title=Wikipedia_talk:Articles_for_deletion#Foo_bar', '[[Wikipedia talk:Articles for deletion#Foo bar]]'},
        {'1=http://en.wiki.x.io/w/index.php?title=Wikipedia_talk:Articles_for_deletion/Archive_1#Proposed_reorganization', '[[Wikipedia talk:Articles for deletion/Archive 1#Proposed reorganization]]'},
        {'Banana#Etymology', '[[Banana#Etymology]]'},
        {'English_language#Classification_and_related_languages', '[[English language#Classification and related languages]]'},
        {'Module:UnitTests#preprocess_equals_many', '[[Module:UnitTests#preprocess equals many]]'},
        {'Wikipedia_talk:Articles_for_deletion#Foo_bar', '[[Wikipedia talk:Articles for deletion#Foo bar]]'},
        {'Wikipedia_talk:Articles_for_deletion/Archive_1#Proposed_reorganization', '[[Wikipedia talk:Articles for deletion/Archive 1#Proposed reorganization]]'},
    })
end

function p:test_random_sites()
    self:preprocess_equals_many('{{#invoke:Urltowiki/sandbox|urlToWiki|', '}}', {
        {'http://www.theguardian.com/tv-and-radio/2013/sep/22/the-simpsons-secret-formula-maths-simon-singh', 'http://www.theguardian.com/tv-and-radio/2013/sep/22/the-simpsons-secret-formula-maths-simon-singh'},
        {'1=http://www.youtube.com/watch?v=AxTiaInrLW4', 'http://www.youtube.com/watch?v=AxTiaInrLW4'},
        {'http://www.ietf.org/rfc/rfc3092.txt', 'http://www.ietf.org/rfc/rfc3092.txt'},
    })
end

function p:test_actions()
    self:preprocess_equals_many('{{#invoke:Urltowiki/sandbox|urlToWiki|', '}}', {
        {'1=http://en.wiki.x.io/w/index.php?title=Wikipedia%3AArticles_for_deletion&action=history', '[[Wikipedia:Articles for deletion]]'},
        {'1=http://en.wiki.x.io/w/index.php?title=Wikipedia:Articles_for_deletion&offset=20121106111840&action=history', '[[Wikipedia:Articles for deletion]]'},
        {'1=http://en.wiki.x.io/w/index.php?title=Wikipedia:Articles_for_deletion&action=edit', '[[Wikipedia:Articles for deletion]]'},
    })
end

function p:test_interwikis()
    self:preprocess_equals_many('{{#invoke:Urltowiki/sandbox|urlToWiki|', '}}', {
        {'https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual', '[[mw:Extension:Scribunto/Lua reference manual]]'},
        {'https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Lua_language', '[[mw:Extension:Scribunto/Lua reference manual#Lua language]]'},
        {'1=https://www.mediawiki.org/w/index.php?title=Extension:Scribunto/Lua_reference_manual#Lua_language', '[[mw:Extension:Scribunto/Lua reference manual#Lua language]]'},
        {'http://meta.wikimedia.org/wiki/Translation_requests/WMF', '[[m:Translation requests/WMF]]'},
    })
end

function p:test_colon_trick()
    self:preprocess_equals_many('{{#invoke:Urltowiki/sandbox|urlToWiki|', '}}', {
        {'http://en.wiki.x.io/wiki/Category:Wikipedians', '[[:Category:Wikipedians]]'},
        {'http://en.wiki.x.io/wiki/File:Example.png', '[[:File:Example.png]]'},
        {'http://en.wiki.x.io/wiki/Image:Example.png', '[[:Image:Example.png]]'},
        {'http://en.wiki.x.io/wiki/Wikipedia_talk:Articles_for_deletion', '[[Wikipedia talk:Articles for deletion]]'},
        {'http://es.wiki.x.io/wiki/Milord_%28tratamiento%29', '[[:es:Milord (tratamiento)]]'},
        {'http://es.wiki.x.io/wiki/Wikipedia:Cartelera_de_acontecimientos', '[[:es:Wikipedia:Cartelera de acontecimientos]]'},
    })
end

function p:test_no_link()
    self:preprocess_equals_many('{{#invoke:Urltowiki/sandbox|urlToWiki|', '}}', {
        {'http://en.wiki.x.io/wiki/Banana|link=no', 'Banana'},
        {'http://en.wiki.x.io/wiki/English_language|link=no', 'English language'},
        {'http://en.wiki.x.io/wiki/Module:UnitTests|link=no', 'Module:UnitTests'},
        {'http://en.wiki.x.io/wiki/Wikipedia_talk:Articles_for_deletion|link=no', 'Wikipedia talk:Articles for deletion'},
        {'1=http://en.wiki.x.io/w/index.php?title=Banana|link=no', 'Banana'},
        {'1=http://en.wiki.x.io/w/index.php?title=English_language|link=no', 'English language'},
        {'1=http://en.wiki.x.io/w/index.php?title=Module:UnitTests|link=no', 'Module:UnitTests'},
        {'1=http://en.wiki.x.io/w/index.php?title=Wikipedia_talk:Articles_for_deletion|link=no', 'Wikipedia talk:Articles for deletion'},
        {'Banana|link=no', 'Banana'},
        {'English_language|link=no', 'English language'},
        {'Module:UnitTests|link=no', 'Module:UnitTests'},
        {'Wikipedia_talk:Articles_for_deletion|link=no', 'Wikipedia talk:Articles for deletion'},
        {'http://en.wiki.x.io/wiki/Category:Wikipedians|link=no', 'Category:Wikipedians'},
        {'http://en.wiki.x.io/wiki/File:Example.png|link=no', 'File:Example.png'},
        {'http://en.wiki.x.io/wiki/Image:Example.png|link=no', 'Image:Example.png'},
        {'http://en.wiki.x.io/wiki/Wikipedia_talk:Articles_for_deletion|link=no', 'Wikipedia talk:Articles for deletion'},
        {'http://es.wiki.x.io/wiki/Milord_%28tratamiento%29|link=no', 'es:Milord (tratamiento)'},
        {'http://es.wiki.x.io/wiki/Wikipedia:Cartelera_de_acontecimientos|link=no', 'es:Wikipedia:Cartelera de acontecimientos'},
        {'http://en.wiki.x.io/wiki/English_language|link=no|display=Foo', 'English language'},
        {'1=http://en.wiki.x.io/w/index.php?title=English_language|link=no|display=Foo', 'English language'},
        {'Banana|link=no|display=Foo', 'Banana'},
        {'http://es.wiki.x.io/wiki/Milord_%28tratamiento%29|link=no|display=Foo', 'es:Milord (tratamiento)'},
    })
end

function p:test_no_colon_trick()
    self:preprocess_equals_many('{{#invoke:Urltowiki/sandbox|urlToWiki|', '}}', {
        {'http://en.wiki.x.io/wiki/Category:Wikipedians|colontrick=no', '[[Category:Wikipedians]]'},
        {'http://en.wiki.x.io/wiki/File:Example.png|colontrick=no', '[[File:Example.png]]'},
        {'http://en.wiki.x.io/wiki/Image:Example.png|colontrick=no', '[[Image:Example.png]]'},
        {'http://en.wiki.x.io/wiki/Wikipedia_talk:Articles_for_deletion|colontrick=no', '[[Wikipedia talk:Articles for deletion]]'},
        {'http://es.wiki.x.io/wiki/Milord_%28tratamiento%29|colontrick=no', '[[es:Milord (tratamiento)]]'},
        {'http://es.wiki.x.io/wiki/Wikipedia:Cartelera_de_acontecimientos|colontrick=no', '[[es:Wikipedia:Cartelera de acontecimientos]]'},
    }, {nowiki = true})
end

function p:test_display()
    self:preprocess_equals_many('{{#invoke:Urltowiki/sandbox|urlToWiki|', '}}', {
        {'http://en.wiki.x.io/wiki/Banana|display=Foo', '[[Banana|Foo]]'},
        {'http://en.wiki.x.io/wiki/English_language|display=Foo', '[[English language|Foo]]'},
        {'http://en.wiki.x.io/wiki/Module:UnitTests|display=Foo', '[[Module:UnitTests|Foo]]'},
        {'http://en.wiki.x.io/wiki/Wikipedia_talk:Articles_for_deletion|display=Foo', '[[Wikipedia talk:Articles for deletion|Foo]]'},
        {'1=http://en.wiki.x.io/w/index.php?title=Banana|display=Foo', '[[Banana|Foo]]'},
        {'1=http://en.wiki.x.io/w/index.php?title=English_language|display=Foo', '[[English language|Foo]]'},
        {'1=http://en.wiki.x.io/w/index.php?title=Module:UnitTests|display=Foo', '[[Module:UnitTests|Foo]]'},
        {'1=http://en.wiki.x.io/w/index.php?title=Wikipedia_talk:Articles_for_deletion|display=Foo', '[[Wikipedia talk:Articles for deletion|Foo]]'},
        {'Banana|display=Foo', '[[Banana|Foo]]'},
        {'English_language|display=Foo', '[[English language|Foo]]'},
        {'Module:UnitTests|display=Foo', '[[Module:UnitTests|Foo]]'},
        {'Wikipedia_talk:Articles_for_deletion|display=Foo', '[[Wikipedia talk:Articles for deletion|Foo]]'},
        {'http://en.wiki.x.io/wiki/Banana#Etymology|display=Foo', '[[Banana#Etymology|Foo]]'},
        {'http://en.wiki.x.io/wiki/English_language#Classification_and_related_languages|display=Foo', '[[English language#Classification and related languages|Foo]]'},
        {'http://en.wiki.x.io/wiki/Module:UnitTests#preprocess_equals_many|display=Foo', '[[Module:UnitTests#preprocess equals many|Foo]]'},
        {'http://en.wiki.x.io/wiki/Wikipedia_talk:Articles_for_deletion#Foo_bar|display=Foo', '[[Wikipedia talk:Articles for deletion#Foo bar|Foo]]'},
        {'http://en.wiki.x.io/wiki/Wikipedia_talk:Articles_for_deletion/Archive_1#Proposed_reorganization|display=Foo', '[[Wikipedia talk:Articles for deletion/Archive 1#Proposed reorganization|Foo]]'},
        {'1=http://en.wiki.x.io/w/index.php?title=Banana#Etymology|display=Foo', '[[Banana#Etymology|Foo]]'},
        {'1=http://en.wiki.x.io/w/index.php?title=English_language#Classification_and_related_languages|display=Foo', '[[English language#Classification and related languages|Foo]]'},
        {'1=http://en.wiki.x.io/w/index.php?title=Module:UnitTests#preprocess_equals_many|display=Foo', '[[Module:UnitTests#preprocess equals many|Foo]]'},
        {'1=http://en.wiki.x.io/w/index.php?title=Wikipedia_talk:Articles_for_deletion#Foo_bar|display=Foo', '[[Wikipedia talk:Articles for deletion#Foo bar|Foo]]'},
        {'1=http://en.wiki.x.io/w/index.php?title=Wikipedia_talk:Articles_for_deletion/Archive_1#Proposed_reorganization|display=Foo', '[[Wikipedia talk:Articles for deletion/Archive 1#Proposed reorganization|Foo]]'},
        {'Banana#Etymology|display=Foo', '[[Banana#Etymology|Foo]]'},
        {'English_language#Classification_and_related_languages|display=Foo', '[[English language#Classification and related languages|Foo]]'},
        {'Module:UnitTests#preprocess_equals_many|display=Foo', '[[Module:UnitTests#preprocess equals many|Foo]]'},
        {'Wikipedia_talk:Articles_for_deletion#Foo_bar|display=Foo', '[[Wikipedia talk:Articles for deletion#Foo bar|Foo]]'},
        {'Wikipedia_talk:Articles_for_deletion/Archive_1#Proposed_reorganization|display=Foo', '[[Wikipedia talk:Articles for deletion/Archive 1#Proposed reorganization|Foo]]'},
    })
end

function p:test_display_no_colon_trick()
    self:preprocess_equals_many('{{#invoke:Urltowiki/sandbox|urlToWiki|', '}}', {
        {'http://en.wiki.x.io/wiki/Category:Wikipedians|colontrick=no|display=Foo', '[[Category:Wikipedians|Foo]]'},
        {'http://en.wiki.x.io/wiki/File:Example.png|colontrick=no|display=Foo', '[[File:Example.png|Foo]]'},
        {'http://en.wiki.x.io/wiki/Image:Example.png|colontrick=no|display=Foo', '[[Image:Example.png|Foo]]'},
        {'http://en.wiki.x.io/wiki/Wikipedia_talk:Articles_for_deletion|colontrick=no|display=Foo', '[[Wikipedia talk:Articles for deletion|Foo]]'},
        {'http://es.wiki.x.io/wiki/Milord_%28tratamiento%29|colontrick=no|display=Foo', '[[es:Milord (tratamiento)|Foo]]'},
        {'http://es.wiki.x.io/wiki/Wikipedia:Cartelera_de_acontecimientos|colontrick=no|display=Foo', '[[es:Wikipedia:Cartelera de acontecimientos|Foo]]'},
    }, {nowiki = true})
end

function p:test_no_section()
    self:preprocess_equals_many('{{#invoke:Urltowiki/sandbox|urlToWiki|', '}}', {
        {'http://en.wiki.x.io/wiki/Banana|section=no', '[[Banana]]'},
        {'http://en.wiki.x.io/wiki/English_language|section=no', '[[English language]]'},
        {'http://en.wiki.x.io/wiki/Module:UnitTests|section=no', '[[Module:UnitTests]]'},
        {'http://en.wiki.x.io/wiki/Wikipedia_talk:Articles_for_deletion|section=no', '[[Wikipedia talk:Articles for deletion]]'},
        {'1=http://en.wiki.x.io/w/index.php?title=Banana|section=no', '[[Banana]]'},
        {'1=http://en.wiki.x.io/w/index.php?title=English_language|section=no', '[[English language]]'},
        {'1=http://en.wiki.x.io/w/index.php?title=Module:UnitTests|section=no', '[[Module:UnitTests]]'},
        {'1=http://en.wiki.x.io/w/index.php?title=Wikipedia_talk:Articles_for_deletion|section=no', '[[Wikipedia talk:Articles for deletion]]'},
        {'Banana|section=no', '[[Banana]]'},
        {'English_language|section=no', '[[English language]]'},
        {'Module:UnitTests|section=no', '[[Module:UnitTests]]'},
        {'Wikipedia_talk:Articles_for_deletion|section=no', '[[Wikipedia talk:Articles for deletion]]'},
        {'http://en.wiki.x.io/wiki/Banana#Etymology|section=no', '[[Banana]]'},
        {'http://en.wiki.x.io/wiki/English_language#Classification_and_related_languages|section=no', '[[English language]]'},
        {'http://en.wiki.x.io/wiki/Module:UnitTests#preprocess_equals_many|section=no', '[[Module:UnitTests]]'},
        {'http://en.wiki.x.io/wiki/Wikipedia_talk:Articles_for_deletion#Foo_bar|section=no', '[[Wikipedia talk:Articles for deletion]]'},
        {'http://en.wiki.x.io/wiki/Wikipedia_talk:Articles_for_deletion/Archive_1#Proposed_reorganization|section=no', '[[Wikipedia talk:Articles for deletion/Archive 1]]'},
        {'1=http://en.wiki.x.io/w/index.php?title=Banana#Etymology|section=no', '[[Banana]]'},
        {'1=http://en.wiki.x.io/w/index.php?title=English_language#Classification_and_related_languages|section=no', '[[English language]]'},
        {'1=http://en.wiki.x.io/w/index.php?title=Module:UnitTests#preprocess_equals_many|section=no', '[[Module:UnitTests]]'},
        {'1=http://en.wiki.x.io/w/index.php?title=Wikipedia_talk:Articles_for_deletion#Foo_bar|section=no', '[[Wikipedia talk:Articles for deletion]]'},
        {'1=http://en.wiki.x.io/w/index.php?title=Wikipedia_talk:Articles_for_deletion/Archive_1#Proposed_reorganization|section=no', '[[Wikipedia talk:Articles for deletion/Archive 1]]'},
        {'Banana#Etymology|section=no', '[[Banana]]'},
        {'English_language#Classification_and_related_languages|section=no', '[[English language]]'},
        {'Module:UnitTests#preprocess_equals_many|section=no', '[[Module:UnitTests]]'},
        {'Wikipedia_talk:Articles_for_deletion#Foo_bar|section=no', '[[Wikipedia talk:Articles for deletion]]'},
        {'Wikipedia_talk:Articles_for_deletion/Archive_1#Proposed_reorganization|section=no', '[[Wikipedia talk:Articles for deletion/Archive 1]]'},
    })
end

function p:test_funky_characters()
    self:preprocess_equals_many('{{#invoke:Urltowiki/sandbox|urlToWiki|', '}}', {
        {'http://en.wiki.x.io/wiki/Wikipedia:Village_pump_%28policy%29/Archive_102#Using_.7B.7BComment.7D.7D_on_articles', '[[Wikipedia:Village pump (policy)/Archive 102#Using %7B%7BComment%7D%7D on articles]]'},
        {'http://es.wikivoyage.org/wiki/Bogot%C3%A1#En_avi.C3.B3n', '[[voy:es:Bogotá#En avión]]'},
        {'http://ja.wiki.x.io/wiki/%E6%BC%A2%E5%AD%97', '[[:ja:漢字]]'},
    })
end

function p:test_identical_page_and_display()
    self:preprocess_equals_many('{{#invoke:Urltowiki/sandbox|urlToWiki|', '}}', {
        {'http://en.wiki.x.io/wiki/Banana|Banana', '[[Banana]]'},
        {'http://en.wiki.x.io/wiki/Banana|banana', '[[banana]]'},
        {'http://en.wiki.x.io/wiki/Category:Foo|Category:Foo', '[[:Category:Foo]]'},
    })
end

return p