Zum Inhalt springen

„Modul:DateTime/test“ – Versionsunterschied

aus Wikipedia, der freien Enzyklopädie
[gesichtete Version][gesichtete Version]
Inhalt gelöscht Inhalt hinzugefügt
update
update
Zeile 1: Zeile 1:
--[=[ 2014-02-05
--[=[ 2014-02-26
Debug Module:DateTime
Debug Module:DateTime
]=]
]=]
Zeile 21: Zeile 21:
"msec",
"msec",
"zone" }
"zone" }



local function fault( a )
-- Formatiere Fehler mit class=error
return string.format( "<span class=\"error\">%s</span>", a )
end -- fault()




Zeile 67: Zeile 74:
end
end
if score ~= suppose then
if score ~= suppose then
r = r .. " || '''!!!'''"
r = string.format( "%s || %s",
r, fault( "!!!!!!!!!!" ) )
end
end
end
end
Zeile 79: Zeile 87:
return r
return r
end -- Tests.fetcher()
end -- Tests.fetcher()



Tests.follow = function ( args )
-- Evaluate sort function
-- Parameter:
-- args -- template parameters
-- 2 -- string to be interpreted
-- 3 -- string with heading cell, or empty
-- r -- expected result (number)
-- Returns:
-- string with table row
local r = "|-\n| "
local l, d = pcall( require, "Module:DateTime/sort" )
if l then
local source = args[ 2 ] or ""
local sort = d.figure( source, false )
local suppose = args.r or ""
if args[ 3 ] then
r = string.format( "%s%s || ", r, args[ 3 ] )
end
r = string.format( "%s%s || <code>%s</code> || ",
r, source, sort )
if sort == suppose then
r = string.format( "%s<code>%s</code>", r, suppose )
else
r = string.format( "%s%s !!!!!!!!!!",
r, fault( suppose ) )
end
end
return r
end -- Tests.follow()




Zeile 106: Zeile 146:
if r ~= args.r then
if r ~= args.r then
local should = ( args.r or "" )
local should = ( args.r or "" )
r = string.format( "<span class=\"error\">%s</span><br />%s",
r = string.format( "%s<br />%s",
r, should )
fault( r ), should )
end
end
r = string.format( "%s<br />%s",
r = string.format( "%s<br />%s",
r, syntax )
r, syntax )
else
else
r = "<span class=\"error\">???????</span>"
r = fault( "???????" )
end
end
r = string.format( "\n==== \"%s\" ====\n%s<br />%s",
r = string.format( "\n==== \"%s\" ====\n%s<br />%s",

Version vom 26. Februar 2014, 22:42 Uhr

Vorlagenprogrammierung Diskussionen Lua Test Unterseiten
Modul Deutsch English

Modul: Dokumentation

Diese Seite enthält Code in der Programmiersprache Lua. Einbindungszahl Cirrus


--[=[ 2014-02-26
Debug Module:DateTime
]=]


-- local globals
local DateTime = require( "Module:DateTime" )
DateTime = DateTime.DateTime
local Tests = { }
local Params = { "lang",
                 "bc",
                 "year",
                 "month",
                 "month2",
                 "dom",
                 "dom2",
                 "hour",
                 "hour2",
                 "min",
                 "sec",
                 "msec",
                 "zone" }



local function fault( a )
    -- Formatiere Fehler mit class=error
    return string.format( "<span class=\"error\">%s</span>", a )
end -- fault()



Tests.fetcher = function ( args )
    -- Evaluate constructor function
    -- Parameter:
    --     args  -- template parameters
    --              2    -- string to be interpreted, or empty
    --              ***  --  expected field values, k=v
    -- Returns:
    --     string
    local r
    local s = ( args[ 2 ] or "" )
    local o = DateTime( s )
    if s == "" then
        r = "\n==== fetcher() ====\n"
    else
        r = string.format( "\n==== %s ====\n", s )
    end
    if o then
        local n = table.maxn( Params )
        local score, single, suppose
        s = mw.text.trim( s )
        if s == "" then
            s = "''empty''"
        end
        r = r ..
            "{| class='wikitable'\n" ..
            "|-\n" ..
            "! item !! expect !! got !! diff\n"
        for i = 1, n do
            single  = Params[ i ]
            score   = o[ single ]
            suppose = args[ single ]
            if score ~= nil  or  suppose ~= nil then
                r = string.format( "%s\n|-\n| %s || ", r, single )
                if suppose then
                    r = string.format( "%s<code>%s</code>", r, suppose )
                end
                r = r .. " || "
                if score ~= nil then
                    score = tostring( score )
                    r     = string.format( "%s<code>%s</code>",
                                           r, score )
                end
                if score ~= suppose then
                    r = string.format( "%s || %s",
                                       r,  fault( "!!!!!!!!!!" ) )
                end
            end
        end -- for i
        r = r .. "\n|}\n"
    elseif args.failed then
        r = r .. "'''failed'''"
    else
        r = r .. "<span class=\"error\">FAILED</span>"
    end
    return r
end -- Tests.fetcher()



Tests.follow = function ( args )
    -- Evaluate sort function
    -- Parameter:
    --     args  -- template parameters
    --              2  -- string to be interpreted
    --              3  -- string with heading cell, or empty
    --              r  -- expected result (number)
    -- Returns:
    --     string with table row
    local r = "|-\n| "
    local l, d = pcall( require, "Module:DateTime/sort" )
    if l then
        local source  = args[ 2 ] or ""
        local sort    = d.figure( source, false )
        local suppose = args.r or ""
        if args[ 3 ] then
            r = string.format( "%s%s || ", r, args[ 3 ] )
        end
        r = string.format( "%s%s || <code>%s</code> || ",
                           r, source, sort )
        if sort == suppose then
            r = string.format( "%s<code>%s</code>", r, suppose )
        else
            r = string.format( "%s%s !!!!!!!!!!",
                               r, fault( suppose ) )
        end
    end
    return r
end -- Tests.follow()



Tests.formatter = function ( args )
    -- Evaluate formatting function
    -- Parameter:
    --     args  -- template parameters
    --              2  -- string to be interpreted, or empty
    --              3  -- string with format, or empty
    --              r  -- expected result
    -- Returns:
    --     string
    local r
    local source = ( args[ 2 ] or "" )
    local o = DateTime( source )
    local shower = ( args[ 3 ] or "" )
    if o then
        r = o:format( shower, "de" )
    end
    if r then
        local syntax = mw.getCurrentFrame():callParserFunction(
                                                  "#tag:syntaxhighlight",
                                                  { r,
                                                    lang="text",
                                                    enclose="none" } )
        if r ~= args.r then
            local should = ( args.r or "" )
            r = string.format( "%s<br />%s",
                               fault( r ),  should )
        end
        r = string.format( "%s<br />%s",
                           r, syntax )
    else
        r = fault( "???????" )
    end
    r = string.format( "\n==== \"%s\" ====\n%s<br />%s",
                       shower, source, r )
    return r
end -- Tests.formatter()



-- Export
local p = { }

function p.f( frame )
    local r, fun
    local params = frame:getParent().args
    local fun    = params[ 1 ]
    if fun then
        local l
        l, r = pcall( Tests[ fun ], params  )
    end
    return r
end -- f

return p