-- Unit tests for quality function of [[Module:Class mask]]. Click talk page to run tests.
local p = require('Module:UnitTests')
local module = mw.getCurrentFrame().args.module or 'Class mask'
-- Pages for testing:
-- Talk:Oxford spelling has banner shell but no global class
-- Talk:James Abbott Thompson is a redirect and has no banner shell
-- Talk:Henri-Charles de Beaumanoir of Lavardin has global class unassessed
-- Talk:Philippe Cattiau has global class Stub
-- Template talk:Germany-silent-film-stub is a template and has global class NA
-- Talk:Siege of Arrah has global class A
-- Talk:Tropical World is a DAB page and has global class NA
-- Template talk:Bombycoidea-stub is a template and has global class NA
-- Talk:Christian Coleman has global class C
-- Talk:2011 Atlanta Falcons season has global class Start
-- Talk:Emma Goldman has global class FA
function p:test_with_inherited_class_Stub()
self:preprocess_equals_many('{{#invoke:' .. module .. '|quality |class=', '|page=Talk:Philippe Cattiau}}', {
{'C', 'XC'},
{'stub', 'HStub'},
{'ddff', 'HStub'},
{'', 'HStub'},
}, {nowiki=1})
end
function p:test_with_inherited_class_A()
self:preprocess_equals_many('{{#invoke:' .. module .. '|quality |class=', ' |page=Talk:Siege of Arrah}}', {
{'C', 'XC'},
{'A', 'HA'},
{'ddff', 'HA'},
{'', 'HA'},
}, {nowiki=1})
end
function p:test_with_custom_quality_criteria()
self:preprocess_equals_many('{{#invoke:' .. module .. ' | quality |QUALITY_CRITERIA=custom |class=C |page=', '}}', {
{'Talk:Oxford spelling', 'YC'},
{'Talk:James Abbott Thompson', 'YC'},
{'Talk:Henri-Charles de Beaumanoir of Lavardin', 'YC'},
{'Talk:Philippe Cattiau', 'YC'},
{'Template talk:Germany-silent-film-stub', 'YC'},
{'Talk:Siege of Arrah', 'YC'},
}, {nowiki=1})
end
function p:test_A_class_on_different_pages()
self:preprocess_equals_many('{{#invoke:' .. module .. ' | quality |class=A |page=', '}}', {
{'Talk:Oxford spelling', 'YA'},
{'Talk:James Abbott Thompson', 'YA'},
{'Talk:Henri-Charles de Beaumanoir of Lavardin', 'YA'},
{'Talk:Philippe Cattiau', 'XA'},
{'Template talk:Germany-silent-film-stub', 'XA'},
{'Talk:Siege of Arrah', 'HA'},
}, {nowiki=1})
end
function p:test_with_matching_classes()
self:preprocess_equals('{{#invoke:' .. module .. ' |quality |class=NA |page=Template talk:Germany-silent-film-stub}}', 'HNA')
self:preprocess_equals('{{#invoke:' .. module .. ' |quality |class=A |page=Talk:Siege of Arrah}}', 'HA')
self:preprocess_equals('{{#invoke:' .. module .. ' |quality |class=stub |page=Talk:Philippe Cattiau}}', 'HStub')
self:preprocess_equals('{{#invoke:' .. module .. ' |quality |class= |page=Talk:Henri-Charles de Beaumanoir of Lavardin}}', 'H')
end
function p:test_for_unassessed()
self:preprocess_equals('{{#invoke:' .. module .. ' |quality |class= |page=Talk:Henri-Charles de Beaumanoir of Lavardin}}', 'H')
self:preprocess_equals('{{#invoke:' .. module .. ' |quality ||page=Talk:Oxford spelling}}', 'Y')
self:preprocess_equals('{{#invoke:' .. module .. ' |quality |class=d |page=Talk:James Abbott Thompson}}', 'YNA')
end
function p:test_with_valid_article_class_ignoring_namespace()
self:preprocess_equals_many('{{#invoke:' .. module .. ' | quality |page=Talk:Emma Goldman |class=', '}}', {
{'xyz', 'HFA'},
{'Stub', 'XStub'},
{'Template', 'XNA'},
{'', 'HFA'},
}, {nowiki=1})
end
function p:test_with_undefined_class_and_article_class()
self:preprocess_equals_many('{{#invoke:' .. module .. ' | quality |class=', '|page=Talk:Oxford spelling}}', {
{'xyz', 'Y'},
{'Stub1', 'Y'},
{'dfd', 'Y'},
{'', 'Y'},
}, {nowiki=1})
end
function p:test_with_undefined_or_invalid_project_class_ignoring_namespace()
self:preprocess_equals_many('{{#invoke:' .. module .. ' | quality |class=', ' |page=Talk:2011 Atlanta Falcons season}}', {
{'xyz', 'HStart'},
{'Stub1', 'HStart'},
{'dfd', 'HStart'},
{'start', 'HStart'},
{'', 'HStart'},
{'B', 'XB'},
}, {nowiki=1})
end
function p:test_non_articles_classes_with_extended_scale_on_dab_page()
self:preprocess_equals_many('{{#invoke:' .. module .. ' | quality |class=', ' | QUALITY_SCALE=extended |page=Talk:Tropical World}}', {
{'NA', 'HNA'},
{'Template', 'HTemplate'},
{'dfd', 'HDisambig'},
{'', 'HDisambig'},
{'project', 'HProject'},
{'Start', 'XStart'},
{'dab', 'HDisambig'},
}, {nowiki=1})
end
function p:test_non_articles_classes_ignoring_namespace()
self:preprocess_equals_many('{{#invoke:' .. module .. ' | quality |class=', ' |page=Template talk:Germany-silent-film-stub}}', {
{'NA', 'HNA'},
{'C', 'XC'},
{'dfd', 'HNA'},
{'', 'HNA'},
{'project', 'HNA'},
{'redir', 'HNA'},
}, {nowiki=1})
end
function p:test_subpage_mask()
self:preprocess_equals_many('{{#invoke:' .. module .. ' | quality |class=', '|page=Talk:Christian Coleman |BANNER_NAME=Template:WikiProject Plants | QUALITY_SCALE=subpage}}', {
{'SL', 'XSL'},
{'c', 'HC'},
{'sausage', 'XTemplate'},
{'', 'XTemplate'},
{'fm', 'XFM'},
{'redir', 'XRedirect'},
}, {nowiki=1})
end
function p:test_inline_mask()
self:preprocess_equals_many('{{#invoke:' .. module .. ' | quality |class=Future|page=', '| QUALITY_SCALE=inline}}', {
{'Talk:James Abbott Thompson', 'YFuture'},
{'Talk:Henri-Charles de Beaumanoir of Lavardin', 'YFuture'},
{'Talk:Philippe Cattiau', 'XFuture'},
{'Template talk:Germany-silent-film-stub', 'XFuture'},
{'Talk:Siege of Arrah', 'XFuture'},
{'Talk:Tropical World', 'XFuture'},
}, {nowiki=1})
end
function p:test_noprefix()
self:preprocess_equals_many('{{#invoke:' .. module .. ' | quality |class=', ' |noprefix=true | QUALITY_SCALE=extended |page=Talk:Siege of Arrah}}', {
{'B', 'B'},
{'Template', 'Template'},
{'dfd', 'A'},
{'', 'A'},
{'project', 'Project'},
{'Start', 'Start'},
}, {nowiki=1})
end
function p:test_with_redirect_and_no_inherited_class()
self:preprocess_equals_many('{{#invoke:' .. module .. ' | quality |class=', '| page=Talk:James Abbott Thompson}}', {
{'', 'YNA'},
{'B', 'YB'},
{'hjfhjh', 'YNA'},
{'NA', 'YNA'},
}, {nowiki=1})
end
return p