Module:Suppress categories/testcases

-- Unit tests for [[Module:Suppress categories]]. Click talk page to run tests.
local p = require('Module:UnitTests')

function p:test_main()
    self:preprocess_equals_many('{{#invoke:Suppress categories|main|', '}}', {
        {'foo', 'foo'},
        {'foo[[Category:Some category]]', 'foo'},
        {'foo[[Category:Some category]]bar[[Category:Another category]]', 'foobar'},
        {'foo{{{some_parameter|[[Category:Bar]]}}}', 'foo'},
        {'foo[[Category:Bad ca[]tegory link]]', 'foo[[Category:Bad ca[]tegory link]]'},
        {'foo[[:Category:Colon trick]]', 'foo[[:Category:Colon trick]]'},
        {'foo[[Category:Piped link|bar]]', 'foo'},
        {'foo[[Category:Piped link|ba[]r]]', 'foo'},
        {'foo[[non-category link]]', 'foo[[non-category link]]'},
        {'foo[[ Category : Some category with spaces ]]', 'foo'},
    }, {nowiki = 'yes'})
end

function p:test_nested()
    self:preprocess_equals_many('{{#invoke:Suppress categories|main|', '}}', {
        {'[[Category:Fo[[Category:Bar]]o]]', '[[Category:Fo<span style="display: none;">[[]]</span>o]]'},
        {'[[Category:Foo|b[[Category:Baz]]ar]]', '[[Category:Foo|b<span style="display: none;">[[]]</span>ar]]'},
        {'[[Category:Foo|ba[[Category:Baz|ba[[Category:Foobar|Bazbat]]m]]r]]', '[[Category:Foo|ba[[Category:Baz|ba<span style="display: none;">[[]]</span>m]]r]]'},
        {'[[Category:Foo|b[a[[Category:Baz|bam]]r]]', '[[Category:Foo|b[a<span style="display: none;">[[]]</span>r]]'}
    }, {nowiki = 'yes'})
end

return p