summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorfesily <fesil@foxmail.com>2024-01-17 17:02:31 +0800
committerfesily <fesil@foxmail.com>2024-01-17 17:04:01 +0800
commitd315c3a271ecffe4d98fabf3e4bac58f71aa8677 (patch)
treec86604bfc6573aa77f406922775388655c674a0b /test
parent5f0cba4fef00f1c426052af421443bd72d38c8aa (diff)
downloadlua-language-server-d315c3a271ecffe4d98fabf3e4bac58f71aa8677.zip
add test
Diffstat (limited to 'test')
-rw-r--r--test/plugins/node/test.lua52
-rw-r--r--test/plugins/test.lua1
2 files changed, 53 insertions, 0 deletions
diff --git a/test/plugins/node/test.lua b/test/plugins/node/test.lua
new file mode 100644
index 00000000..81d9a1b3
--- /dev/null
+++ b/test/plugins/node/test.lua
@@ -0,0 +1,52 @@
+local files = require 'files'
+local scope = require 'workspace.scope'
+local nodeHelper = require 'plugins.nodeHelper'
+local vm = require 'vm'
+local guide = require 'parser.guide'
+
+
+local pattern, msg = nodeHelper.createFieldPattern("*.components")
+assert(pattern, msg)
+
+---@param source parser.object
+function OnNodeCompileFunctionParam(uri, source)
+ --从该参数的使用模式来推导该类型
+ if nodeHelper.matchPattern(source, pattern) then
+ local type = vm.declareGlobal('type', 'TestClass', TESTURI)
+ return vm.createNode(type, source)
+ end
+end
+
+local myplugin = { OnNodeCompileFunctionParam = OnNodeCompileFunctionParam }
+
+---@diagnostic disable: await-in-sync
+local function TestPlugin(script)
+ local prefix = [[
+ ---@class TestClass
+ ---@field b string
+ ]]
+ ---@param checker fun(state:parser.state)
+ return function (plugin, checker)
+ files.open(TESTURI)
+ files.setText(TESTURI, prefix .. script, true)
+ scope.getScope(TESTURI):set('pluginInterface', plugin)
+ local state = files.getState(TESTURI)
+ assert(state)
+ checker(state)
+ files.remove(TESTURI)
+ end
+end
+
+TestPlugin [[
+ local function t(a)
+ a.components:test()
+ end
+]](myplugin, function (state)
+ guide.eachSourceType(state.ast, 'local', function (src)
+ if guide.getKeyName(src) == 'a' then
+ local node = vm.compileNode(src)
+ assert(node)
+ assert(not vm.isUnknown(node))
+ end
+ end)
+end)
diff --git a/test/plugins/test.lua b/test/plugins/test.lua
index 655d30b8..53a92cc8 100644
--- a/test/plugins/test.lua
+++ b/test/plugins/test.lua
@@ -1,2 +1,3 @@
require 'plugins.ast.test'
require 'plugins.ffi.test'
+require 'plugins.node.test' \ No newline at end of file