2014-04-05

created

New page

-- Unit tests for [[Module:Pagetype]]. Click talk page to run tests.

local p = require('Module:UnitTests')

function p:test_current_page()

self:preprocess_equals_many('{{#invoke:pagetype/sandbox|main', '}}', {

{'', 'module'},

{'|module=no', 'page'},

{'|module=foo', 'foo'},

})

end

function p:test_spaces()

self:preprocess_equals_many('{{#invoke:pagetype/sandbox|main', '}}', {

{'', 'module'},

{'|module= no ', 'page'},

{'|module= foo ', 'foo'},

{'|page= UK |redirect= No ', 'article'},

})

end

function p:test_all_namespaces()

self:preprocess_equals_many('{{#invoke:pagetype/sandbox|main', '}}', {

{'|page=UK', 'redirect'},

{'|page=Talk:UK', 'redirect'},

{'|page=United Kingdom', 'article'},

{'|page=Talk:United Kingdom', 'article'},

{'|page=User:Example', 'page'},

{'|page=User talk:Example', 'page'},

{'|page=Wikisource:Namespace', 'page'},

{'|page=Wikisource talk:Namespace', 'page'},

{'|page=Project:Namespace', 'page'},

{'|page=Project talk:Namespace', 'page'},

{'|page=WS:Namespace', 'page'},

{'|page=WT:Namespace', 'page'},

{'|page=File:Example.jpg', 'file'},

{'|page=File talk:Example.jpg', 'file'},

{'|page=Image:Example.jpg', 'file'},

{'|page=Image talk:Example.jpg', 'file'},

{'|page=MediaWiki:Watchlist-details', 'page'},

{'|page=MediaWiki talk:Watchlist-details', 'page'},

{'|page=Template:Pagetype', 'template'},

{'|page=Template talk:Pagetype', 'template'},

{'|page=Help:Contents', 'page'},

{'|page=Help talk:Contents', 'page'},

{'|page=Category:Wikisourcerers', 'category'},

{'|page=Category talk:Wikisourcerers', 'category'},

{'|page=Portal:Arts', 'page'},

{'|page=Portal talk:Arts', 'page'},

{'|page=Author:Countries', 'author'},

{'|page=Author talk:Countries', 'author'},

{'|page=Page:Example', 'page'},

{'|page=Page talk:Example', 'page'},

{'|page=Index:Foo', 'page'},

{'|page=Index talk:Foo', 'page'},

{'|page=Translation:Foo', 'page'},

{'|page=Translation talk:Foo', 'page'},

{'|page=Special:PrefixIndex', 'page'},

{'|page=Media:Example.jpg', 'page'},

})

end

function p:test_defaultns_none()

self:preprocess_equals_many('{{#invoke:pagetype/sandbox|main', '}}', {

{'|page=UK|defaultns=none', 'redirect'},

{'|page=Talk:UK|defaultns=none', 'redirect'},

{'|page=United Kingdom|defaultns=none', 'page'},

{'|page=Talk:United Kingdom|defaultns=none', 'page'},

{'|page=User:Example|defaultns=none', 'page'},

{'|page=User talk:Example|defaultns=none', 'page'},

{'|page=Wikisource:Namespace|defaultns=none', 'page'},

{'|page=Wikisource talk:Namespace|defaultns=none', 'page'},

{'|page=Project:Namespace|defaultns=none', 'page'},

{'|page=Project talk:Namespace|defaultns=none', 'page'},

{'|page=WP:Namespace|defaultns=none', 'page'},

{'|page=WT:Namespace|defaultns=none', 'page'},

{'|page=File:Example.jpg|defaultns=none', 'page'},

{'|page=File talk:Example.jpg|defaultns=none', 'page'},

{'|page=Image:Example.jpg|defaultns=none', 'page'},

{'|page=Image talk:Example.jpg|defaultns=none', 'page'},

{'|page=MediaWiki:Watchlist-details|defaultns=none', 'page'},

{'|page=MediaWiki talk:Watchlist-details|defaultns=none', 'page'},

{'|page=Template:Pagetype|defaultns=none', 'page'},

{'|page=Template talk:Pagetype|defaultns=none', 'page'},

{'|page=Help:Contents|defaultns=none', 'page'},

{'|page=Help talk:Contents|defaultns=none', 'page'},

{'|page=Category:Wikisourcerers|defaultns=none', 'page'},

{'|page=Category talk:Wikisourcerers|defaultns=none', 'page'},

{'|page=Portal:Arts|defaultns=none', 'page'},

{'|page=Portal talk:Arts|defaultns=none', 'page'},

{'|page=Author:Countries|defaultns=none', 'page'},

{'|page=Author talk:Countries|defaultns=none', 'page'},

{'|page=Page:Example|defaultns=none', 'page'},

{'|page=Page talk:Example|defaultns=none', 'page'},

{'|page=Index:Foo|defaultns=none', 'page'},

{'|page=Index talk:Foo|defaultns=none', 'page'},

{'|page=Translation:Foo|defaultns=none', 'page'},

{'|page=Translation talk:Foo|defaultns=none', 'page'},

{'|page=Special:PrefixIndex|defaultns=none', 'page'},

{'|page=Media:Example.jpg|defaultns=none', 'page'},

})

end

function p:test_defaultns_extended()

self:preprocess_equals_many('{{#invoke:pagetype/sandbox|main', '}}', {

{'|page=UK|defaultns=extended', 'redirect'},

{'|page=Talk:UK|defaultns=extended', 'redirect'},

{'|page=United Kingdom|defaultns=extended', 'article'},

{'|page=Talk:United Kingdom|defaultns=extended', 'article'},

{'|page=User:Example|defaultns=extended', 'user page'},

{'|page=User talk:Example|defaultns=extended', 'user page'},

{'|page=Wikisource:Namespace|defaultns=extended', 'project page'},

{'|page=Wikisource talk:Namespace|defaultns=extended', 'project page'},

{'|page=Project:Namespace|defaultns=extended', 'project page'},

{'|page=Project talk:Namespace|defaultns=extended', 'project page'},

{'|page=WP:Namespace|defaultns=extended', 'project page'},

{'|page=WT:Namespace|defaultns=extended', 'project page'},

{'|page=File:Example.jpg|defaultns=extended', 'file'},

{'|page=File talk:Example.jpg|defaultns=extended', 'file'},

{'|page=Image:Example.jpg|defaultns=extended', 'file'},

{'|page=Image talk:Example.jpg|defaultns=extended', 'file'},

{'|page=MediaWiki:Watchlist-details|defaultns=extended', 'interface page'},

{'|page=MediaWiki talk:Watchlist-details|defaultns=extended', 'interface page'},

{'|page=Template:Pagetype|defaultns=extended', 'template'},

{'|page=Template talk:Pagetype|defaultns=extended', 'template'},

{'|page=Help:Contents|defaultns=extended', 'help page'},

{'|page=Help talk:Contents|defaultns=extended', 'help page'},

{'|page=Category:Wikisourcerers|defaultns=extended', 'category'},

{'|page=Category talk:Wikisourcerers|defaultns=extended', 'category'},

{'|page=Portal:Arts|defaultns=extended', 'portal'},

{'|page=Portal talk:Arts|defaultns=extended', 'portal'},

{'|page=Author:Countries|defaultns=extended', 'author'},

{'|page=Author talk:Countries|defaultns=extended', 'author'},

{'|page=Page:example|defaultns=extended', 'page'},

{'|page=Page talk:example|defaultns=extended', 'page'},

{'|page=Index:Foo|defaultns=extended', 'page'},

{'|page=Index talk:Foo|defaultns=extended', 'page'},

{'|page=Translation:Foo|defaultns=extended', 'page'},

{'|page=Translation talk:Foo|defaultns=extended', 'page'},

{'|page=Special:PrefixIndex|defaultns=extended', 'page'},

{'|page=Media:Example.jpg|defaultns=extended', 'page'},

})

end

function p:test_defaultns_all()

self:preprocess_equals_many('{{#invoke:pagetype/sandbox|main', '}}', {

{'|page=UK|defaultns=all', 'redirect'},

{'|page=Talk:UK|defaultns=all', 'redirect'},

{'|page=United Kingdom|defaultns=all', 'article'},

{'|page=Talk:United Kingdom|defaultns=all', 'talk page'},

{'|page=User:Example|defaultns=all', 'user page'},

{'|page=User talk:Example|defaultns=all', 'talk page'},

{'|page=Wikisource:Namespace|defaultns=all', 'project page'},

{'|page=Wikisource talk:Namespace|defaultns=all', 'talk page'},

{'|page=Project:Namespace|defaultns=all', 'project page'},

{'|page=Project talk:Namespace|defaultns=all', 'talk page'},

{'|page=WP:Namespace|defaultns=all', 'project page'},

{'|page=WT:Namespace|defaultns=all', 'talk page'},

{'|page=File:Example.jpg|defaultns=all', 'file'},

{'|page=File talk:Example.jpg|defaultns=all', 'talk page'},

{'|page=Image:Example.jpg|defaultns=all', 'file'},

{'|page=Image talk:Example.jpg|defaultns=all', 'talk page'},

{'|page=MediaWiki:Watchlist-details|defaultns=all', 'interface page'},

{'|page=MediaWiki talk:Watchlist-details|defaultns=all', 'talk page'},

{'|page=Template:Pagetype|defaultns=all', 'template'},

{'|page=Template talk:Pagetype|defaultns=all', 'talk page'},

{'|page=Help:Contents|defaultns=all', 'help page'},

{'|page=Help talk:Contents|defaultns=all', 'talk page'},

{'|page=Category:Wikisourcerers|defaultns=all', 'category'},

{'|page=Category talk:Wikisourcerers|defaultns=all', 'talk page'},

{'|page=Portal:Arts|defaultns=all', 'portal'},

{'|page=Portal talk:Arts|defaultns=all', 'talk page'},

{'|page=Author:Countries|defaultns=all', 'author'},

{'|page=Author talk:Countries|defaultns=all', 'talk page'},

{'|page=Page:Example|defaultns=all', 'page'},

{'|page=Page talk:Example|defaultns=all', 'talk page'},

{'|page=Index:Foo|defaultns=all', 'index page'},

{'|page=Index talk:Foo|defaultns=all', 'talk page'},

{'|page=Translation:Foo|defaultns=all', 'translation page'},

{'|page=Translation talk:Foo|defaultns=all', 'talk page'},

{'|page=Special:PrefixIndex|defaultns=all', 'special page'},

{'|page=Media:Example.jpg|defaultns=all', 'file'},

})

end

function p:test_custom_namespace_text()

self:preprocess_equals_many('{{#invoke:pagetype/sandbox|main', '}}', {

{'|page=UK|redirect=custom text', 'custom text'},

{'|page=Talk:UK|redirect=custom text', 'custom text'},

{'|page=Talk:UK|talk=custom text', 'redirect'},

{'|page=United Kingdom|main=custom text', 'custom text'},

{'|page=Talk:United Kingdom|main=custom text', 'custom text'},

{'|page=Talk:United Kingdom|talk=custom text', 'custom text'},

{'|page=User:Example|user=custom text', 'custom text'},

{'|page=User talk:Example|user=custom text', 'custom text'},

{'|page=User talk:Example|talk=custom text', 'custom text'},

{'|page=Wikisource:Namespace|wikisource=custom text', 'custom text'},

{'|page=Wikisource talk:Namespace|wikisource=custom text', 'custom text'},

{'|page=Wikisource talk:Namespace|talk=custom text', 'custom text'},

{'|page=Project:Namespace|project=custom text', 'custom text'},

{'|page=Project talk:Namespace|project=custom text', 'custom text'},

{'|page=Project talk:Namespace|talk=custom text', 'custom text'},

{'|page=WP:Namespace|wp=custom text', 'custom text'},

{'|page=WT:Namespace|wp=custom text', 'custom text'},

{'|page=WT:Namespace|talk=custom text', 'custom text'},

{'|page=WT:Namespace|wt=custom text', 'page'},

{'|page=Wikisource:Namespace|project=custom text', 'custom text'},

{'|page=Wikisource talk:Namespace|project=custom text', 'custom text'},

{'|page=WP:Namespace|project=custom text', 'custom text'},

{'|page=WT:Namespace|project=custom text', 'custom text'},

{'|page=Wikisource:Namespace|wp=custom text', 'custom text'},

{'|page=Wikisource talk:Namespace|wp=custom text', 'custom text'},

{'|page=Project:Namespace|wp=custom text', 'custom text'},

{'|page=Project talk:Namespace|wp=custom text', 'custom text'},

{'|page=File:Example.jpg|file=custom text', 'custom text'},

{'|page=File talk:Example.jpg|file=custom text', 'custom text'},

{'|page=File talk:Example.jpg|talk=custom text', 'custom text'},

{'|page=Image:Example.jpg|file=custom text', 'custom text'},

{'|page=Image talk:Example.jpg|file=custom text', 'custom text'},

{'|page=Image talk:Example.jpg|talk=custom text', 'custom text'},

{'|page=File:Example.jpg|image=custom text', 'custom text'},

{'|page=File talk:Example.jpg|image=custom text', 'custom text'},

{'|page=File talk:Example.jpg|image=custom text', 'custom text'},

{'|page=Image:Example.jpg|image=custom text', 'custom text'},

{'|page=Image talk:Example.jpg|image=custom text', 'custom text'},

{'|page=Image talk:Example.jpg|image=custom text', 'custom text'},

{'|page=MediaWiki:Watchlist-details|mediawiki=custom text', 'custom text'},

{'|page=MediaWiki talk:Watchlist-details|mediawiki=custom text', 'custom text'},

{'|page=MediaWiki talk:Watchlist-details|talk=custom text', 'custom text'},

{'|page=Template:Pagetype|template=custom text', 'custom text'},

{'|page=Template talk:Pagetype|template=custom text', 'custom text'},

{'|page=Template talk:Pagetype|talk=custom text', 'custom text'},

{'|page=Help:Contents|help=custom text', 'custom text'},

{'|page=Help talk:Contents|help=custom text', 'custom text'},

{'|page=Help talk:Contents|talk=custom text', 'custom text'},

{'|page=Category:Wikisourcerers|category=custom text', 'custom text'},

{'|page=Category talk:Wikisourcerers|category=custom text', 'custom text'},

{'|page=Category talk:Wikisourcerers|talk=custom text', 'custom text'},

{'|page=Portal:Arts|portal=custom text', 'custom text'},

{'|page=Portal talk:Arts|portal=custom text', 'custom text'},

{'|page=Portal talk:Arts|talk=custom text', 'custom text'},

{'|page=Author:Countries|author=custom text', 'custom text'},

{'|page=Author talk:Countries|author=custom text', 'custom text'},

{'|page=Author talk:Countries|talk=custom text', 'custom text'},

{'|page=Page:Example|page=custom text', 'custom text'},

{'|page=Page talk:Example|page=custom text', 'custom text'},

{'|page=Page talk:Example|talk=custom text', 'custom text'},

{'|page=Index:Foo|index=custom text', 'custom text'},

{'|page=Index talk:Foo|index=custom text', 'custom text'},

{'|page=Index talk:Foo|talk=custom text', 'custom text'},

{'|page=Translation:Foo|timedtext=custom text', 'custom text'},

{'|page=Translation talk:Foo|timedtext=custom text', 'custom text'},

{'|page=Translation talk:Foo|talk=custom text', 'custom text'},

{'|page=Special:PrefixIndex|special=custom text', 'custom text'},

{'|page=Media:Example.jpg|media=custom text', 'custom text'},

{'|page=Media:Example.jpg|file=custom text', 'page'},

})

end

function p:test_order_of_precedence()

self:preprocess_equals_many('{{#invoke:pagetype/sandbox|main', '}}', {

{'|module=foo', 'foo'}, -- This should be run on the talk page - it will not work if run in other places.

{'|talk=bar', 'bar'}, -- This should be run on the talk page - it will not work if run in other places.

{'|module=foo|talk=bar', 'bar'}, -- This should be run on the talk page - it will not work if run in other places.

{'|page=Module:Pagetype/testcases|module=foo|talk=bar', 'foo'},

{'|page=UK|defaultns=none|redirect=foo', 'foo'}, -- UK is a redirect page.

{'|page=UK|defaultns=none|redirect=foo|main=bar', 'foo'},

{'|page=UK|defaultns=extended|redirect=foo', 'foo'},

{'|page=UK|defaultns=extended|main=foo|redirect=bar', 'bar'},

{'|page=UK|main=foo|redirect=bar', 'bar'},

{'|page=UK|dab|main=foo|redirect=bar|dab=baz', 'bar'},

{'|page=UK|na|main=foo|redirect=bar|na=baz', 'bar'},

{'|page=Talk:UK|main=foo|redirect=bar', 'bar'}, -- Talk:UK is a redirect.

{'|page=Talk:UK|main=foo|redirect=bar|talk=baz', 'bar'},

{'|page=Foo|main=foo|redirect=bar', 'bar'}, -- Foo is a redirect.

{'|page=Talk:Foo|main=foo|redirect=bar', 'bar'}, -- Talk:Foo is not a redirect.

{'|page=Talk:Foo|main=foo|redirect=bar|talk=baz', 'baz'},

{'|page=United Kingdom|main=foo|redirect=bar|talk=baz', 'foo'},

{'|page=United Kingdom|dab|main=foo|redirect=bar|talk=baz', 'page'},

{'|page=United Kingdom|dab|main=foo|redirect=bar|talk=baz|dab=yes', 'page'},

{'|page=United Kingdom|dab|main=foo|redirect=bar|talk=baz|dab=bin', 'bin'},

{'|page=United Kingdom|na|main=foo|redirect=bar|talk=baz', 'page'},

{'|page=United Kingdom|na|main=foo|redirect=bar|talk=baz|na=yes', 'page'},

{'|page=United Kingdom|na|main=foo|redirect=bar|talk=baz|na=bin', 'bin'},

{'|page=Wikisource:Namespace|wp=foo|project=bar|wikisource=baz', 'baz'},

{'|page=Wikisource:Namespace|wp=foo|project=bar', 'bar'},

{'|page=Wikisource:Namespace|wp=foo', 'foo'},

{'|page=Wikisource:Namespace|wikisource=foo|wp=bar', 'foo'},

{'|page=Wikisource talk:Namespace|wp=foo|project=bar|wikisource=baz', 'baz'},

{'|page=Wikisource talk:Namespace|wp=foo|project=bar|wikisource=baz|talk=bin', 'bin'},

{'|page=Project talk:Namespace|wp=foo|project=bar|wikisource=baz', 'baz'},

{'|page=Project talk:Namespace|wp=foo|project=bar|wikisource=baz|talk=bin', 'bin'},

{'|page=File:Example.jpg|file=foo|image=bar', 'foo'},

{'|page=File talk:Example.jpg|file=foo|image=bar', 'foo'},

{'|page=File talk:Example.jpg|file=foo|image=bar|talk=baz', 'baz'},

{'|page=Image:Example.jpg|file=foo|image=bar', 'foo'},

{'|page=Image talk:Example.jpg|file=foo|image=bar', 'foo'},

{'|page=Image talk:Example.jpg|file=foo|image=bar|talk=baz', 'baz'},

})

end

function p:test_other_parameter()

self:preprocess_equals_many('{{#invoke:pagetype/sandbox|main', '}}', {

{'|page=Wikisource:Namespace', 'page'},

{'|page=Wikisource:Namespace|other=custom text', 'custom text'},

{'|page=Wikisource:Namespace|other=no', 'page'},

{'|page=Wikisource:Namespace|other=yes', 'page'},

{'|page=Wikisource:Namespace|other=custom text|wikisource=wikisource-space text', 'wikisource-space text'},

})

end

function p:test_yesno()

self:preprocess_equals_many('{{#invoke:pagetype/sandbox|main', '}}', {

{'|page=Wikisource:Namespace|wikisource=yes', 'project page'},

{'|page=Wikisource:Namespace|wikisource=Yes', 'project page'},

{'|page=Wikisource:Namespace|wikisource=YeS', 'project page'},

{'|page=Wikisource:Namespace|wikisource=y', 'project page'},

{'|page=Wikisource:Namespace|wikisource=Y', 'project page'},

{'|page=Wikisource:Namespace|wikisource=true', 'project page'},

{'|page=Wikisource:Namespace|wikisource=True', 'project page'},

{'|page=Wikisource:Namespace|wikisource=TrUe', 'project page'},

{'|page=Wikisource:Namespace|wikisource=1', 'project page'},

{'|page=Wikisource:Namespace|wikisource=1.0', 'project page'},

{'|page=Template:Pagetype|template=no', 'page'},

{'|page=Template:Pagetype|template=No', 'page'},

{'|page=Template:Pagetype|template=nO', 'page'},

{'|page=Template:Pagetype|template=n', 'page'},

{'|page=Template:Pagetype|template=N', 'page'},

{'|page=Template:Pagetype|template=false', 'page'},

{'|page=Template:Pagetype|template=False', 'page'},

{'|page=Template:Pagetype|template=fAlSe', 'page'},

{'|page=Template:Pagetype|template=0', 'page'},

{'|page=Template:Pagetype|template=0.0', 'page'},

})

end

function p:test_subject_redirect_defaultns_all()

self:preprocess_equals_many('{{#invoke:pagetype/sandbox|main', '}}', {

{'|page=MediaWiki talk:Spam-blacklist/log|defaultns=all', 'talk page'},

})

end

return p

Show more