-- Example Unit tests for [[Module:Namespace detect]]. Click talk page to run tests.
local p = require('Module:UnitTests')
local nsDetect = require('Module:Namespace detect/sandbox')._main

function p:test_template_testcases_page()
    self:preprocess_equals_many('{{#invoke:Namespace detect/sandbox|main', '}}', {
        {[[
| main = Article text.
| talk = Any talk page text.
| user = User page text.
| other = Other pages text.]], 'Any talk page text.'},
        {[[
| main = Article text.
| talk = Any talk page text.
| user = User page text.
| other = Other pages text.
| demospace = ]], 'Any talk page text.'},
        {[[
| main = Article text.
| talk = Any talk page text.
| user = User page text.
| other = Other pages text.
| demospace = main]], 'Article text.'},
        {[[
| main = Article text.
| talk = Any talk page text.
| user = User page text.
| other = Other pages text.
| demospace = talk]], 'Any talk page text.'},
        {[[
| main = Article text.
| talk = Any talk page text.
| user = User page text.
| other = Other pages text.
| demospace = help talk]], 'Other pages text.'},
        {[[
| main = Article text.
| talk = Any talk page text.
| user = User page text.
| other = Other pages text.
| page = ]], 'Any talk page text.'},
        {[[
| main = Article text.
| talk = Any talk page text.
| user = User page text.
| other = Other pages text.
| page = Example/test]], 'Article text.'},
        {[[
| main = Article text.
| talk = Any talk page text.
| user = User page text.
| other = Other pages text.
| page = User:Example/test]], 'User page text.'},
        {[[
| main = Article text.
| talk = Any talk page text.
| user = User page text.
| other = Other pages text.
| page = User talk:Example/test]], 'Any talk page text.'},
    })
end

function p:test_new()
    self:preprocess_equals_many('{{#invoke:Namespace detect/sandbox|main', '}}', {
        {[[]], ''},
        {[[
| main = Article text.
| talk = 
| user = User page text.
| other = Other pages text.
| page = User talk:Example/test]], ''},
        {[[
| main = Article text.
| talk = 
| user = User page text.
| other = Other pages text.
| page = User:Example/test]], 'User page text.'},
        {[[
| main = Article text.
| TALK = Talk page text.
| user = User page text.
| other = Other pages text.
| page = User talk:Example/test]], 'Other pages text.'},
        {[[
| main = Article text.
| talk = talk page text with a delete character here: ""
| user = User page text.
| other = Other pages text.
| page = User talk:Example/test]], 'talk page text with a delete character here: ""'},
        {[[
| main = Article text.
| talk = Talk page text.
| wikipedia = Wikipedia page text.
| user = User page text.
| other = Other pages text.
| demospace = Wikipedia ]], 'Wikipedia page text.'},
        {[[
| main = 
| talk = talk page text with a delete character here: ""
| user = User page text.
| other = Other pages text.
| page = Foo]], ''},
        {[[
| main = Article text.
| talk = talk page text with a delete character here: ""
| user = 
| other = Other pages text.
| page = User:Example/test]], ''},
        {[[
| main = Article text.
| talk = talk page text with a delete character here: ""
| user = User page text.
| book = Book page text.
| other = Other pages text.
| page = Book:Foo]], 'Book page text.'},
        {[[
| main = Article text.
| talk = talk page text with a delete character here: ""
| user = User page text.
| image = Image page text.
| other = Other pages text.
| page = File:Foo]], 'Image page text.'},
        {[[
| main = Article text.
| talk = talk page text with a delete character here: ""
| user = User page text.
| file = File page text.
| other = Other pages text.
| page = File:Foo]], 'File page text.'},
        {[[
| main = Article text.
| talk = talk page text with a delete character here: ""
| user = User page text.
| image = 
| other = Other pages text.
| page = File:Foo]], ''},
        {[[
| main = Article text.
| talk = talk page text with a delete character here: ""
| user = User page text.
| file = 
| other = Other pages text.
| page = File:Foo]], ''},
        {[[
| main = Article text.
| talk = talk page text with a delete character here: ""
| user = User page text.
| mediawiki = MediaWiki page text.
| other = Other pages text.
| page = MediaWiki:Foo]], 'MediaWiki page text.'},
        {[[
| main = Article text.
| talk = talk page text with a delete character here: ""
| user = User page text.
| template = Template page text.
| other = Other pages text.
| page = Template:Foo]], 'Template page text.'},
        {[[
| main = Article text.
| talk = talk page text with a delete character here: ""
| help = Help page text.
| image = Image page text.
| other = Other pages text.
| page = Help:Foo]], 'Help page text.'},
        {[[
| main = Article text.
| talk = talk page text with a delete character here: ""
| user = User page text.
| category = Category page text.
| other = Other pages text.
| page = Category:Foo]], 'Category page text.'},
        {[[
| main = Article text.
| talk = talk page text with a delete character here: ""
| user = User page text.
| portal = Portal page text.
| other = Other pages text.
| page = Portal:Foo]], 'Portal page text.'},
        {[[
| main = Article text.
| talk = talk page text with a delete character here: ""
| user = User page text.
| nonexistent = Nonexistent namespace page text.
| other = Other pages text.
| page = Nonexistent:Foo]], 'Article text.'},
        {[[
| main = Article text.
| talk = talk page text with a delete character here: ""
| user = User page text.
| nonexistent = Nonexistent namespace page text.
| other = Other pages text.
| demospace = Nonexistent]], 'Other pages text.'},
    })
end

function p:test_bad_titles()
    self:preprocess_equals_many('{{#invoke:Namespace detect/sandbox|main', '}}', {
        {[==[
| main = Article text.
| talk = Any talk page text.
| user = User page text.
| other = Other pages text.
| page = Talk:Square [[brackets]] aren't allowed in page titles]==], 'Other pages text.'},
    })
end

function p:test_subject_namespaces()
    self:preprocess_equals_many('{{#invoke:Namespace detect/sandbox|main', '}}', {
           {[==[
| main = Article text.
| talk = Any talk page text.
| user = User page text.
| other = Other pages text.
| page = Talk:Foo]==], 'Any talk page text.'},
        {[==[
| subjectns = yes
| main = Article text.
| talk = Any talk page text.
| user = User page text.
| other = Other pages text.
| page = Talk:Foo]==], 'Article text.'},
        {[==[
| subjectns = no
| main = Article text.
| talk = Any talk page text.
| user = User page text.
| other = Other pages text.
| page = Talk:Foo]==], 'Any talk page text.'},
        {[==[
| subjectns = yes
| main = Article text.
| talk = Any talk page text.
| user = User page text.
| other = Other pages text.
| page = Wikipedia talk:Foo]==], 'Other pages text.'},
    })
end

function p:test_multiple_word_namespaces()
    self:preprocess_equals_many('{{#invoke:Namespace detect/sandbox|main', '}}', {
           {[==[
| main = Article text.
| talk = Any talk page text.
| user = User page text.
| education program = Education Program pages text.
| other = Other pages text.
| page = Education Program:Foo]==], 'Education Program pages text.'},
    })
end

function p:test_returning_false()
    self:equals('Return false from article', nsDetect{page = 'Wikipedia', main = false}, false)
    self:equals('Return false from talk page', nsDetect{page = 'Talk:Wikipedia', main = true, talk = false}, false)
    self:equals('Return false from category page', nsDetect{page = 'Category:Wikipedians', main = true, talk = true, category = false}, false)
    self:equals('Return false from other page', nsDetect{page = 'Template:Pagetype', main = true, talk = true, other = false}, false)
end

return p
"https://si.wikipedia.org/w/index.php?title=Module:Namespace_detect/testcases&oldid=548164" වෙතින් සම්ප්‍රවේශනය කෙරිණි