diff options
Diffstat (limited to 'test/plugins/ast/helper.lua')
-rw-r--r-- | test/plugins/ast/helper.lua | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/test/plugins/ast/helper.lua b/test/plugins/ast/helper.lua new file mode 100644 index 00000000..f892ea1b --- /dev/null +++ b/test/plugins/ast/helper.lua @@ -0,0 +1,64 @@ +local helper = require 'plugins.astHelper' +local parser = require 'parser' + +function Run(script, plugin) + local state = parser.compile(script, "Lua", "Lua 5.4") + plugin(state) + parser.luadoc(state) + return state +end + +local function TestInsertDoc(script) + local state = Run(script, function (state) + local comment = assert(helper.buildComment("class", "AA", state.ast[1].start)) + helper.InsertDoc(state.ast, comment) + end) + assert(state.ast[1].bindDocs) +end + +TestInsertDoc("A={}") + +local function TestaddClassDoc(script) + local state = Run(script, function (state) + assert(helper.addClassDoc(state.ast, state.ast[1], "AA")) + end) + assert(state.ast[1].bindDocs) +end + +TestaddClassDoc [[a={}]] + +TestaddClassDoc [[local a={}]] + +local function TestaddClassDocAtParam(script, index) + index = index or 1 + local arg + local state = Run(script, function (state) + local func = state.ast[1].value + local ok + ok, arg = helper.addClassDocAtParam(state.ast, "AA", func, index) + assert(ok) + end) + assert(arg.bindDocs) +end + +TestaddClassDocAtParam [[ + function a(b) end +]] + +local function TestaddParamTypeDoc(script, index) + index = index or 1 + local func + Run(script, function (state) + func = state.ast[1].value + assert(helper.addParamTypeDoc(state.ast, "string", func.args[index])) + end) + assert(func.args[index].bindDocs) +end + +TestaddParamTypeDoc [[ + local function t(a)end +]] + +TestaddParamTypeDoc([[ + local function t(a,b,c,d)end +]], 4) |