Modul:Autocategories/testtilfeller

Fra Wikipedia, den frie encyklopedi


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

function p:test_run()
    self:preprocess_equals('{{#invoke:Autocategories|run|P1|P2|P3}}', 'P1, P2, P3')
    self:preprocess_equals('{{#invoke:Autocategories|run|P910}}', 'P910')
end

function p:test_findPidsInFrames()
    self:equals_deep("A single argument 'P1' in a single frame should be kept", ac._findPidsInFrames({ args={'P1'}}), { P1=true })
    self:equals_deep("A single argument 'P1' in a single frame should be kept", ac._findPidsInFrames({ args={'!P1'}}), {})
    self:equals_deep("A single argument 'P1' in two frames should be kept", ac._findPidsInFrames({ args={'P1'}}, { args={'P1'}}), { P1=true })
    self:equals_deep("A single argument 'P1' and another '!P1' should be dropped", ac._findPidsInFrames({ args={'P1'}}, { args={'!P1'}}), {})
    self:equals_deep("A arguments 'P1, P2' and '!P1' should keep 'P2'", ac._findPidsInFrames({ args={'P1, P2'}}, { args={'!P1'}}), { P2=true })
end

function p:test_findPidsInArgs()
    self:equals_deep("A single argument 'P1' should be kept", ac._findPidsInArgs({}, { 'P1' }), { P1=true })
    self:equals_deep("A single argument '!P1' should be dropped", ac._findPidsInArgs({}, { '!P1' }), {})
    self:equals_deep("Two arguments 'P1' and 'P1' should be kept", ac._findPidsInArgs({}, { 'P1', 'P1' }), { P1=true })
    self:equals_deep("Two arguments '!P1' and 'P1' should be kept", ac._findPidsInArgs({}, {'!P1', 'P1' }), { P1=true })
    self:equals_deep("Two arguments 'P1' and '!P1' should be dropped", ac._findPidsInArgs({}, {'P1', '!P1'}), {})
    self:equals_deep("Two arguments '!P1' and '!P1' should be dropped", ac._findPidsInArgs({}, {'!P1', '!P1'}), {})
end

return p