Skip to content

Commit 0108cc7

Browse files
committed
cleanup test codes
1 parent 38beb84 commit 0108cc7

File tree

5 files changed

+25
-17
lines changed

5 files changed

+25
-17
lines changed

test.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,14 @@ local function main()
8282

8383
--log.print = true
8484

85-
TESTURI = furi.encode('/unittest.lua')
85+
TESTROOT = ROOT:string() .. '/test_root/'
86+
TESTROOTURI = furi.encode(TESTROOT)
87+
TESTURI = furi.encode(TESTROOT .. 'unittest.lua')
8688

8789
---@async
8890
lclient():start(function (client)
8991
client:registerFakers()
90-
local rootUri = furi.encode '/'
92+
local rootUri = furi.encode(TESTROOT)
9193
client:initialize {
9294
rootUri = rootUri,
9395
}

test/code_action/init.lua

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ local function eq(expected, result)
1717
end
1818
local tp1, tp2 = type(expected), type(result)
1919
if tp1 ~= tp2 then
20-
return false, string.format(": expected type %s, got %s for %s", tp1, tp2)
20+
return false, string.format(": expected type %s, got %s", tp1, tp2)
2121
end
2222
if tp1 == 'table' then
2323
local mark = {}
@@ -53,7 +53,7 @@ local function TEST_CROSSFILE(testfiles)
5353
local mainscript = table.remove(testfiles, 1)
5454
return function(expected)
5555
for _, data in ipairs(testfiles) do
56-
local uri = furi.encode(data.path)
56+
local uri = furi.encode(TESTROOT .. data.path)
5757
files.setText(uri, data.content)
5858
files.compileState(uri)
5959
end
@@ -64,7 +64,7 @@ local function TEST_CROSSFILE(testfiles)
6464

6565
local _ <close> = function ()
6666
for _, info in ipairs(testfiles) do
67-
files.remove(furi.encode(info.path))
67+
files.remove(furi.encode(TESTROOT .. info.path))
6868
end
6969
files.remove(TESTURI)
7070
end
@@ -205,7 +205,7 @@ TEST_CROSSFILE {
205205
arguments = {
206206
{
207207
uri = TESTURI,
208-
target = furi.encode 'unrequiredModule.lua',
208+
target = furi.encode(TESTROOT .. 'unrequiredModule.lua'),
209209
name = 'unrequiredModule',
210210
requireName = 'unrequiredModule'
211211
},
@@ -236,7 +236,7 @@ TEST_CROSSFILE {
236236
arguments = {
237237
{
238238
uri = TESTURI,
239-
target = furi.encode 'myModule/init.lua',
239+
target = furi.encode(TESTROOT .. 'myModule/init.lua'),
240240
name = 'myModule',
241241
requireName = 'myModule.init'
242242
},
@@ -252,7 +252,7 @@ TEST_CROSSFILE {
252252
arguments = {
253253
{
254254
uri = TESTURI,
255-
target = furi.encode 'myModule/init.lua',
255+
target = furi.encode(TESTROOT .. 'myModule/init.lua'),
256256
name = 'myModule',
257257
requireName = 'init'
258258
},
@@ -268,11 +268,11 @@ TEST_CROSSFILE {
268268
arguments = {
269269
{
270270
uri = TESTURI,
271-
target = furi.encode 'myModule/init.lua',
271+
target = furi.encode(TESTROOT .. 'myModule/init.lua'),
272272
name = 'myModule',
273273
requireName = 'myModule'
274274
},
275275
},
276276
}
277277
},
278-
}
278+
}

test/crossfile/completion.lua

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function TEST(data)
6161
local mainUri
6262
local pos
6363
for _, info in ipairs(data) do
64-
local uri = furi.encode(info.path)
64+
local uri = furi.encode(TESTROOT .. info.path)
6565
local script = info.content or ''
6666
if info.main then
6767
local newScript, catched = catch(script, '?')
@@ -75,7 +75,7 @@ function TEST(data)
7575

7676
local _ <close> = function ()
7777
for _, info in ipairs(data) do
78-
files.remove(furi.encode(info.path))
78+
files.remove(furi.encode(TESTROOT .. info.path))
7979
end
8080
end
8181

@@ -108,6 +108,12 @@ function TEST(data)
108108
: gsub('\r\n', '\n')
109109
end
110110
end
111+
for _, eitem in ipairs(expect) do
112+
if eitem['description'] then
113+
eitem['description'] = eitem['description']
114+
: gsub('%$(.-)%$', _G)
115+
end
116+
end
111117
assert(result)
112118
assert(eq(expect, result))
113119
end
@@ -936,7 +942,7 @@ TEST {
936942
kind = CompletionItemKind.Variable,
937943
detail = 'function',
938944
description = [[
939-
从 [myfunc.lua](file:///myfunc.lua) 中导入
945+
从 [myfunc.lua]($TESTROOTURI$myfunc.lua) 中导入
940946
941947
```lua
942948
function (a: any, b: any)
@@ -967,7 +973,7 @@ TEST {
967973
kind = CompletionItemKind.Variable,
968974
detail = 'function',
969975
description = [[
970-
从 [dir\myfunc.lua](file:///dir/myfunc.lua) 中导入
976+
从 [dir\myfunc.lua]($TESTROOTURI$dir/myfunc.lua) 中导入
971977
972978
```lua
973979
function (a: any, b: any)

test/crossfile/references.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function TEST(datas)
5858
local sourceList
5959
local sourceUri
6060
for i, data in ipairs(datas) do
61-
local uri = furi.encode(data.path)
61+
local uri = furi.encode(TESTROOT .. data.path)
6262
local newScript, catched = catch(data.content, '!?~')
6363
if catched['!'] or catched['~'] then
6464
for _, position in ipairs(catched['!'] + catched['~']) do
@@ -79,7 +79,7 @@ function TEST(datas)
7979

8080
local _ <close> = function ()
8181
for _, info in ipairs(datas) do
82-
files.remove(furi.encode(info.path))
82+
files.remove(furi.encode(TESTROOT .. info.path))
8383
end
8484
end
8585

test/plugins/ffi/test.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ local template = require 'config.template'
88

99
template['Lua.runtime.version'].default = 'LuaJIT'
1010

11-
TESTURI = furi.encode('/unittest.ffi.lua')
11+
TESTURI = furi.encode(TESTROOT .. 'unittest.ffi.lua')
1212

1313
---@async
1414
local function TestBuilder()

0 commit comments

Comments
 (0)