summaryrefslogtreecommitdiff
path: root/test/references
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-05-31 19:54:19 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-05-31 19:54:19 +0800
commitfea027821633ef07c5f702a9fe7eb65952f5a4b2 (patch)
tree4f25ba25a34e4efe1784189ff6465c9a9b8aa9da /test/references
parentfaa16704fb8ce52dbc67a92834bf4bba9cc989e1 (diff)
downloadlua-language-server-fea027821633ef07c5f702a9fe7eb65952f5a4b2.zip
update
Diffstat (limited to 'test/references')
-rw-r--r--test/references/all.lua78
-rw-r--r--test/references/init.lua25
2 files changed, 78 insertions, 25 deletions
diff --git a/test/references/all.lua b/test/references/all.lua
new file mode 100644
index 00000000..c27beb3c
--- /dev/null
+++ b/test/references/all.lua
@@ -0,0 +1,78 @@
+local core = require 'core.reference'
+local files = require 'files'
+
+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)
+ if #targets ~= #results then
+ return false
+ end
+ for _, target in ipairs(targets) do
+ for _, result in ipairs(results) do
+ if target[1] == result[1] and target[2] == result[2] then
+ goto NEXT
+ end
+ end
+ do return false end
+ ::NEXT::
+ end
+ return true
+end
+
+function TEST(script)
+ files.removeAll()
+ local expect = catch_target(script)
+ local start = script:find('<[?~]')
+ local finish = script:find('[?~]>')
+ local pos = (start + finish) // 2 + 1
+ local new_script = script:gsub('<[!?~]', ' '):gsub('[!?~]>', ' ')
+ files.setText('', new_script)
+
+ local results = core('', pos)
+ if results then
+ local positions = {}
+ for i, result in ipairs(results) do
+ positions[i] = { result.target.start, result.target.finish }
+ end
+ assert(founded(expect, positions))
+ else
+ assert(#expect == 0)
+ end
+end
+
+TEST [[
+---@class A
+local a = {}
+a.<?x?> = 1
+
+---@return A
+local function f() end
+
+local b = f()
+return b.<!x!>
+]]
+
+TEST [[
+---@class A
+local a = {}
+a.<?x?> = 1
+
+---@return table
+---@return A
+local function f() end
+
+local a, b = f()
+return a.x, b.<!x!>
+]]
diff --git a/test/references/init.lua b/test/references/init.lua
index cb026cbc..e6abc3bd 100644
--- a/test/references/init.lua
+++ b/test/references/init.lua
@@ -334,31 +334,6 @@ function mt2:doSomething()
end
]]
-TEST [[
----@class A
-local a = {}
-a.<?x?> = 1
-
----@return A
-local function f() end
-
-local b = f()
-return b.<!x!>
-]]
-
-TEST [[
----@class A
-local a = {}
-a.<?x?> = 1
-
----@return table
----@return A
-local function f() end
-
-local a, b = f()
-return a.x, b.<!x!>
-]]
-
-- TODO 支持泛型
do return end
TEST [[