summaryrefslogtreecommitdiff
path: root/server/test
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2018-11-30 14:58:26 +0800
committer最萌小汐 <sumneko@hotmail.com>2018-11-30 14:58:26 +0800
commitb12c90d26fe0e99fb77f22ebbedc4411794133d2 (patch)
tree5cd7acebb2bb8785cc3f61e123cb98036892c916 /server/test
parentbad3834c8f6f6b462e8ef968f28e2e49929fbe65 (diff)
downloadlua-language-server-b12c90d26fe0e99fb77f22ebbedc4411794133d2.zip
支持多返回值
Diffstat (limited to 'server/test')
-rw-r--r--server/test/definition/arg.lua8
-rw-r--r--server/test/definition/bug.lua4
-rw-r--r--server/test/definition/function.lua8
-rw-r--r--server/test/definition/init.lua55
-rw-r--r--server/test/definition/local.lua42
-rw-r--r--server/test/definition/method.lua23
-rw-r--r--server/test/definition/set.lua8
-rw-r--r--server/test/definition/table.lua4
8 files changed, 101 insertions, 51 deletions
diff --git a/server/test/definition/arg.lua b/server/test/definition/arg.lua
index 2004d666..83afb04f 100644
--- a/server/test/definition/arg.lua
+++ b/server/test/definition/arg.lua
@@ -1,6 +1,6 @@
TEST [[
local function xx (<!xx!>)
- <?xx?> = 1
+ <?xx?>()
end
]]
@@ -11,13 +11,13 @@ end
]]
TEST [[
-function mt<!:!>x()
- <?self?> = 1
+function <!mt!>:x()
+ <?self?>()
end
]]
TEST [[
function mt:x(<!self!>)
- <?self?> = 1
+ <?self?>()
end
]]
diff --git a/server/test/definition/bug.lua b/server/test/definition/bug.lua
index 4ad2a05a..7019e079 100644
--- a/server/test/definition/bug.lua
+++ b/server/test/definition/bug.lua
@@ -10,12 +10,12 @@ end
TEST [[
function _(<!x!>)
do return end
- <?x?> = 1
+ <?x?>()
end
]]
TEST [[
-function a<!:!>b()
+function <!a!>:b()
a:b()
<?self?>()
end
diff --git a/server/test/definition/function.lua b/server/test/definition/function.lua
index 1ef6a463..5deda51c 100644
--- a/server/test/definition/function.lua
+++ b/server/test/definition/function.lua
@@ -1,18 +1,18 @@
TEST [[
function <!x!> () end
-<?x?> = 1
+<?x?>()
]]
TEST [[
local function <!x!> () end
-<?x?> = 1
+<?x?>()
]]
TEST [[
local x
local function <!x!> ()
- <?x?> = 1
+ <?x?>()
end
]]
@@ -20,5 +20,5 @@ TEST [[
local <!x!>
function x()
end
-<?x?> = 1
+<?x?>()
]]
diff --git a/server/test/definition/init.lua b/server/test/definition/init.lua
index 1de41c57..de503c81 100644
--- a/server/test/definition/init.lua
+++ b/server/test/definition/init.lua
@@ -3,26 +3,52 @@ local parser = require 'parser'
rawset(_G, 'TEST', true)
-function TEST(script)
- local start = script:find('<!', 1, true)
- local finish = script:find('!>', 1, true)
- if start and finish then
- start = start + 2
- finish = finish - 1
+local function catch_target(script)
+ local list = {}
+ local cur = 1
+ while true do
+ local start, finish = script:find('<!.-!>', cur)
+ if not start then
+ break
+ end
+ list[#list+1] = { start + 2, finish - 2 }
+ cur = finish + 1
+ end
+ return list
+end
+
+local function founded(targets, results)
+ while true do
+ local target = table.remove(targets)
+ if not target then
+ break
+ end
+ for i, result in ipairs(results) do
+ if target[1] == result[1] and target[2] == result[2] then
+ table.remove(results, i)
+ goto CONTINUE
+ end
+ end
+ do return false end
+ ::CONTINUE::
+ end
+ if #results == 0 then
+ return true
+ else
+ return false
end
+end
+
+function TEST(script)
+ local target = catch_target(script)
local pos = script:find('<?', 1, true) + 2
local new_script = script:gsub('<[!?]', ' '):gsub('[!?]>', ' ')
local ast, err = parser:ast(new_script)
assert(ast)
- local suc, a, b = matcher.definition(ast, pos)
- if start and finish then
- assert(suc == true)
- assert(a == start)
- assert(b == finish)
- else
- assert(suc == false)
- end
+ local suc, result = matcher.definition(ast, pos)
+ assert(suc)
+ assert(founded(target, result))
end
require 'definition.set'
@@ -30,4 +56,5 @@ require 'definition.local'
require 'definition.arg'
require 'definition.function'
require 'definition.table'
+require 'definition.method'
require 'definition.bug'
diff --git a/server/test/definition/local.lua b/server/test/definition/local.lua
index 0737443d..f4744799 100644
--- a/server/test/definition/local.lua
+++ b/server/test/definition/local.lua
@@ -1,33 +1,33 @@
TEST [[
local <!x!>
-<?x?> = 1
+<?x?>()
]]
TEST [[
local z, y, <!x!>
-<?x?> = 1
+<?x?>()
]]
TEST [[
local <!x!> = 1
-<?x?> = 1
+<?x?>()
]]
TEST [[
local z, y, <!x!> = 1
-<?x?> = 1
+<?x?>()
]]
TEST [[
local x
local <!x!>
-<?x?> = 1
+<?x?>()
]]
TEST [[
local <!x!>
do
- <?x?> = 1
+ <?x?>()
end
]]
@@ -36,7 +36,7 @@ local <!x!>
do
local x
end
-<?x?> = 1
+<?x?>()
]]
TEST [[
@@ -64,13 +64,13 @@ elseif x then
else
local x
end
-<?x?> = 1
+<?x?>()
]]
TEST [[
local <!x!>
if x then
- <?x?> = 1
+ <?x?>()
elseif x then
local x
else
@@ -82,13 +82,13 @@ TEST [[
local <!x!>
for x = 1, 10 do
end
-<?x?> = 1
+<?x?>()
]]
TEST [[
local x
for <!x!> = 1, 10 do
- <?x?> = 1
+ <?x?>()
end
]]
@@ -96,7 +96,7 @@ TEST [[
local <!x!>
for x in x do
end
-<?x?> = 1
+<?x?>()
]]
TEST [[
@@ -108,14 +108,14 @@ end
TEST [[
local x
for <!x!> in x do
- <?x?> = 1
+ <?x?>()
end
]]
TEST [[
local x
for z, y, <!x!> in x do
- <?x?> = 1
+ <?x?>()
end
]]
@@ -128,7 +128,7 @@ end
TEST [[
local <!x!>
while x do
- <?x?> = 1
+ <?x?>()
end
]]
@@ -137,13 +137,13 @@ local <!x!>
while x do
local x
end
-<?x?> = 1
+<?x?>()
]]
TEST [[
local <!x!>
repeat
- <?x?> = 1
+ <?x?>()
until true
]]
@@ -152,7 +152,7 @@ local <!x!>
repeat
local x
until true
-<?x?> = 1
+<?x?>()
]]
TEST [[
@@ -173,19 +173,19 @@ local <!x!>
function _()
local x
end
-<?x?> = 1
+<?x?>()
]]
TEST [[
local <!x!>
return function ()
- <?x?> = 1
+ <?x?>()
end
]]
TEST [[
local <!x!>
local x = function ()
- <?x?> = 1
+ <?x?>()
end
]]
diff --git a/server/test/definition/method.lua b/server/test/definition/method.lua
new file mode 100644
index 00000000..96b77a60
--- /dev/null
+++ b/server/test/definition/method.lua
@@ -0,0 +1,23 @@
+TEST [[
+function mt:<!a!>()
+end
+function mt:b()
+ mt:<?a?>()
+end
+]]
+
+TEST [[
+function mt:<!m1!>()
+end
+function mt:m2()
+ self:<?m1?>()
+end
+]]
+
+TEST [[
+function mt:m3()
+ mt:<?m4?>()
+end
+function mt:<!m4!>()
+end
+]]
diff --git a/server/test/definition/set.lua b/server/test/definition/set.lua
index 2e48e490..294a92ca 100644
--- a/server/test/definition/set.lua
+++ b/server/test/definition/set.lua
@@ -1,13 +1,13 @@
TEST [[
<!x!> = 1
-<?x?> = 1
+<?x?>()
]]
TEST [[
do
<!global!> = 1
end
-<?global?> = 1
+<?global?>()
]]
TEST [[
@@ -15,7 +15,7 @@ TEST [[
do
local x = 1
end
-<?x?> = 1
+<?x?>()
]]
TEST [[
@@ -25,6 +25,6 @@ do
do
x = 2
end
- <?x?> = 1
+ <?x?>()
end
]]
diff --git a/server/test/definition/table.lua b/server/test/definition/table.lua
index 47248508..398abc80 100644
--- a/server/test/definition/table.lua
+++ b/server/test/definition/table.lua
@@ -8,12 +8,12 @@ a = {
TEST [[
local t
t.<!x!> = 1
-t.<?x?> = 1
+t.<?x?>()
]]
TEST [[
t.<!x!> = 1
-t.<?x?> = 1
+t.<?x?>()
]]
TEST [[