summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2023-07-19 15:55:30 +0800
committer最萌小汐 <sumneko@hotmail.com>2023-07-19 15:55:30 +0800
commit0108cc7c485a2885976d33e2da9419b97223e66e (patch)
tree09bba6d187a1d1a0967e6ac201718c7b194b56bd
parent38beb846ea216dbca75174692f142fb215d9f896 (diff)
downloadlua-language-server-0108cc7c485a2885976d33e2da9419b97223e66e.zip
cleanup test codes
-rw-r--r--test.lua6
-rw-r--r--test/code_action/init.lua16
-rw-r--r--test/crossfile/completion.lua14
-rw-r--r--test/crossfile/references.lua4
-rw-r--r--test/plugins/ffi/test.lua2
5 files changed, 25 insertions, 17 deletions
diff --git a/test.lua b/test.lua
index 9e596e88..6b3bc16d 100644
--- a/test.lua
+++ b/test.lua
@@ -82,12 +82,14 @@ local function main()
--log.print = true
- TESTURI = furi.encode('/unittest.lua')
+ TESTROOT = ROOT:string() .. '/test_root/'
+ TESTROOTURI = furi.encode(TESTROOT)
+ TESTURI = furi.encode(TESTROOT .. 'unittest.lua')
---@async
lclient():start(function (client)
client:registerFakers()
- local rootUri = furi.encode '/'
+ local rootUri = furi.encode(TESTROOT)
client:initialize {
rootUri = rootUri,
}
diff --git a/test/code_action/init.lua b/test/code_action/init.lua
index ed145766..264cfacf 100644
--- a/test/code_action/init.lua
+++ b/test/code_action/init.lua
@@ -17,7 +17,7 @@ local function eq(expected, result)
end
local tp1, tp2 = type(expected), type(result)
if tp1 ~= tp2 then
- return false, string.format(": expected type %s, got %s for %s", tp1, tp2)
+ return false, string.format(": expected type %s, got %s", tp1, tp2)
end
if tp1 == 'table' then
local mark = {}
@@ -53,7 +53,7 @@ local function TEST_CROSSFILE(testfiles)
local mainscript = table.remove(testfiles, 1)
return function(expected)
for _, data in ipairs(testfiles) do
- local uri = furi.encode(data.path)
+ local uri = furi.encode(TESTROOT .. data.path)
files.setText(uri, data.content)
files.compileState(uri)
end
@@ -64,7 +64,7 @@ local function TEST_CROSSFILE(testfiles)
local _ <close> = function ()
for _, info in ipairs(testfiles) do
- files.remove(furi.encode(info.path))
+ files.remove(furi.encode(TESTROOT .. info.path))
end
files.remove(TESTURI)
end
@@ -205,7 +205,7 @@ TEST_CROSSFILE {
arguments = {
{
uri = TESTURI,
- target = furi.encode 'unrequiredModule.lua',
+ target = furi.encode(TESTROOT .. 'unrequiredModule.lua'),
name = 'unrequiredModule',
requireName = 'unrequiredModule'
},
@@ -236,7 +236,7 @@ TEST_CROSSFILE {
arguments = {
{
uri = TESTURI,
- target = furi.encode 'myModule/init.lua',
+ target = furi.encode(TESTROOT .. 'myModule/init.lua'),
name = 'myModule',
requireName = 'myModule.init'
},
@@ -252,7 +252,7 @@ TEST_CROSSFILE {
arguments = {
{
uri = TESTURI,
- target = furi.encode 'myModule/init.lua',
+ target = furi.encode(TESTROOT .. 'myModule/init.lua'),
name = 'myModule',
requireName = 'init'
},
@@ -268,11 +268,11 @@ TEST_CROSSFILE {
arguments = {
{
uri = TESTURI,
- target = furi.encode 'myModule/init.lua',
+ target = furi.encode(TESTROOT .. 'myModule/init.lua'),
name = 'myModule',
requireName = 'myModule'
},
},
}
},
-} \ No newline at end of file
+}
diff --git a/test/crossfile/completion.lua b/test/crossfile/completion.lua
index 113b0327..227350cb 100644
--- a/test/crossfile/completion.lua
+++ b/test/crossfile/completion.lua
@@ -61,7 +61,7 @@ function TEST(data)
local mainUri
local pos
for _, info in ipairs(data) do
- local uri = furi.encode(info.path)
+ local uri = furi.encode(TESTROOT .. info.path)
local script = info.content or ''
if info.main then
local newScript, catched = catch(script, '?')
@@ -75,7 +75,7 @@ function TEST(data)
local _ <close> = function ()
for _, info in ipairs(data) do
- files.remove(furi.encode(info.path))
+ files.remove(furi.encode(TESTROOT .. info.path))
end
end
@@ -108,6 +108,12 @@ function TEST(data)
: gsub('\r\n', '\n')
end
end
+ for _, eitem in ipairs(expect) do
+ if eitem['description'] then
+ eitem['description'] = eitem['description']
+ : gsub('%$(.-)%$', _G)
+ end
+ end
assert(result)
assert(eq(expect, result))
end
@@ -936,7 +942,7 @@ TEST {
kind = CompletionItemKind.Variable,
detail = 'function',
description = [[
-从 [myfunc.lua](file:///myfunc.lua) 中导入
+从 [myfunc.lua]($TESTROOTURI$myfunc.lua) 中导入
```lua
function (a: any, b: any)
@@ -967,7 +973,7 @@ TEST {
kind = CompletionItemKind.Variable,
detail = 'function',
description = [[
-从 [dir\myfunc.lua](file:///dir/myfunc.lua) 中导入
+从 [dir\myfunc.lua]($TESTROOTURI$dir/myfunc.lua) 中导入
```lua
function (a: any, b: any)
diff --git a/test/crossfile/references.lua b/test/crossfile/references.lua
index faa9dba9..36c08170 100644
--- a/test/crossfile/references.lua
+++ b/test/crossfile/references.lua
@@ -58,7 +58,7 @@ function TEST(datas)
local sourceList
local sourceUri
for i, data in ipairs(datas) do
- local uri = furi.encode(data.path)
+ local uri = furi.encode(TESTROOT .. data.path)
local newScript, catched = catch(data.content, '!?~')
if catched['!'] or catched['~'] then
for _, position in ipairs(catched['!'] + catched['~']) do
@@ -79,7 +79,7 @@ function TEST(datas)
local _ <close> = function ()
for _, info in ipairs(datas) do
- files.remove(furi.encode(info.path))
+ files.remove(furi.encode(TESTROOT .. info.path))
end
end
diff --git a/test/plugins/ffi/test.lua b/test/plugins/ffi/test.lua
index b46fe962..f07e71c6 100644
--- a/test/plugins/ffi/test.lua
+++ b/test/plugins/ffi/test.lua
@@ -8,7 +8,7 @@ local template = require 'config.template'
template['Lua.runtime.version'].default = 'LuaJIT'
-TESTURI = furi.encode('/unittest.ffi.lua')
+TESTURI = furi.encode(TESTROOT .. 'unittest.ffi.lua')
---@async
local function TestBuilder()