summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorjefersonf <jeferson.silva>2021-10-30 13:19:12 -0300
committerjefersonf <jeferson.silva>2021-10-30 13:19:12 -0300
commitf0c5bbeb62794116b6517be51efa6054254076eb (patch)
treefee585182a7ec10e987e758a53edcbd7db9dca9b /test
parentf41a33de696dc5ff802d2f5e540da1c87861dac9 (diff)
parent107b57cc7728824a0e9515727f9a6123c5f7c902 (diff)
downloadlua-language-server-f0c5bbeb62794116b6517be51efa6054254076eb.zip
Merge branch 'master' of https://github.com/sumneko/lua-language-server into pt-br-locale-support
Diffstat (limited to 'test')
-rw-r--r--test/completion/init.lua8
-rw-r--r--test/crossfile/completion.lua116
-rw-r--r--test/crossfile/definition.lua25
-rw-r--r--test/crossfile/hover.lua35
-rw-r--r--test/diagnostics/init.lua37
-rw-r--r--test/hover/init.lua9
6 files changed, 222 insertions, 8 deletions
diff --git a/test/completion/init.lua b/test/completion/init.lua
index 051c288c..58885149 100644
--- a/test/completion/init.lua
+++ b/test/completion/init.lua
@@ -83,9 +83,11 @@ function TEST(script)
assert(result ~= nil)
result.enableCommon = nil
for _, item in ipairs(result) do
- local r = core.resolve(item.id)
- for k, v in pairs(r or {}) do
- item[k] = v
+ if item.id then
+ local r = core.resolve(item.id)
+ for k, v in pairs(r or {}) do
+ item[k] = v
+ end
end
for k in pairs(item) do
if not Cared[k] then
diff --git a/test/crossfile/completion.lua b/test/crossfile/completion.lua
index 455f0600..27acb15d 100644
--- a/test/crossfile/completion.lua
+++ b/test/crossfile/completion.lua
@@ -87,7 +87,7 @@ function TEST(data)
local pos
for _, info in ipairs(data) do
local uri = furi.encode(info.path)
- local script = info.content
+ local script = info.content or ''
if info.main then
local newScript, catched = catch(script, '?')
pos = catched['?'][1][1]
@@ -108,9 +108,11 @@ function TEST(data)
result.enableCommon = nil
removeMetas(result)
for _, item in ipairs(result) do
- local r = core.resolve(item.id)
- for k, v in pairs(r or {}) do
- item[k] = v
+ if item.id then
+ local r = core.resolve(item.id)
+ for k, v in pairs(r or {}) do
+ item[k] = v
+ end
end
for k in pairs(item) do
if not Cared[k] then
@@ -563,8 +565,114 @@ TEST {
]],
main = true,
},
+ completion = nil,
+}
+
+TEST {
+ { path = 'f/a.lua' },
+ { path = 'f/b.lua' },
+ {
+ path = 'c.lua',
+ content = [[
+ require '<??>'
+ ]],
+ main = true,
+ },
+ completion = {
+ {
+ label = 'a',
+ kind = CompletionItemKind.Reference,
+ textEdit = EXISTS,
+ },
+ {
+ label = 'b',
+ kind = CompletionItemKind.Reference,
+ textEdit = EXISTS,
+ },
+ {
+ label = 'f.a',
+ kind = CompletionItemKind.Reference,
+ textEdit = EXISTS,
+ },
+ {
+ label = 'f.b',
+ kind = CompletionItemKind.Reference,
+ textEdit = EXISTS,
+ },
+ }
+}
+
+TEST {
+ { path = 'f/a.lua' },
+ { path = 'f/b.lua' },
+ {
+ path = 'c.lua',
+ content = [[
+ require 'a<??>'
+ ]],
+ main = true,
+ },
+ completion = {
+ {
+ label = 'a',
+ kind = CompletionItemKind.Reference,
+ textEdit = EXISTS,
+ },
+ {
+ label = 'f.a',
+ kind = CompletionItemKind.Reference,
+ textEdit = EXISTS,
+ },
+ }
+}
+
+config.set('Lua.runtime.pathStrict', true)
+
+TEST {
+ { path = 'f/a.lua' },
+ { path = 'f/b.lua' },
+ {
+ path = 'c.lua',
+ content = [[
+ require '<??>'
+ ]],
+ main = true,
+ },
+ completion = {
+ {
+ label = 'f.a',
+ kind = CompletionItemKind.Reference,
+ textEdit = EXISTS,
+ },
+ {
+ label = 'f.b',
+ kind = CompletionItemKind.Reference,
+ textEdit = EXISTS,
+ },
+ }
+}
+
+TEST {
+ { path = 'f/a.lua' },
+ { path = 'f/b.lua' },
+ {
+ path = 'c.lua',
+ content = [[
+ require 'a<??>'
+ ]],
+ main = true,
+ },
+ completion = {
+ {
+ label = 'f.a',
+ kind = CompletionItemKind.Reference,
+ textEdit = EXISTS,
+ },
+ }
}
+config.set('Lua.runtime.pathStrict', false)
+
TEST {
{
path = 'xxx.lua',
diff --git a/test/crossfile/definition.lua b/test/crossfile/definition.lua
index 37c10db6..862d95e8 100644
--- a/test/crossfile/definition.lua
+++ b/test/crossfile/definition.lua
@@ -117,6 +117,31 @@ TEST {
},
}
+config.set('Lua.runtime.pathStrict', true)
+TEST {
+ {
+ path = 'aaa/bbb.lua',
+ content = '',
+ },
+ {
+ path = 'b.lua',
+ content = 'require "<?bbb?>"',
+ },
+}
+
+TEST {
+ {
+ path = 'aaa/bbb.lua',
+ content = '<!!>',
+ },
+ {
+ path = 'b.lua',
+ content = 'require "<?aaa.bbb?>"',
+ },
+}
+
+config.set('Lua.runtime.pathStrict', false)
+
TEST {
{
path = 'a.lua',
diff --git a/test/crossfile/hover.lua b/test/crossfile/hover.lua
index b1c4c804..35528446 100644
--- a/test/crossfile/hover.lua
+++ b/test/crossfile/hover.lua
@@ -40,7 +40,7 @@ end
function TEST(expect)
files.removeAll()
- local targetScript = expect[1].content
+ local targetScript, targetList = catch(expect[1].content, '?')
local targetUri = furi.encode(expect[1].path)
local sourceScript, sourceList = catch(expect[2].content, '?')
@@ -49,6 +49,10 @@ function TEST(expect)
files.setText(targetUri, targetScript)
files.setText(sourceUri, sourceScript)
+ if targetList['?'] then
+ local targetPos = (targetList['?'][1][1] + targetList['?'][1][2]) // 2
+ core.byUri(targetUri, targetPos)
+ end
local sourcePos = (sourceList['?'][1][1] + sourceList['?'][1][2]) // 2
local hover = core.byUri(sourceUri, sourcePos)
assert(hover)
@@ -1018,3 +1022,32 @@ function fn()
line1
line2]]}
+
+TEST {
+ {
+ path = 'a.lua',
+ content = [[
+---@type string[]
+local ss
+
+for _, s in ipairs(ss) do
+ print(<?s?>)
+end
+]],
+ },
+ {
+ path = 'b.lua',
+ content = [[
+
+
+
+for _, x in ipairs({} and {}) do
+ print(<?x?>) -- `x` is infered as `string`
+end
+]],
+ },
+ hover = [[
+```lua
+local x: any
+```]]
+}
diff --git a/test/diagnostics/init.lua b/test/diagnostics/init.lua
index c526560a..ab55cd92 100644
--- a/test/diagnostics/init.lua
+++ b/test/diagnostics/init.lua
@@ -1311,6 +1311,43 @@ end
local val = {}
location('uri', val)
]]
+
+-- redundant-return
+TEST [[
+local function f()
+ <!return!>
+end
+f()
+]]
+
+TEST [[
+local function f()
+ return nil
+end
+f()
+]]
+
+TEST [[
+local function f()
+ local function x()
+ <!return!>
+ end
+ x()
+ return true
+end
+f()
+]]
+
+TEST [[
+local function f()
+ local function x()
+ return true
+ end
+ return x()
+end
+f()
+]]
+
---TODO(arthur)
do return end
diff --git a/test/hover/init.lua b/test/hover/init.lua
index 0a05e1cc..36fbd6d2 100644
--- a/test/hover/init.lua
+++ b/test/hover/init.lua
@@ -1714,3 +1714,12 @@ local t: A<string, number> {
y: number,
}
]]
+
+TEST [[
+---@return nil
+local function <?f?>() end
+]]
+[[
+function f()
+ -> nil
+]]