summaryrefslogtreecommitdiff
path: root/server/test
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-08-27 14:06:19 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-08-27 14:06:19 +0800
commita90fa730acdbd823e556dcbc66ab8a360650c290 (patch)
treed2a833f6fd46bebbef204f2d88f7dff40a900f7b /server/test
parent1fd5d5954f1c95b97dd9c5ab1c4dabb714bd5003 (diff)
downloadlua-language-server-a90fa730acdbd823e556dcbc66ab8a360650c290.zip
诊断未使用的局部函数
Diffstat (limited to 'server/test')
-rw-r--r--server/test/diagnostics/init.lua52
1 files changed, 40 insertions, 12 deletions
diff --git a/server/test/diagnostics/init.lua b/server/test/diagnostics/init.lua
index 981133f5..70a6c586 100644
--- a/server/test/diagnostics/init.lua
+++ b/server/test/diagnostics/init.lua
@@ -5,18 +5,26 @@ local service = require 'service'
rawset(_G, 'TEST', true)
-local function catch_target(script)
+local function catch_target(script, ...)
local list = {}
- local cur = 1
- local cut = 0
- while true do
- local start, finish = script:find('<!.-!>', cur)
- if not start then
- break
+ local function catch(buf)
+ local cur = 1
+ local cut = 0
+ while true do
+ local start, finish = buf:find('<!.-!>', cur)
+ if not start then
+ break
+ end
+ list[#list+1] = { start - cut, finish - 4 - cut }
+ cur = finish + 1
+ cut = cut + 4
+ end
+ end
+ catch(script)
+ if ... then
+ for _, buf in ipairs {...} do
+ catch(buf)
end
- list[#list+1] = { start - cut, finish - 4 - cut }
- cur = finish + 1
- cut = cut + 4
end
local new_script = script:gsub('<!(.-)!>', '%1')
return new_script, list
@@ -38,8 +46,8 @@ local function founded(targets, results)
return true
end
-function TEST(script)
- local new_script, target = catch_target(script)
+function TEST(script, ...)
+ local new_script, target = catch_target(script, ...)
local lsp = service()
local ast = parser:ast(new_script, 'lua', 'Lua 5.3')
assert(ast)
@@ -65,6 +73,26 @@ TEST [[
local <!x!>
]]
+TEST([[
+<!local function x()
+end!>
+]],
+[[
+local function <!x!>()
+end
+]]
+)
+
+TEST [[
+local <!x!> = <!function () end!>
+]]
+
+TEST [[
+local <!x!>
+x = <!function () end!>
+]]
+
+
TEST [[
print(<!x!>)
print(<!log!>)