Module:Category handler/Exemplos para testes

-- Unit tests for Module:Category handler. Click talk page to run tests. local m_category_handler = require('Módulo:Category handler/Testes') local chmain = m_category_handler._main local ScribuntoUnit = require('Módulo:ScribuntoUnit') local suite = ScribuntoUnit:new

-- Define table of defaults local d = {}

-- Values d.absent = nil d.blank = '' d.negation = '¬' d.yes = 'yes' d.no = 'no' d.subpageOnly = 'only' d.subpageNo = 'no'

-- Categories d.category = 'Categoria:Algumacat' d.category1 = 'Categoria:Algumacat1' d.category2 = 'Categoria:Algumacat2'

-- Pages d.article = 'Algumartigo' d.file = 'Ficheiro:Example.png' d.talk = 'Discussão:Foo' d.archive = 'Usuário(a) Discussão:Exemplo/Arquivo' d.subpage = 'Usuário(a):Exemplo/teste' d.basepage = 'Usuário(a):Examplo'

-- Params d.archiveParam = 'discussão'

-- Test nil

function suite:test_nil self:assertEquals(d.absent, chmain{nil}) end

-- Test defaults

function suite:test_default_current_page -- Will test either module or module talk space, neither of which are categorised by default. self:assertEquals(d.absent, chmain{d.category}) end

function suite:test_default_main self:assertEquals(d.category, chmain{d.category, page = d.article}) end

function suite:test_default_file self:assertEquals(d.category, chmain{d.category, page = d.file}) end

-- Test numbered parameters

function suite:test_numbered_main self:assertEquals(d.category, chmain{		[1] = d.category,		main = 1,		page = d.article	}) end

function suite:test_numbered_two_params self:assertEquals(d.category2, chmain{		[1] = d.category1,		[2] = d.category2,		main = 1,		file = 2,		page = d.file	}) end

-- Test overriding defaults

function suite:test_numbered_main self:assertEquals(d.absent, chmain{		main = d.category,		page = d.file	}) end

-- Test blank namespace parameters

function suite:test_blank_namespace_talk self:assertEquals(d.blank, chmain{		talk = d.blank,		other = d.category,		page = d.talk	}) end

-- Test other parameter

function suite:test_other_only self:assertEquals(d.category, chmain{		other = d.category,	}) end

-- Test nocat parameter

function suite:test_nocat_true self:assertEquals(d.absent, chmain{d.category, page = d.file, nocat = true}) end

function suite:test_nocat_blank self:assertEquals(d.category, chmain{d.category, page = d.file, nocat = ''}) end

function suite:test_nocat_yes self:assertEquals(d.absent, chmain{d.category, page = d.file, nocat = d.yes}) end

function suite:test_nocat_false self:assertEquals(d.category, chmain{		[d.archiveParam] = d.category,		page = d.archive,		nocat = false	}) end

function suite:test_nocat_no self:assertEquals(d.category, chmain{		[d.archiveParam] = d.category,		page = d.archive,		nocat = d.no	}) end

-- Test categories parameter

function suite:test_categories_true self:assertEquals(d.category, chmain{		[d.archiveParam] = d.category,		page = d.archive,		categories = true	}) end

function suite:test_categories_blank self:assertEquals(d.category, chmain{d.category, page = d.file, categories = ''}) end

function suite:test_categories_yes self:assertEquals(d.category, chmain{		[d.archiveParam] = d.category,		page = d.archive,		categories = d.yes	}) end

function suite:test_categories_false self:assertEquals(d.absent, chmain{		file = d.category,		page = d.file,		categories = false	}) end

function suite:test_categories_no self:assertEquals(d.absent, chmain{		file = d.category,		page = d.file,		categories = d.no	}) end

-- Test category2 parameter

function suite:test_category2_no self:assertEquals(d.absent, chmain{		other = d.category,		category2 = d.no	}) end

function suite:test_category2_blank self:assertEquals(d.absent, chmain{		other = d.category,		category2 = d.blank	}) end

function suite:test_category2_negation self:assertEquals(d.category, chmain{		other = d.category,		category2 = d.negation	}) end

function suite:test_category2_blacklist self:assertEquals(d.category, chmain{		other = d.category,		page = d.archive,		categories = d.yes	}) end

-- Test subpage parameter

function suite:test_subpage_no_basepage self:assertEquals(d.category, chmain{		other = d.category,		page = d.basepage,		subpage = d.subpageNo	}) end

function suite:test_subpage_no_subpage self:assertEquals(d.absent, chmain{		other = d.category,		page = d.subpage,		subpage = d.subpageNo	}) end

function suite:test_subpage_only_basepage self:assertEquals(d.absent, chmain{		other = d.category,		page = d.basepage,		subpage = d.subpageOnly	}) end

function suite:test_subpage_only_subpage self:assertEquals(d.category, chmain{		other = d.category,		page = d.subpage,		subpage = d.subpageOnly	}) end

-- Test blacklist

function suite:test_blacklist_archives self:assertEquals(d.absent, chmain{		other = d.category,		page = 'Usuário(a) Discussão:Exemplo/Arquivo 5',	}) end

function suite:test_blacklist_archives_lowercase self:assertEquals(d.absent, chmain{		other = d.category,		page = 'Usuário(a) Discussão:Exemplo/arquivo',	}) end

function suite:test_blacklist_archives_notarchive self:assertEquals(d.category, chmain{		other = d.category,		page = 'Usuário Discussão:Exemplo/Arquvio 5',	}) end

function suite:test_blacklist_main_page self:assertEquals(d.absent, chmain{		other = d.category,		page = 'Wikipédia:Página principal',	}) end

function suite:test_blacklist_main_page_talk self:assertEquals(d.category, chmain{		other = d.category,		page = 'Wikipédia Discussão:Página principal',	}) end

function suite:test_blacklist_template_messages_basepage self:assertEquals(d.category, chmain{		other = d.category,		page = 'Wikipédia:Lista de predefinições',	}) end

function suite:test_blacklist_template_messages_slash self:assertEquals(d.absent, chmain{		other = d.category,		page = 'Wikipédia:Lista de predefinições/',	}) end

function suite:test_blacklist_template_messages_not_subpage self:assertEquals(d.category, chmain{		other = d.category,		page = 'Wikipédia:Lista de predefiniçõesFoo',	}) end

function suite:test_blacklist_template_messages_subpage self:assertEquals(d.absent, chmain{		other = d.category,		page = 'Wikipédia:Lista de predefinições/Esboços',	}) end

-- Test namespace params

function suite:test_main self:assertEquals(d.category, chmain{		main = d.category,		page = 'Algum artigo',	}) end

function suite:test_talk self:assertEquals(d.category, chmain{		talk = d.category,		page = 'Discussão:Algum artigo',	}) end

function suite:test_user self:assertEquals(d.category, chmain{		user = d.category,		page = 'Usuário(a):Exemplo',	}) end

function suite:test_user_talk self:assertEquals(d.category, chmain{		talk = d.category,		page = 'Usuário(a) Discussão:Exemplo',	}) self:assertEquals(d.absent, chmain{		['usuário discussão'] = d.category,		page = 'Usuário(a) Discussão:Exemplo',	}) self:assertEquals(d.absent, chmain{		['usuário_discussão'] = d.category,		page = 'Usuário(a) Discussão:Example',	}) end

function suite:test_wikipedia self:assertEquals(d.category, chmain{		wikipedia = d.category,		page = 'Wikipédia:Exemplo',	}) end

function suite:test_wikipedia self:assertEquals(d.category, chmain{		wikipedia = d.category,		page = 'Wikipédia:Exemplo',	}) end

function suite:test_project self:assertEquals(d.category, chmain{		project = d.category,		page = 'Wikipédia:Exemplo',	}) end

function suite:test_wp self:assertEquals(d.category, chmain{		wp = d.category,		page = 'Wikipédia:Exemplo',	}) end

function suite:test_file self:assertEquals(d.category, chmain{		file = d.category,		page = 'Ficheiro:Example.png',	}) end

function suite:test_image self:assertEquals(d.category, chmain{		image = d.category,		page = 'Ficheiro:Example.png',	}) end

function suite:test_mediawiki self:assertEquals(d.category, chmain{		mediawiki = d.category,		page = 'MediaWiki:Protectedpagetext',	}) end

function suite:test_template self:assertEquals(d.category, chmain{		template = d.category,		page = 'Predefinição:Exemplo',	}) end

function suite:test_help self:assertEquals(d.category, chmain{		help = d.category,		page = 'Ajuda:Guia de edição',	}) end

function suite:test_category self:assertEquals(d.category, chmain{		category = d.category,		page = 'Categoria:!Wikipedistas',	}) end

function suite:test_category self:assertEquals(d.category, chmain{		category = d.category,		page = 'Categoria:!Wikipedistas',	}) end

function suite:test_portal self:assertEquals(d.category, chmain{		portal = d.category,		page = 'Portal:França',	}) end

function suite:test_timedtext self:assertEquals(d.category, chmain{		timedtext = d.category,		page = 'TimedText:Exemplo',	}) end

function suite:test_module self:assertEquals(d.category, chmain{		module = d.category,		page = 'Módulo:Testes',	}) end

function suite:test_special self:assertEquals(d.category, chmain{		special = d.category,		page = 'Special:WhatLinksHere',	}) end

function suite:test_media self:assertEquals(d.category, chmain{		media = d.category,		page = 'Media:Exemplo.png',	}) end

return suite