Skip to content

Commit d315c3a

Browse files
committed
add test
1 parent 5f0cba4 commit d315c3a

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

test/plugins/node/test.lua

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
local files = require 'files'
2+
local scope = require 'workspace.scope'
3+
local nodeHelper = require 'plugins.nodeHelper'
4+
local vm = require 'vm'
5+
local guide = require 'parser.guide'
6+
7+
8+
local pattern, msg = nodeHelper.createFieldPattern("*.components")
9+
assert(pattern, msg)
10+
11+
---@param source parser.object
12+
function OnNodeCompileFunctionParam(uri, source)
13+
--从该参数的使用模式来推导该类型
14+
if nodeHelper.matchPattern(source, pattern) then
15+
local type = vm.declareGlobal('type', 'TestClass', TESTURI)
16+
return vm.createNode(type, source)
17+
end
18+
end
19+
20+
local myplugin = { OnNodeCompileFunctionParam = OnNodeCompileFunctionParam }
21+
22+
---@diagnostic disable: await-in-sync
23+
local function TestPlugin(script)
24+
local prefix = [[
25+
---@class TestClass
26+
---@field b string
27+
]]
28+
---@param checker fun(state:parser.state)
29+
return function (plugin, checker)
30+
files.open(TESTURI)
31+
files.setText(TESTURI, prefix .. script, true)
32+
scope.getScope(TESTURI):set('pluginInterface', plugin)
33+
local state = files.getState(TESTURI)
34+
assert(state)
35+
checker(state)
36+
files.remove(TESTURI)
37+
end
38+
end
39+
40+
TestPlugin [[
41+
local function t(a)
42+
a.components:test()
43+
end
44+
]](myplugin, function (state)
45+
guide.eachSourceType(state.ast, 'local', function (src)
46+
if guide.getKeyName(src) == 'a' then
47+
local node = vm.compileNode(src)
48+
assert(node)
49+
assert(not vm.isUnknown(node))
50+
end
51+
end)
52+
end)

test/plugins/test.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
require 'plugins.ast.test'
22
require 'plugins.ffi.test'
3+
require 'plugins.node.test'

0 commit comments

Comments
 (0)