summaryrefslogtreecommitdiff
path: root/test-beta/definition/special.lua
blob: 6bbf104c669722883b9926a3769b53aba6cd3a58 (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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
TEST [[
_ENV.<!x!> = 1
print(<?x?>)
]]

TEST [[
_G.<!x!> = 1
print(<?x?>)
]]

TEST [[
<!rawset(_G, 'x', 1)!>
print(<?x?>)
]]

TEST [[
local mt
mt.__index = mt
function mt:<!method1!>()
end

local obj = setmetatable({}, mt)
obj:<?method1?>()
]]

TEST [[
local mt
function mt:<!method1!>()
end

local obj = setmetatable({}, { __index = mt })
obj:<?method1?>()
]]

TEST [[
local mt
function mt:<!method1!>()
end

setmetatable(api, { __index = mt })
api:<?method1?>()
]]

TEST [[
local mt
local api
function mt:<!method1!>()
end

setmetatable(api, { __index = mt })
api:<?method1?>()
]]

TEST [[
local mt
function mt:x()
    self.<?init?>()
end

local obj, _ = setmetatable({}, { __index = mt })
obj.<!init!> = 1
obj:x()
]]

TEST [[
local mt
function mt:x()
    self.<?init?>()
end

local obj = setmetatable({ <!init!> = 1 }, { __index = mt })
obj:x()
]]

TEST [[
local mt
function mt:x()
    self.a.<?out?>()
end

local obj = setmetatable({
    a = {
        <!out!> = 1,
    }
}, { __index = mt })
obj:x()
]]

TEST [[
local sm = setmetatable
local mt
mt.__index = mt
function mt:<!method1!>()
end

local obj = sm({}, mt)
obj:<?method1?>()
]]

-- TODO
--TEST [[
--local mt = {}
--function mt:<!x!>()
--end
--
--local obj = setmetatable({}, {__index = mt})
--function obj:x()
--end
--
--mt:<?x?>()
--]]

-- TODO 通过代码执行顺序来判断
--TEST [[
--local mt = {}
--function mt:x()
--end
--
--local obj = setmetatable({}, {__index = mt})
--function obj:<!x!>()
--end
--
--obj:<?x?>()
--]]