FANDOM


-- <nowiki>Unit tests.  Click talk page to run tests.
-- ==test data 1 ==
---
local FUNC_PREF = '%%@:Tb-'
-- special patterns
local FUNC_PTRN = '^%s*(f)unction%s+([%w:._]*)'
local FUNC_LOCAL_PTRN = '^%s*local%s+(f)unction%s+([%w:._]*)'
 
local func_definition1 = [=[--% Build function commentary structure from text
--@ test(string) program code
--: (table) function structure
function testfunction (test)
    return {}
end
]=]
local func_definition2 = [=[--% Build function commentary structure from text
--@ test(string) program code
--: (table) function structure
local function _testfunction (test)
    return {}
end
]=]
-- ==Expected results ==
-- For get_functions
local expectedFuncTable1 = { {
   name = "testfunction",
   parameters = { {
       name = "test",
       purpose = "program code.",
       type = "string"
     } },
   purpose = "Build function commentary structure from text..",
   returns = { {
       purpose = "function structure.",
       type = "table"
     } }
 } } 
local expectedFuncTable2 = mw.clone(expectedFuncTable1)
expectedFuncTable2[1].name = "_testfunction"
-- For scan_lines
local scan_linesTable = {{ "%", "Build function commentary structure from text" }, { "@", "test(string) program code" }, { ":", "(table) function structure" }, { "f", "testfunction" }, ["n"] = 0}
-----------
 
local procsrc = require "Module:Codedoc/Procsrc"
local dbg = require "Module:Debug"
---
local p ={
    get_functions={--functioname
        options={nowiki=1}, --options 
        tests = {
            equals_deep ={
                {'test table with functions', procsrc:get_functions(func_definition1), expectedFuncTable1},
                {'Test table with local functions', procsrc:get_functions(func_definition2), expectedFuncTable2},
                {'Gets table with everything', procsrc:scan_lines(func_definition1, FUNC_PREF , FUNC_PTRN), scan_linesTable},
            },
        },
    },
}
 
return p

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.