diff options
author | fesily <fesil@foxmail.com> | 2024-01-10 11:02:43 +0800 |
---|---|---|
committer | fesily <fesil@foxmail.com> | 2024-01-10 11:02:43 +0800 |
commit | bb6e172d6166190bd4edd3bb56230a7d60ebcb93 (patch) | |
tree | 935bd5608abf778319521a51216d22f5051c26ab /test/plugins | |
parent | 94a1cef1100621082b7f56d0a0fdd46c0662a79f (diff) | |
download | lua-language-server-bb6e172d6166190bd4edd3bb56230a7d60ebcb93.zip |
astHelper: addParamTypeDoc
Diffstat (limited to 'test/plugins')
-rw-r--r-- | test/plugins/ast/helper.lua | 64 | ||||
-rw-r--r-- | test/plugins/ast/test.lua (renamed from test/plugins/ast/init.lua) | 7 | ||||
-rw-r--r-- | test/plugins/test.lua | 2 |
3 files changed, 68 insertions, 5 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) diff --git a/test/plugins/ast/init.lua b/test/plugins/ast/test.lua index ac2f7079..f13b33a2 100644 --- a/test/plugins/ast/init.lua +++ b/test/plugins/ast/test.lua @@ -1,14 +1,9 @@ -local config = require 'config' -local utility = require 'utility' local parser = require 'parser' -local luadoc = require 'parser.luadoc' local guide = require 'parser.guide' -local vm = require 'vm' local helper = require 'plugins.astHelper' ---@diagnostic disable: await-in-sync local function TestPlugin(script, plugin, checker) - config.set(TESTURI, 'Lua.workspace.preloadFileSize', 1000000000) local state = parser.compile(script, "Lua", "Lua 5.4") state.ast = plugin(TESTURI, state.ast) or state.ast parser.luadoc(state) @@ -90,3 +85,5 @@ TestPlugin2 [[ TestPlugin2 [[ function ctor(self) end ]] + +require 'plugins.ast.helper'
\ No newline at end of file diff --git a/test/plugins/test.lua b/test/plugins/test.lua new file mode 100644 index 00000000..d73bfac2 --- /dev/null +++ b/test/plugins/test.lua @@ -0,0 +1,2 @@ +require 'plugins.ast.test' +require 'plugins.ffi.test'
\ No newline at end of file |