dev

This module contains testcases for its parent module, Entrypoint.

See also


-- <nowiki>
local suite = require('Module:ScribuntoUnit'):new()
local frame = mw.getCurrentFrame()

local isUCP = tonumber(mw.site.currentVersion:match('^%d+.%d+')) >= 1.25

--- Testharness preprocessor.
local function pp(str)
    return mw.text.trim(frame:preprocess(str))
end

-- Entrypoint tests for dependent modules.
-- Tests for equivalent behaviour between invocations and template transclusions.
-- Borrows invocation tests from Testharness test suites.
for _, modulename in ipairs{'Calculator', 'Colors', 'I18n', 'String'} do
    suite['test'.. modulename] = function(self)
        if modulename == 'Colors' and isUCP then
            self:markTestSkipped('Module:Colors is not UCP compatible.')
        end

        require('Module:' .. modulename)
        local tests = require('Module:' .. modulename .. '/testcases')
        local members = {}
        for member in pairs(tests) do
            table.insert(members, member)
        end
        table.sort(members)

        local is_preprocessed, test_address
        for _, member in ipairs(members) do
            data = tests[member]
            if
                member ~= 'main' and
                data.options.mode == 'invocation' and
                not data.options.template
            then
                for index, test in ipairs(data.tests) do
                    if
                        type(test[1]) == 'string' and
                        not test[1]:find('^%d%s*=') and
                        not test[1]:find('%s*|%d%s*=')
                    then
                        is_preprocessed = data.options.preprocess or (test[3] or {}).pp
                        test_address = member .. '#' .. index .. ': '
                        self:assertEquals(
                            test_address .. (is_preprocessed and pp(test[2]) or mw.text.trim(test[2])),
                            test_address .. pp('{{'.. modulename ..'|' ..  member .. '|' .. test[1] .. '}}')
                        )
                    end
                end
            end
        end
    end
end

return suite