summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/completion/init.lua24
-rw-r--r--test/crossfile/definition.lua25
-rw-r--r--test/definition/bug.lua23
-rw-r--r--test/definition/luadoc.lua84
-rw-r--r--test/diagnostics/init.lua37
-rw-r--r--test/full/example.lua3
-rw-r--r--test/full/init.lua1
-rw-r--r--test/full/self.lua29
-rw-r--r--test/signature/init.lua16
-rw-r--r--test/???.md94
10 files changed, 222 insertions, 114 deletions
diff --git a/test/completion/init.lua b/test/completion/init.lua
index 662df84e..69ca83c3 100644
--- a/test/completion/init.lua
+++ b/test/completion/init.lua
@@ -1071,10 +1071,10 @@ function$
{
label = 'function ()',
kind = define.CompletionItemKind.Snippet,
- insertText = [[
-function $1($2)
- $0
-end]],
+ insertText = "\z
+function $1($2)\
+\t$0\
+end",
},
}
@@ -1089,10 +1089,10 @@ local t = function$
{
label = 'function ()',
kind = define.CompletionItemKind.Snippet,
- insertText = [[
-function ($1)
- $0
-end]],
+ insertText = "\z
+function ($1)\
+\t$0\
+end",
},
}
Cared['insertText'] = false
@@ -1964,10 +1964,10 @@ f($)
{
label = 'fun(x: number, y: number):string',
kind = define.CompletionItemKind.Function,
- insertText = [[
-function (${1:x}, ${2:y})
- $0
-end]],
+ insertText = "\z
+function (${1:x}, ${2:y})\
+\t$0\
+end",
},
}
Cared['insertText'] = nil
diff --git a/test/crossfile/definition.lua b/test/crossfile/definition.lua
index 839a3e89..30d796c8 100644
--- a/test/crossfile/definition.lua
+++ b/test/crossfile/definition.lua
@@ -615,3 +615,28 @@ TEST {
]]
},
}
+
+TEST {
+ {
+ path = 'a.lua',
+ content = [[
+ local lib = {}
+
+ function lib:fn1()
+ return self
+ end
+
+ function lib:<!fn2!>()
+ end
+
+ return lib:fn1()
+ ]]
+ },
+ {
+ path = 'b.lua',
+ content = [[
+ local app = require 'a'
+ print(app.<?fn2?>)
+ ]]
+ },
+}
diff --git a/test/definition/bug.lua b/test/definition/bug.lua
index e7158848..8c446123 100644
--- a/test/definition/bug.lua
+++ b/test/definition/bug.lua
@@ -146,3 +146,26 @@ t.<!f1!> = t.f2
print(t.<?f2?>)
]]
+
+TEST [[
+---@type string
+string.xx = ''
+string.xx:<?format?>()
+]]
+
+TEST [[
+---@class Foo
+Foo = {}
+function Foo:Constructor()
+ self.<!bar1!> = 1
+end
+
+---@class Foo2: Foo
+Foo2 = {}
+function Foo2:Constructor()
+end
+
+---@type Foo2
+local v
+v.<?bar1?>
+]]
diff --git a/test/definition/luadoc.lua b/test/definition/luadoc.lua
index 31134135..1f3dae00 100644
--- a/test/definition/luadoc.lua
+++ b/test/definition/luadoc.lua
@@ -169,3 +169,87 @@ end
AAAA.a.<?SSDF?>
]]
+
+TEST [[
+---@class Cat
+local <!m!> ---hahaha
+---@class Dog
+local m2
+---@type Cat
+local <?<!v!>?>
+]]
+
+TEST [[
+---@class Cat
+local <!m!> --hahaha
+---@class Dog
+local m2
+---@type Cat
+local <?<!v!>?>
+]]
+
+TEST [[
+---@class Cat
+ local <!m!> ---hahaha
+
+ ---@class Dog
+ local m2
+ ---@type Cat
+ local <?<!v!>?>
+]]
+
+TEST [[
+---@class Foo
+local Foo = {}
+function Foo:<!bar1!>() end
+
+---@generic T
+---@param arg1 T
+---@return T
+function Generic(arg1) print(arg1) end
+
+local v1 = Generic(Foo)
+print(v1.<?bar1?>)
+]]
+
+TEST [[
+---@class Foo
+local Foo = {}
+function Foo:bar1() end
+
+---@generic T
+---@param arg1 T
+---@return T
+function Generic(arg1) print(arg1) end
+
+local v1 = Generic("Foo")
+print(v1.<?bar1?>)
+]]
+
+TEST [[
+---@class Foo
+local Foo = {}
+function Foo:bar1() end
+
+---@generic T
+---@param arg1 `T`
+---@return T
+function Generic(arg1) print(arg1) end
+
+local v1 = Generic(Foo)
+print(v1.<?bar1?>)
+]]
+
+TEST [[
+---@class Foo
+local Foo = {}
+function Foo:<!bar1!>() end
+
+---@generic T
+---@param arg1 `T`
+---@return T
+function Generic(arg1) print(arg1) end
+
+local v1 = Generic("Foo")
+print(v1.<?bar1?>)
+]]
diff --git a/test/diagnostics/init.lua b/test/diagnostics/init.lua
index cfd0f4cb..d95bf380 100644
--- a/test/diagnostics/init.lua
+++ b/test/diagnostics/init.lua
@@ -76,7 +76,7 @@ local <!x!>
]]
TEST [[
-local x <close>
+local x <close> = print
]]
TEST [[
@@ -319,6 +319,16 @@ return [[
]]
]=]
+config.config.diagnostics.disable['close-non-object'] = true
+TEST [[
+local _ <close> = function () end
+]]
+
+config.config.diagnostics.disable['close-non-object'] = nil
+TEST [[
+local _ <close> = <!1!>
+]]
+
config.config.diagnostics.disable['unused-local'] = true
TEST [[
local f = <!function () end!>
@@ -340,8 +350,7 @@ TEST [[
--<!function F() end!>
--]]
-config.config.diagnostics.disable['unused-local'] = false
-config.config.diagnostics.disable['unused-function'] = true
+config.config.diagnostics.disable['unused-local'] = nil
TEST [[
local mt, x
function mt:m()
@@ -823,11 +832,7 @@ TEST [[
---@class class
local t
]]
-
-TEST [[
-local _ <close> = function () end
-]]
-
+---[==[
-- checkUndefinedField 通用
TEST [[
---@class Foo
@@ -945,3 +950,19 @@ v2 = v
v2:method1()
v2:method2() -- 这个感觉实际应该报错更合适
]]
+
+TEST [[
+---@type table
+T1 = {}
+print(T1.f1)
+---@type table*
+T2 = {}
+print(T2.<!f2!>)
+]]
+--]==]
+TEST [[
+---@overload fun(...)
+local function f() end
+
+f(1)
+]]
diff --git a/test/full/example.lua b/test/full/example.lua
index b19f0485..4f6090ee 100644
--- a/test/full/example.lua
+++ b/test/full/example.lua
@@ -41,6 +41,7 @@ local function testIfExit(path)
local lines = parser:lines(buf)
for i = 1, max do
files.removeAll()
+ files.open('')
files.setText('', buf)
diag('', function () end)
local passed = os.clock() - clock
@@ -52,6 +53,8 @@ local function testIfExit(path)
print(('基准诊断测试[%s]单次耗时:%.10f'):format(path:filename():string(), need))
end
end
+
+require 'tracy' .enable()
testIfExit(ROOT / 'test' / 'example' / 'vm.txt')
testIfExit(ROOT / 'test' / 'example' / 'largeGlobal.txt')
testIfExit(ROOT / 'test' / 'example' / 'guide.txt')
diff --git a/test/full/init.lua b/test/full/init.lua
index f370671e..ad34da7d 100644
--- a/test/full/init.lua
+++ b/test/full/init.lua
@@ -11,3 +11,4 @@ end
require 'full.normal'
require 'full.example'
require 'full.dirty'
+require 'full.self'
diff --git a/test/full/self.lua b/test/full/self.lua
new file mode 100644
index 00000000..247702ae
--- /dev/null
+++ b/test/full/self.lua
@@ -0,0 +1,29 @@
+local files = require 'files'
+local fsu = require 'fs-utility'
+local furi = require 'file-uri'
+local diag = require 'provider.diagnostic'
+local config = require 'config'
+files.removeAll()
+
+fsu.scanDirectory(ROOT, function (path)
+ if path:extension():string() ~= '.lua' then
+ return
+ end
+ local uri = furi.encode(path:string())
+ local text = fsu.loadFile(path)
+ files.setText(uri, text)
+ files.open(uri)
+end)
+
+config.config.diagnostics.disable['undefined-field'] = true
+config.config.diagnostics.disable['redundant-parameter'] = true
+diag.start()
+
+local clock = os.clock()
+
+for uri in files.eachFile() do
+ diag.doDiagnostic(uri)
+end
+
+local passed = os.clock() - clock
+print('基准全量诊断用时:', passed)
diff --git a/test/signature/init.lua b/test/signature/init.lua
index 765e0814..fca995bd 100644
--- a/test/signature/init.lua
+++ b/test/signature/init.lua
@@ -174,3 +174,19 @@ function Foo(param01: any, param02: any)
]],
arg = {14, 25},
}
+
+TEST [[
+function f1(a, b)
+end
+
+function f2(c, d)
+end
+
+f2(f1(),$)
+]]
+{
+ label = [[
+function f2(c: any, d: any)
+]],
+ arg = {21, 26},
+}
diff --git a/test/???.md b/test/???.md
deleted file mode 100644
index 46a4b58a..00000000
--- a/test/???.md
+++ /dev/null
@@ -1,94 +0,0 @@
-# 如何搜索引用
-
-```lua
-local x = 1
-print(x) -- 通过语法搜索到 local x
-```
-
-```lua
-local function f()
-end
-
-local x = f
-print(x) -- 通过 x 的赋值搜索到函数
-```
-
-```lua
-X.Y.Z = 1
-print(X.Y.Z) -- 通过 field 的赋值行为搜索
-```
-
-```lua
-local function f()
- return f
-end
-
-local x = f()
-print(x) -- 引用不穿透函数调用?
-```
-
-```lua
-local t = {
- x = 1
-}
-
-print(t.x) -- 引用穿透表
-```
-
-```lua
-local function f()
- return {
- x = 1
- }
-end
-
-local t = f()
-print(t.x) -- 是否穿透函数返回的表?
-```
-
-在栈帧上标记值?
-
-```lua
-X.Y.Z = 1
-local t = X.Y
-print(t.Z)
-```
-
-字符串匹配?
-1. t -> Z
-2. X.Y -> Z
-3. X.Y.Z = 1
-
-语义匹配?
-1. t -> Z
-2. X.Y -> Z
-3. X -> Y -> Z
-4. X.Y.Z = 1
-
-建立标记?
-```lua
-{
- type = 'set',
- key = {
- 's|X',
- 's|Y',
- 's|Z',
- }
- v = 1,
-},
-{
- type = 'local',
- key = 't',
- v = {
- 's|X',
- 's|Y',
- },
-},
-{
- type = 'get',
- key = {
- 'l|t',
- 's|Z',
- }
-}
-```