summaryrefslogtreecommitdiff
path: root/test/crossfile
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-09-24 15:08:02 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-09-24 15:08:02 +0800
commit4b085b8aea5f33ec114baa31d2b9d72341383c32 (patch)
treefe35a326408e762711a31d3e803464f0c1a8468d /test/crossfile
parent0c8c6bbf23082d0b858646846a47a3001f718ae2 (diff)
parent35ce57976db3b4c42193279dd55972ea013fecad (diff)
downloadlua-language-server-4b085b8aea5f33ec114baa31d2b9d72341383c32.zip
Merge branch 'newparser'
Diffstat (limited to 'test/crossfile')
-rw-r--r--test/crossfile/allreferences.lua17
-rw-r--r--test/crossfile/completion.lua58
-rw-r--r--test/crossfile/definition.lua79
-rw-r--r--test/crossfile/diagnostic.lua27
-rw-r--r--test/crossfile/hover.lua22
-rw-r--r--test/crossfile/references.lua66
6 files changed, 85 insertions, 184 deletions
diff --git a/test/crossfile/allreferences.lua b/test/crossfile/allreferences.lua
index 056fa416..bddc159d 100644
--- a/test/crossfile/allreferences.lua
+++ b/test/crossfile/allreferences.lua
@@ -9,10 +9,9 @@ TEST {
{
path = 'lib.lua',
content = [[
- return <~function~> ()
- end
+ return <!<?function?> ()
+ end!>
]],
- target = {22, 50},
},
}
@@ -21,7 +20,7 @@ TEST {
path = 'a.lua',
content = [[
local m = {}
- function m.<?func?>()
+ function m.<~func~>()
end
return m
]],
@@ -39,7 +38,7 @@ TEST {
{
path = 'a.lua',
content = [[
- return <?function () end?>
+ return <~function () end~>
]],
},
{
@@ -72,7 +71,7 @@ TEST {
{
path = 'a.lua',
content = [[
- local function <?f?>()
+ local function <~f~>()
end
return {
@@ -126,7 +125,7 @@ TEST {
local t = require 'a'
local <!f!> = t.<!f!>
- <?f?>()
+ <~f~>()
return {
<!f!> = <!f!>,
@@ -139,7 +138,7 @@ TEST {
{
path = 'a.lua',
content = [[
- local function <?f?>()
+ local function <~f~>()
end
return {
@@ -202,7 +201,7 @@ TEST {
{
path = 'a.lua',
content = [[
- local <?t?> = require 'b'
+ local <~t~> = require 'b'
return <!t!>
]]
},
diff --git a/test/crossfile/completion.lua b/test/crossfile/completion.lua
index d26398ca..9c5ed96e 100644
--- a/test/crossfile/completion.lua
+++ b/test/crossfile/completion.lua
@@ -4,6 +4,7 @@ local furi = require 'file-uri'
local platform = require 'bee.platform'
local util = require 'utility'
local config = require 'config'
+local catch = require 'catch'
rawset(_G, 'TEST', true)
@@ -88,8 +89,9 @@ function TEST(data)
local uri = furi.encode(info.path)
local script = info.content
if info.main then
- pos = script:find('$', 1, true) - 1
- script = script:gsub('%$', '')
+ local newScript, catched = catch(script, '?')
+ pos = catched['?'][1][1]
+ script = newScript
mainUri = uri
end
files.setText(uri, script)
@@ -139,7 +141,7 @@ TEST {
},
{
path = 'test.lua',
- content = 'require "a$"',
+ content = 'require "a<??>"',
main = true,
},
completion = {
@@ -178,7 +180,7 @@ TEST {
},
{
path = 'test.lua',
- content = 'require "A$"',
+ content = 'require "A<??>"',
main = true,
},
completion = {
@@ -201,7 +203,7 @@ TEST {
},
{
path = 'test.lua',
- content = 'require "a$"',
+ content = 'require "a<??>"',
main = true,
},
completion = {
@@ -229,7 +231,7 @@ TEST {
},
{
path = 'test.lua',
- content = 'require "abc$"',
+ content = 'require "abc<??>"',
main = true,
},
completion = {
@@ -257,7 +259,7 @@ TEST {
},
{
path = 'test.lua',
- content = 'require "abc$"',
+ content = 'require "abc<??>"',
main = true,
},
completion = {
@@ -290,7 +292,7 @@ TEST {
},
{
path = 'test.lua',
- content = 'require "abc.i$"',
+ content = 'require "abc.i<??>"',
main = true,
},
completion = {
@@ -315,7 +317,7 @@ TEST {
},
{
path = 'test.lua',
- content = 'require "abc/i$"',
+ content = 'require "abc/i<??>"',
main = true,
},
completion = {
@@ -339,7 +341,7 @@ TEST {
},
{
path = 'test.lua',
- content = 'require "core.co$"',
+ content = 'require "core.co<??>"',
main = true,
},
completion = {
@@ -362,7 +364,7 @@ TEST {
},
{
path = 'abc/test.lua',
- content = 'require "x$"',
+ content = 'require "x<??>"',
main = true,
},
completion = {
@@ -397,7 +399,7 @@ TEST {
},
{
path = 'main.lua',
- content = 'require "x$"',
+ content = 'require "x<??>"',
main = true,
},
completion = {
@@ -428,7 +430,7 @@ TEST {
},
{
path = 'main.lua',
- content = 'require "x$"',
+ content = 'require "x<??>"',
main = true,
},
completion = {
@@ -457,7 +459,7 @@ TEST {
path = 'b.lua',
content = [[
local t = require 'a'
- t.$
+ t.<??>
]],
main = true,
},
@@ -499,7 +501,7 @@ TEST {
{
path = 'b.lua',
content = [[
- zab$
+ zab<??>
]],
main = true,
},
@@ -533,7 +535,7 @@ TEST {
{
path = 'b.lua',
content = [[
- zab$
+ zab<??>
]],
main = true,
},
@@ -557,7 +559,7 @@ TEST {
path = 'a.lua',
content = [[
local japi = require 'jass.japi'
- japi.xxxaaaax$
+ japi.xxxaaaax<??>
]],
main = true,
},
@@ -571,7 +573,7 @@ TEST {
{
path = 'xxxx.lua',
content = [[
- require 'xx$'
+ require 'xx<??>'
]],
main = true,
},
@@ -592,7 +594,7 @@ TEST {
{
path = 'main.lua',
content = [[
- require 'xx$'
+ require 'xx<??>'
]],
main = true,
},
@@ -613,7 +615,7 @@ TEST {
{
path = 'main.lua',
content = [[
- require [=[xx$]=]'
+ require [=[xx<??>]=]'
]],
main = true,
},
@@ -635,7 +637,7 @@ TEST {
{
path = 'main.lua',
content = [[
- dofile 'ab$'
+ dofile 'ab<??>'
]],
main = true,
},
@@ -656,7 +658,7 @@ TEST {
{
path = 'main.lua',
content = [[
- dofile 'ab$'
+ dofile 'ab<??>'
]],
main = true,
},
@@ -686,7 +688,7 @@ TEST {
content = [[
local t = require 'a'
local v = setmetatable({}, {__index = t})
- v.$
+ v.<??>
]]
},
completion = {
@@ -712,7 +714,7 @@ TEST {
content = [[
local z = require 'a'
- z$
+ z<??>
]],
main = true,
},
@@ -743,7 +745,7 @@ TEST {
path = 'main.lua',
main = true,
content = [[
- myfun$
+ myfun<??>
]],
},
completion = {
@@ -774,7 +776,7 @@ TEST {
path = 'main.lua',
main = true,
content = [[
- myfun$
+ myfun<??>
]],
},
completion = {
@@ -807,7 +809,7 @@ TEST {
path = 'main.lua',
main = true,
content = [[
- A.$
+ A.<??>
]],
},
completion = EXISTS,
@@ -819,7 +821,7 @@ TEST {
path = 'main.lua',
main = true,
content = [[
- require'$
+ require'<??>
]]
},
completion = EXISTS
diff --git a/test/crossfile/definition.lua b/test/crossfile/definition.lua
index 66e9b269..01bf0202 100644
--- a/test/crossfile/definition.lua
+++ b/test/crossfile/definition.lua
@@ -3,26 +3,10 @@ local furi = require 'file-uri'
local core = require 'core.definition'
local config = require 'config'
local platform = require 'bee.platform'
+local catch = require 'catch'
rawset(_G, 'TEST', true)
-local function catch_target(script, sep)
- local list = {}
- local cur = 1
- local cut = 0
- while true do
- local start, finish = script:find(('<%%%s.-%%%s>'):format(sep, sep), cur)
- if not start then
- break
- end
- list[#list+1] = { start - cut, finish - 4 - cut }
- cur = finish + 1
- cut = cut + 4
- end
- local new_script = script:gsub(('<%%%s(.-)%%%s>'):format(sep, sep), '%1')
- return new_script, list
-end
-
local function founded(targets, results)
if #targets ~= #results then
return false
@@ -50,32 +34,26 @@ function TEST(datas)
local sourceUri
for i, data in ipairs(datas) do
local uri = furi.encode(data.path)
- local new, list = catch_target(data.content, '!')
- if new ~= data.content or data.target then
- if data.target then
- targetList[#targetList+1] = {
- data.target[1],
- data.target[2],
- uri,
- }
- else
- for _, position in ipairs(list) do
- targetList[#targetList+1] = {
- position[1],
- position[2],
- uri,
- }
- end
- end
- data.content = new
+ local newScript, catched = catch(data.content, '!?~')
+ for _, position in ipairs(catched['!'] or {}) do
+ targetList[#targetList+1] = {
+ position[1],
+ position[2],
+ uri,
+ }
+ end
+ for _, position in ipairs(catched['~'] or {}) do
+ targetList[#targetList+1] = {
+ position[1],
+ position[2],
+ uri,
+ }
end
- new, list = catch_target(data.content, '?')
- if new ~= data.content then
- sourceList = list
+ if catched['?'] or catched['~'] then
+ sourceList = catched['?'] or catched['~']
sourceUri = uri
- data.content = new
end
- files.setText(uri, data.content)
+ files.setText(uri, newScript)
end
local sourcePos = (sourceList[1][1] + sourceList[1][2]) // 2
@@ -98,8 +76,7 @@ end
TEST {
{
path = 'a.lua',
- content = '',
- target = {0, 0},
+ content = '<!!>',
},
{
path = 'b.lua',
@@ -110,8 +87,7 @@ TEST {
TEST {
{
path = 'aaa/bbb.lua',
- content = '',
- target = {0, 0},
+ content = '<!!>',
},
{
path = 'b.lua',
@@ -122,8 +98,7 @@ TEST {
TEST {
{
path = '@bbb.lua',
- content = '',
- target = {0, 0},
+ content = '<!!>',
},
{
path = 'b.lua',
@@ -134,8 +109,7 @@ TEST {
TEST {
{
path = 'aaa/bbb.lua',
- content = '',
- target = {0, 0},
+ content = '<!!>',
},
{
path = 'b.lua',
@@ -150,8 +124,7 @@ TEST {
},
{
path = 'b.lua',
- content = 'local <?t?> = require "a"',
- target = {7, 7},
+ content = 'local <~t~> = require "a"',
},
}
@@ -176,8 +149,7 @@ TEST {
},
{
path = 'b.lua',
- content = 'local <?t?> = require "a"',
- target = {7, 7},
+ content = 'local <~t~> = require "a"',
},
}
@@ -245,9 +217,8 @@ TEST {
{
path = 'b.lua',
content = [[
- local <?t?> = require 'a'
+ local <~t~> = require 'a'
]],
- target = {19, 19},
},
}
diff --git a/test/crossfile/diagnostic.lua b/test/crossfile/diagnostic.lua
index a430cb4e..adc2961f 100644
--- a/test/crossfile/diagnostic.lua
+++ b/test/crossfile/diagnostic.lua
@@ -3,28 +3,12 @@ local furi = require 'file-uri'
local core = require 'core.diagnostics'
local config = require 'config'
local platform = require 'bee.platform'
+local catch = require 'catch'
config.get 'Lua.diagnostics.neededFileStatus'['deprecated'] = 'Any'
rawset(_G, 'TEST', true)
-local function catch_target(script, sep)
- local list = {}
- local cur = 1
- local cut = 0
- while true do
- local start, finish = script:find(('<%%%s.-%%%s>'):format(sep, sep), cur)
- if not start then
- break
- end
- list[#list+1] = { start - cut, finish - 4 - cut }
- cur = finish + 1
- cut = cut + 4
- end
- local new_script = script:gsub(('<%%%s(.-)%%%s>'):format(sep, sep), '%1')
- return new_script, list
-end
-
local function founded(targets, results)
if #targets ~= #results then
return false
@@ -48,19 +32,18 @@ function TEST(datas)
files.removeAll()
local targetList = {}
- local sourceUri
for _, data in ipairs(datas) do
local uri = furi.encode(data.path)
- local new, list = catch_target(data.content, '!')
- for _, position in ipairs(list) do
+ local newScript, catched = catch(data.content, '!')
+ for _, position in ipairs(catched['!'] or {}) do
targetList[#targetList+1] = {
position[1],
position[2],
uri,
}
end
- data.content = new
- files.setText(uri, new)
+ data.content = newScript
+ files.setText(uri, newScript)
end
local result = {}
diff --git a/test/crossfile/hover.lua b/test/crossfile/hover.lua
index a877d226..1c46214c 100644
--- a/test/crossfile/hover.lua
+++ b/test/crossfile/hover.lua
@@ -2,6 +2,7 @@ local files = require 'files'
local furi = require 'file-uri'
local core = require 'core.hover'
local config = require 'config'
+local catch = require 'catch'
rawset(_G, 'TEST', true)
@@ -36,36 +37,19 @@ local function eq(a, b)
return a == b
end
-local function catch_target(script, sep)
- local list = {}
- local cur = 1
- local cut = 0
- while true do
- local start, finish = script:find(('<%%%s.-%%%s>'):format(sep, sep), cur)
- if not start then
- break
- end
- list[#list+1] = { start - cut, finish - 4 - cut }
- cur = finish + 1
- cut = cut + 4
- end
- local new_script = script:gsub(('<%%%s(.-)%%%s>'):format(sep, sep), '%1')
- return new_script, list
-end
-
function TEST(expect)
files.removeAll()
local targetScript = expect[1].content
local targetUri = furi.encode(expect[1].path)
- local sourceScript, sourceList = catch_target(expect[2].content, '?')
+ local sourceScript, sourceList = catch(expect[2].content, '?')
local sourceUri = furi.encode(expect[2].path)
files.setText(targetUri, targetScript)
files.setText(sourceUri, sourceScript)
- local sourcePos = (sourceList[1][1] + sourceList[1][2]) // 2
+ local sourcePos = (sourceList['?'][1][1] + sourceList['?'][1][2]) // 2
local hover = core.byUri(sourceUri, sourcePos)
assert(hover)
hover = tostring(hover):gsub('\r\n', '\n')
diff --git a/test/crossfile/references.lua b/test/crossfile/references.lua
index 6c28b34b..145792b5 100644
--- a/test/crossfile/references.lua
+++ b/test/crossfile/references.lua
@@ -1,6 +1,7 @@
local files = require 'files'
local furi = require 'file-uri'
local core = require 'core.reference'
+local catch = require 'catch'
rawset(_G, 'TEST', true)
@@ -32,21 +33,6 @@ local function eq(a, b)
return a == b
end
-local function catch_target(script, sep)
- local list = {}
- local cur = 1
- while true do
- local start, finish = script:find(('<%%%s.-%%%s>'):format(sep, sep), cur)
- if not start then
- break
- end
- list[#list+1] = { start + 2, finish - 2 }
- cur = finish + 1
- end
- local new_script = script:gsub(('<%%%s(.-)%%%s>'):format(sep, sep), ' %1 ')
- return new_script, list
-end
-
local function founded(targets, results)
if #targets ~= #results then
return false
@@ -74,37 +60,9 @@ function TEST(datas)
local sourceUri
for i, data in ipairs(datas) do
local uri = furi.encode(data.path)
- local new, list = catch_target(data.content, '!')
- if new ~= data.content or data.target then
- if data.target then
- targetList[#targetList+1] = {
- data.target[1],
- data.target[2],
- uri,
- }
- else
- for _, position in ipairs(list) do
- targetList[#targetList+1] = {
- position[1],
- position[2],
- uri,
- }
- end
- end
- data.content = new
- end
- new, list = catch_target(data.content, '~')
- if new ~= data.content then
- sourceList = list
- sourceUri = uri
- data.content = new
- end
- new, list = catch_target(data.content, '?')
- if new ~= data.content then
- sourceList = list
- sourceUri = uri
- data.content = new
- for _, position in ipairs(list) do
+ local newScript, catched = catch(data.content, '!?~')
+ if catched['!'] or catched['~'] then
+ for _, position in ipairs(catched['!'] + catched['~']) do
targetList[#targetList+1] = {
position[1],
position[2],
@@ -112,7 +70,11 @@ function TEST(datas)
}
end
end
- files.setText(uri, data.content)
+ if catched['?'] or catched['~'] then
+ sourceList = catched['?'] + catched['~']
+ sourceUri = uri
+ end
+ files.setText(uri, newScript)
end
local sourcePos = (sourceList[1][1] + sourceList[1][2]) // 2
@@ -143,7 +105,7 @@ TEST {
{
path = 'a.lua',
content = [[
- local <?f?> = require 'lib'
+ local <~f~> = require 'lib'
]],
},
}
@@ -158,7 +120,7 @@ TEST {
{
path = 'b.lua',
content = [[
- print(<?ROOT?>)
+ print(<~ROOT~>)
]],
},
}
@@ -167,7 +129,7 @@ TEST {
{
path = 'a.lua',
content = [[
- <?ROOT?> = 1
+ <~ROOT~> = 1
]],
},
{
@@ -183,7 +145,7 @@ TEST {
path = 'a.lua',
content = [[
local f = require 'lib'
- local <?o?> = f()
+ local <~o~> = f()
]],
},
{
@@ -212,7 +174,7 @@ TEST {
---@class A
local mt
- function mt.<?f?>()
+ function mt.<~f~>()
end
]]
}