summaryrefslogtreecommitdiff
path: root/server/test
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2018-12-12 21:15:27 +0800
committer最萌小汐 <sumneko@hotmail.com>2018-12-12 21:15:27 +0800
commitd76d63f7063376852ee9c8ea6795abde09149851 (patch)
tree5067140e9d592e5e401fe448186592026e59a133 /server/test
parent3ce89009f9e37193a00aa3eefb09f46eaff409c7 (diff)
downloadlua-language-server-d76d63f7063376852ee9c8ea6795abde09149851.zip
非函数的hover
Diffstat (limited to 'server/test')
-rw-r--r--server/test/hover/init.lua57
1 files changed, 48 insertions, 9 deletions
diff --git a/server/test/hover/init.lua b/server/test/hover/init.lua
index 55931339..e3ad7be2 100644
--- a/server/test/hover/init.lua
+++ b/server/test/hover/init.lua
@@ -4,27 +4,34 @@ local matcher = require 'matcher'
rawset(_G, 'TEST', true)
function TEST(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)
- local vm = matcher.vm(ast)
- assert(vm)
- local result = matcher.hover(vm, pos)
- assert(result)
+ return function (expect)
+ 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)
+ local vm = matcher.vm(ast)
+ assert(vm)
+ local result = matcher.hover(vm, pos)
+ assert(result)
+ expect = expect:gsub('^[\r\n]*(.-)[\r\n]*$', '%1')
+ result = result:gsub('```lua', ''):gsub('```', ''):gsub('^[\r\n]*(.-)[\r\n]*$', '%1')
+ assert(expect == result)
+ end
end
TEST [[
local function <?x?>(a, b)
end
]]
+"function x(a: any, b: any)"
TEST [[
local function x(a, b)
end
<?x?>()
]]
+"function x(a: any, b: any)"
TEST [[
local mt = {}
@@ -38,6 +45,10 @@ local obj = setmetatable({}, mt)
obj:<?init?>(1, '测试')
]]
+[[
+function mt:init(a: number, b: string, c: any)
+ -> table
+]]
TEST [[
local mt = {}
@@ -52,6 +63,10 @@ local obj = setmetatable({}, mt)
obj:init(1, '测试')
obj.<?init?>(obj, 1, '测试')
]]
+[[
+function mt.init(self: table, a: number, b: string, c: any)
+ -> table
+]]
TEST [[
function obj.xxx()
@@ -59,7 +74,31 @@ end
obj.<?xxx?>()
]]
+"function obj.xxx()"
TEST [[
obj.<?xxx?>()
]]
+"function obj.xxx()"
+
+TEST [[
+local <?x?> = 1
+]]
+"local: number"
+
+TEST [[
+<?x?> = 1
+]]
+"global: number"
+
+TEST [[
+local t = {}
+t.<?x?> = 1
+]]
+"local field: number"
+
+TEST [[
+t = {}
+t.<?x?> = 1
+]]
+"global field: number"