Documentation for this module may be created at Module:EpisodeText/doc

local p = {}
local data = mw.loadData("Module:EpisodeText/data")

function p.main(frame)
    local args = require("Dev:Arguments").getArgs(frame, {
        parentFirst = true,
        wrappers = {
            "Template:EpisodeText",
        },
    })
    return p._main(args[1])
end

function p._main(level)
    local text = data[tonumber(level)]
    if not text then return nil end
    local displayText = string.match(text, "(.-)%s*%(Episode %d+%)")
    if displayText then
        text = text .. '|' .. displayText
    end
    return text
end

function p.test(frame)
    -- TODO: Use a proper unit test module.
    local expected, actual
    expected = "Chocolate Mountains"
    actual = p._main(4)
    assert(expected == actual, string.format('Expected %q but got %q', tostring(expected), tostring(actual)))

    expected = "Minty Meadow (Episode 5)|Minty Meadow"
    actual = p._main(5)
    assert(expected == actual, string.format('Expected %q but got %q', tostring(expected), tostring(actual)))

    actual = p._main(-42)
    assert(actual == nil, string.format('Expected nil but got %q', tostring(actual)))

    actual = p._main("Hello World")
    assert(actual == nil, string.format('Expected nil but got %q', tostring(actual)))

    return "All tests OK"
end

return p
Community content is available under CC-BY-SA unless otherwise noted.