Difference between revisions of "Module:Pagetype/testcases"
Jump to navigation
Jump to search
blackwiki>Mr. Stradivarius (fixes) |
blackwiki>Mr. Stradivarius (add order of precedence tests) |
||
| Line 243: | Line 243: | ||
{'|page=Media:Example.svg|media=custom text', 'custom text'}, | {'|page=Media:Example.svg|media=custom text', 'custom text'}, | ||
{'|page=Media:Example.svg|file=custom text', 'page'}, | {'|page=Media:Example.svg|file=custom text', 'page'}, | ||
| + | }) | ||
| + | end | ||
| + | |||
| + | function p:test_order_of_precedence() | ||
| + | self:preprocess_equals_many('{{#invoke:pagetype|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=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', 'disambiguation 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=Wikipedia:Namespace|wp=foo|project=bar|wikipedia=baz', 'baz'}, | ||
| + | {'|page=Wikipedia:Namespace|wp=foo|project=bar', 'bar'}, | ||
| + | {'|page=Wikipedia:Namespace|wp=foo', 'foo'}, | ||
| + | {'|page=Wikipedia:Namespace|wikipedia=foo|wp=bar', 'bar'}, | ||
| + | {'|page=Wikipedia talk:Namespace|wp=foo|project=bar|wikipedia=baz', 'baz'}, | ||
| + | {'|page=Wikipedia talk:Namespace|wp=foo|project=bar|wikipedia=baz|talk=bin', 'bin'}, | ||
| + | {'|page=Project talk:Namespace|wp=foo|project=bar|wikipedia=baz', 'baz'}, | ||
| + | {'|page=Project talk:Namespace|wp=foo|project=bar|wikipedia=baz|talk=bin', 'bin'}, | ||
| + | {'|page=File:Example.svg|file=foo|image=bar', 'foo'}, | ||
| + | {'|page=File talk:Example.svg|file=foo|image=bar', 'foo'}, | ||
| + | {'|page=File talk:Example.svg|file=foo|image=bar|talk=baz', 'baz'}, | ||
| + | {'|page=Image:Example.svg|file=foo|image=bar', 'foo'}, | ||
| + | {'|page=Image talk:Example.svg|file=foo|image=bar', 'foo'}, | ||
| + | {'|page=Image talk:Example.svg|file=foo|image=bar|talk=baz', 'baz'}, | ||
}) | }) | ||
end | end | ||
return p | return p | ||
Revision as of 07:37, 28 October 2013
Documentation for this module may be created at Module:Pagetype/testcases/doc
-- 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|main', '}}', {
{'', 'module'},
{'|module=no', 'page'},
{'|module=foo', 'foo'},
})
end
function p:test_spaces()
self:preprocess_equals_many('{{#invoke:pagetype|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|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=Wikipedia:Namespace', 'page'},
{'|page=Wikipedia talk:Namespace', 'page'},
{'|page=Project:Namespace', 'page'},
{'|page=Project talk:Namespace', 'page'},
{'|page=WP:Namespace', 'page'},
{'|page=WT:Namespace', 'page'},
{'|page=File:Example.svg', 'file'},
{'|page=File talk:Example.svg', 'file'},
{'|page=Image:Example.svg', 'file'},
{'|page=Image talk:Example.svg', '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:Wikipedians', 'category'},
{'|page=Category talk:Wikipedians', 'category'},
{'|page=Portal:Arts', 'page'},
{'|page=Portal talk:Arts', 'page'},
{'|page=Book:Countries', 'book'},
{'|page=Book talk:Countries', 'book'},
{'|page=Education Program:Foo', 'page'},
{'|page=Education Program talk:Foo', 'page'},
{'|page=TimedText:Foo', 'page'},
{'|page=TimedText talk:Foo', 'page'},
{'|page=Special:PrefixIndex', 'page'},
{'|page=Media:Example.svg', 'page'},
})
end
function p:test_defaultns_none()
self:preprocess_equals_many('{{#invoke:pagetype|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=Wikipedia:Namespace|defaultns=none', 'page'},
{'|page=Wikipedia 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.svg|defaultns=none', 'page'},
{'|page=File talk:Example.svg|defaultns=none', 'page'},
{'|page=Image:Example.svg|defaultns=none', 'page'},
{'|page=Image talk:Example.svg|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:Wikipedians|defaultns=none', 'page'},
{'|page=Category talk:Wikipedians|defaultns=none', 'page'},
{'|page=Portal:Arts|defaultns=none', 'page'},
{'|page=Portal talk:Arts|defaultns=none', 'page'},
{'|page=Book:Countries|defaultns=none', 'page'},
{'|page=Book talk:Countries|defaultns=none', 'page'},
{'|page=Education Program:Foo|defaultns=none', 'page'},
{'|page=Education Program talk:Foo|defaultns=none', 'page'},
{'|page=TimedText:Foo|defaultns=none', 'page'},
{'|page=TimedText talk:Foo|defaultns=none', 'page'},
{'|page=Special:PrefixIndex|defaultns=none', 'page'},
{'|page=Media:Example.svg|defaultns=none', 'page'},
})
end
function p:test_defaultns_extended()
self:preprocess_equals_many('{{#invoke:pagetype|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=Wikipedia:Namespace|defaultns=extended', 'project page'},
{'|page=Wikipedia 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.svg|defaultns=extended', 'file'},
{'|page=File talk:Example.svg|defaultns=extended', 'file'},
{'|page=Image:Example.svg|defaultns=extended', 'file'},
{'|page=Image talk:Example.svg|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:Wikipedians|defaultns=extended', 'category'},
{'|page=Category talk:Wikipedians|defaultns=extended', 'category'},
{'|page=Portal:Arts|defaultns=extended', 'portal'},
{'|page=Portal talk:Arts|defaultns=extended', 'portal'},
{'|page=Book:Countries|defaultns=extended', 'book'},
{'|page=Book talk:Countries|defaultns=extended', 'book'},
{'|page=Education Program:Foo|defaultns=extended', 'page'},
{'|page=Education Program talk:Foo|defaultns=extended', 'page'},
{'|page=TimedText:Foo|defaultns=extended', 'page'},
{'|page=TimedText talk:Foo|defaultns=extended', 'page'},
{'|page=Special:PrefixIndex|defaultns=extended', 'page'},
{'|page=Media:Example.svg|defaultns=extended', 'page'},
})
end
function p:test_defaultns_all()
self:preprocess_equals_many('{{#invoke:pagetype|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=Wikipedia:Namespace|defaultns=all', 'project page'},
{'|page=Wikipedia 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.svg|defaultns=all', 'file'},
{'|page=File talk:Example.svg|defaultns=all', 'talk page'},
{'|page=Image:Example.svg|defaultns=all', 'file'},
{'|page=Image talk:Example.svg|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:Wikipedians|defaultns=all', 'category'},
{'|page=Category talk:Wikipedians|defaultns=all', 'talk page'},
{'|page=Portal:Arts|defaultns=all', 'portal'},
{'|page=Portal talk:Arts|defaultns=all', 'talk page'},
{'|page=Book:Countries|defaultns=all', 'book'},
{'|page=Book talk:Countries|defaultns=all', 'talk page'},
{'|page=Education Program:Foo|defaultns=all', 'education program page'},
{'|page=Education Program talk:Foo|defaultns=all', 'talk page'},
{'|page=TimedText:Foo|defaultns=all', 'Timed Text page'},
{'|page=TimedText talk:Foo|defaultns=all', 'talk page'},
{'|page=Special:PrefixIndex|defaultns=all', 'special page'},
{'|page=Media:Example.svg|defaultns=all', 'file'},
})
end
function p:test_custom_namespace_text()
self:preprocess_equals_many('{{#invoke:pagetype|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=Wikipedia:Namespace|wikipedia=custom text', 'custom text'},
{'|page=Wikipedia talk:Namespace|wikipedia=custom text', 'custom text'},
{'|page=Wikipedia 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=Wikipedia:Namespace|project=custom text', 'custom text'},
{'|page=Wikipedia talk:Namespace|project=custom text', 'custom text'},
{'|page=WP:Namespace|project=custom text', 'custom text'},
{'|page=WT:Namespace|project=custom text', 'custom text'},
{'|page=Wikipedia:Namespace|wp=custom text', 'custom text'},
{'|page=Wikipedia 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:Wikipedians|category=custom text', 'custom text'},
{'|page=Category talk:Wikipedians|category=custom text', 'custom text'},
{'|page=Category talk:Wikipedians|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=Book:Countries|book=custom text', 'custom text'},
{'|page=Book talk:Countries|book=custom text', 'custom text'},
{'|page=Book talk:Countries|talk=custom text', 'custom text'},
{'|page=Education Program:Foo|education program=custom text', 'custom text'},
{'|page=Education Program talk:Foo|education program=custom text', 'custom text'},
{'|page=Education Program talk:Foo|talk=custom text', 'custom text'},
{'|page=TimedText:Foo|timedtext=custom text', 'custom text'},
{'|page=TimedText talk:Foo|timedtext=custom text', 'custom text'},
{'|page=TimedText talk:Foo|talk=custom text', 'custom text'},
{'|page=Special:PrefixIndex|special=custom text', 'custom text'},
{'|page=Media:Example.svg|media=custom text', 'custom text'},
{'|page=Media:Example.svg|file=custom text', 'page'},
})
end
function p:test_order_of_precedence()
self:preprocess_equals_many('{{#invoke:pagetype|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=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', 'disambiguation 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=Wikipedia:Namespace|wp=foo|project=bar|wikipedia=baz', 'baz'},
{'|page=Wikipedia:Namespace|wp=foo|project=bar', 'bar'},
{'|page=Wikipedia:Namespace|wp=foo', 'foo'},
{'|page=Wikipedia:Namespace|wikipedia=foo|wp=bar', 'bar'},
{'|page=Wikipedia talk:Namespace|wp=foo|project=bar|wikipedia=baz', 'baz'},
{'|page=Wikipedia talk:Namespace|wp=foo|project=bar|wikipedia=baz|talk=bin', 'bin'},
{'|page=Project talk:Namespace|wp=foo|project=bar|wikipedia=baz', 'baz'},
{'|page=Project talk:Namespace|wp=foo|project=bar|wikipedia=baz|talk=bin', 'bin'},
{'|page=File:Example.svg|file=foo|image=bar', 'foo'},
{'|page=File talk:Example.svg|file=foo|image=bar', 'foo'},
{'|page=File talk:Example.svg|file=foo|image=bar|talk=baz', 'baz'},
{'|page=Image:Example.svg|file=foo|image=bar', 'foo'},
{'|page=Image talk:Example.svg|file=foo|image=bar', 'foo'},
{'|page=Image talk:Example.svg|file=foo|image=bar|talk=baz', 'baz'},
})
end
return p