Fandom Developers Wiki
No edit summary
Tag: sourceedit
No edit summary
Tag: sourceedit
Line 47: Line 47:
 
local p ={
 
local p ={
 
get_functions={--functioname
 
get_functions={--functioname
options={nowiki=false}, --options
+
options={nowiki=true}, --options
 
tests = {
 
tests = {
 
equals_deep ={
 
equals_deep ={

Revision as of 15:26, 12 November 2016

This module contains testcases for its parent module, Codedoc.

See also


-- <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=true}, --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