summaryrefslogtreecommitdiff
path: root/server/test/find_lib/init.lua
blob: 26dbc8936ccfc8929adba167b1ef29b3be75f961 (plain)
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 results = matcher.compile(ast)
        assert(results)
        local result = matcher.findResult(results, pos)
        assert(result)
        assert(result.type == 'var')
        local var = result.var
        assert(var)
        local _, name = matcher.findLib(var)
        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?>)
]]