1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
local matcher = require 'matcher'
local parser = require 'parser'
rawset(_G, 'TEST', true)
function TEST(fullkey)
return function (script)
local start = script:find('<?', 1, true)
local finish = script:find('?>', 1, true)
local pos = (start + finish) // 2 + 1
local new_script = script:gsub('<[!?]', ' '):gsub('[!?]>', ' ')
local ast = parser:ast(new_script)
assert(ast)
local vm = matcher.vm(ast)
assert(vm)
local result = matcher.findResult(vm, pos)
local _, name = matcher.findLib(result)
assert(name == fullkey)
end
end
TEST 'require' [[
<?require?> 'xxx'
]]
TEST 'require' [[
local <?req?> = require
]]
TEST 'require' [[
local req = require
local t = {
xx = req,
}
t[<?'xx'?>]()
]]
TEST 'table' [[
<?table?>.unpack()
]]
TEST 'table' [[
local <?xx?> = require 'table'
]]
TEST 'table' [[
local rq = require
local lib = 'table'
local <?xx?> = rq(lib)
]]
TEST 'table.insert' [[
table.<?insert?>()
]]
TEST 'table.insert' [[
local t = table
t.<?insert?>()
]]
TEST 'table.insert' [[
local insert = table.insert
<?insert?>()
]]
TEST 'table.insert' [[
local t = require 'table'
t.<?insert?>()
]]
TEST 'table.insert' [[
require 'table'.<?insert?>()
]]
TEST '*string:sub' [[
local str = 'xxx'
str.<?sub?>()
]]
TEST '*string:sub' [[
local str = 'xxx'
str:<?sub?>(1, 1)
]]
TEST '*string:sub' [[
('xxx').<?sub?>()
]]
TEST 'bee::filesystem' [[
local <?fs?> = require 'bee.filesystem'
]]
TEST 'fs.current_path' [[
local filesystem = require 'bee.filesystem'
ROOT = filesystem.<?current_path?>()
]]
TEST(nil)[[
print(<?insert?>)
]]
TEST '_G' [[
local x = <?_G?>
]]
|