summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2023-08-11 17:57:22 +0800
committer最萌小汐 <sumneko@hotmail.com>2023-08-11 17:57:29 +0800
commit5e5a1b2ebb103625bbbb686ab31abc11a78e9d73 (patch)
tree8140d6f9c04a51476e558a9b7fa661a068d6c49a
parentcd370225fc4eaf6e2f6baadfb5a8501943c86783 (diff)
downloadlua-language-server-5e5a1b2ebb103625bbbb686ab31abc11a78e9d73.zip
cleanup tests
-rw-r--r--test/crossfile/diagnostic.lua24
-rw-r--r--test/diagnostics/await-in-sync.lua49
-rw-r--r--test/diagnostics/close-non-object.lua7
-rw-r--r--test/diagnostics/common.lua756
-rw-r--r--test/diagnostics/duplicate-doc-field.lua16
-rw-r--r--test/diagnostics/duplicate-set-field.lua31
-rw-r--r--test/diagnostics/global-in-nil-env.lua6
-rw-r--r--test/diagnostics/init.lua82
-rw-r--r--test/diagnostics/invisible.lua145
-rw-r--r--test/diagnostics/missing-fields.lua199
-rw-r--r--test/diagnostics/missing-parameter.lua8
-rw-r--r--test/diagnostics/missing-return-value.lua28
-rw-r--r--test/diagnostics/missing-return.lua141
-rw-r--r--test/diagnostics/not-yieldable.lua48
-rw-r--r--test/diagnostics/redundant-parameter.lua13
-rw-r--r--test/diagnostics/redundant-return-value.lua26
-rw-r--r--test/diagnostics/undefined-doc-class.lua20
-rw-r--r--test/diagnostics/undefined-doc-name.lua19
-rw-r--r--test/diagnostics/undefined-field.lua16
-rw-r--r--test/diagnostics/unknown-cast-variable.lua8
-rw-r--r--test/diagnostics/unknown-operator.lua4
-rw-r--r--test/diagnostics/unreachable-code.lua71
-rw-r--r--test/diagnostics/unused-local.lua13
23 files changed, 865 insertions, 865 deletions
diff --git a/test/crossfile/diagnostic.lua b/test/crossfile/diagnostic.lua
index e270d3da..1acf3fe2 100644
--- a/test/crossfile/diagnostic.lua
+++ b/test/crossfile/diagnostic.lua
@@ -58,20 +58,26 @@ function TEST(datas)
local results = {}
+ local origins = {}
for _, data in ipairs(datas) do
local uri = furi.encode(data.path)
core(uri, false, function (result)
- results[#results+1] = {
- result.start,
- result.finish,
- uri,
- }
+ if result.code == datas.code then
+ results[#results+1] = {
+ result.start,
+ result.finish,
+ uri,
+ }
+ end
+ origins[#origins+1] = result
end)
end
+ assert(datas.code, 'Need code')
assert(founded(targetList, results))
end
TEST {
+ code = 'different-requires',
{
path = 'f/a.lua',
content = '',
@@ -87,6 +93,7 @@ TEST {
}
TEST {
+ code = 'different-requires',
{
path = 'f/a.lua',
content = '',
@@ -106,6 +113,7 @@ TEST {
}
TEST {
+ code = 'different-requires',
{
path = 'a.lua',
content = '',
@@ -125,6 +133,7 @@ TEST {
}
TEST {
+ code = 'different-requires',
{
path = 'a/init.lua',
content = '',
@@ -144,6 +153,7 @@ TEST {
}
TEST {
+ code = 'invisible',
{ path = 'a.lua', content = [[
---@class A
---@field package x string
@@ -156,6 +166,7 @@ TEST {
}
TEST {
+ code = 'invisible',
{ path = 'a.lua', content = [[
---@class A
---@field package x string
@@ -169,6 +180,7 @@ TEST {
}
TEST {
+ code = 'duplicate-doc-field',
{ path = 'a.lua', content = [[
---@class A
---@field <!x!> number
@@ -180,6 +192,7 @@ TEST {
}
TEST {
+ code = 'duplicate-set-field',
{ path = 'a.lua', content = [[
---@class A
local mt
@@ -197,6 +210,7 @@ TEST {
}
TEST {
+ code = 'duplicate-set-field',
{ path = 'a.lua', content = [[
---@class A
local mt
diff --git a/test/diagnostics/await-in-sync.lua b/test/diagnostics/await-in-sync.lua
index 277101dd..323c1113 100644
--- a/test/diagnostics/await-in-sync.lua
+++ b/test/diagnostics/await-in-sync.lua
@@ -118,34 +118,6 @@ end
]]
TEST [[
----@param cb fun()
-local function f(cb)
- return cb
-end
-
----@async
-local function af()
- return nil
-end
-
-f(<!af!>)
-]]
-
-TEST [[
----@param cb async fun()
-local function f(cb)
- return cb
-end
-
----@async
-local function af()
- return nil
-end
-
-f(af)
-]]
-
-TEST [[
local function f(cb)
cb()
end
@@ -158,24 +130,3 @@ end
return af
]]
-
-TEST [[
-local function f(cb)
- cb()
-end
-
----@async
-local function af()
- f(function () ---@async
- return nil
- end)
-end
-
-return af
-]]
-
-TEST [[
-local _ = type(function () ---@async
- return nil
-end)
-]]
diff --git a/test/diagnostics/close-non-object.lua b/test/diagnostics/close-non-object.lua
index 10f207f0..11b882b7 100644
--- a/test/diagnostics/close-non-object.lua
+++ b/test/diagnostics/close-non-object.lua
@@ -9,3 +9,10 @@ local _ <close> = <!''!>
TEST [[
local c <close> = <!(function () return 1 end)()!>
]]
+
+TEST [[
+---@type unknown
+local t
+
+local _ <close> = t
+]]
diff --git a/test/diagnostics/common.lua b/test/diagnostics/common.lua
deleted file mode 100644
index 9352765f..00000000
--- a/test/diagnostics/common.lua
+++ /dev/null
@@ -1,756 +0,0 @@
-
-
-TEST [[
----@cast <!x!> integer
-]]
-
-TEST [[
----@diagnostic disable: unused-local
-local x, y
----@cast y number
-]]
-
-TEST [[
----@class A
-
----@class B
----@field [integer] A
----@field [A] true
-]]
-
-TEST [[
----@class A
-
----@class B
----@field [<!A!>] A
----@field [<!A!>] true
-]]
-
-TEST [[
----@diagnostic disable: unused-local
-
----@type 'x'
-local t
-
-local n = t:upper()
-]]
-
-TEST [[
----@diagnostic disable: unused-local
-
----@alias A 'x'
-
----@type A
-local t
-
-local n = t:upper()
-]]
-
-TEST [[
-local t = {}
-
-function t:init() end
-
-<!t.init()!>
-]]
-
-TEST [[
----@meta
-
-return function f(x, y, z) end
-]]
-
-util.arrayInsert(disables, 'redundant-return')
-TEST [[
----@return number
-function F()
- <!return!>
-end
-]]
-
-TEST [[
----@return number, number
-function F()
- <!return!> 1
-end
-]]
-
-TEST [[
----@return number, number?
-function F()
- return 1
-end
-]]
-
-TEST [[
----@return ...
-function F()
- return
-end
-]]
-
-TEST [[
----@return number, number?
-function F()
- return 1, 1, <!1!>
-end
-]]
-
-TEST [[
----@return number, number?
-function F()
- return 1, 1, <!1!>, <!2!>, <!3!>
-end
-]]
-
-TEST [[
----@meta
-
----@return number, number
-local function r2() end
-
----@return number, number?
-function F()
- return 1, <!r2()!>
-end
-]]
-
-TEST [[
----@return number
-function F()
- X = 1<!!>
-end
-]]
-
-TEST [[
-local A
----@return number
-function F()
- if A then
- return 1
- end<!!>
-end
-]]
-
-TEST [[
-local A, B
----@return number
-function F()
- if A then
- return 1
- elseif B then
- return 2
- end<!!>
-end
-]]
-
-TEST [[
-local A, B
----@return number
-function F()
- if A then
- return 1
- elseif B then
- return 2
- else
- return 3
- end
-end
-]]
-
-TEST [[
-local A, B
----@return number
-function F()
- if A then
- elseif B then
- return 2
- else
- return 3
- end<!!>
-end
-]]
-
-TEST [[
----@return any
-function F()
- X = 1
-end
-]]
-
-TEST [[
----@return any, number
-function F()
- X = 1<!!>
-end
-]]
-
-TEST [[
----@return number, any
-function F()
- X = 1<!!>
-end
-]]
-
-TEST [[
----@return any, any
-function F()
- X = 1
-end
-]]
-
-TEST [[
-local A
----@return number
-function F()
- for _ = 1, 10 do
- if A then
- return 1
- end
- end
- error('should not be here')
-end
-]]
-
-TEST [[
-local A
----@return number
-function F()
- while true do
- if A then
- return 1
- end
- end
-end
-]]
-
-TEST [[
-local A
----@return number
-function F()
- while A do
- if A then
- return 1
- end
- end<!!>
-end
-]]
-
-TEST [[
-local A
----@return number
-function F()
- while A do
- if A then
- return 1
- else
- return 2
- end
- end
-end
-]]
-
-TEST [[
----@return number?
-function F()
-
-end
-]]
-
-util.arrayRemove(disables, 'redundant-return')
-
-TEST [[
----@class A
----@operator <!xxx!>: A
-]]
-
-config.add(nil, 'Lua.diagnostics.unusedLocalExclude', 'll_*')
-
-TEST [[
-local <!xx!>
-local ll_1
-local ll_2
-local <!ll!>
-]]
-
-config.remove(nil, 'Lua.diagnostics.unusedLocalExclude', 'll_*')
-
-TEST [[
----@diagnostic disable: undefined-global
-
-if X then
- return false
-elseif X then
- return false
-else
- return false
-end
-<!return true!>
-]]
-
-TEST [[
----@diagnostic disable: undefined-global
-
-function X()
- if X then
- return false
- elseif X then
- return false
- else
- return false
- end
- <!return true!>
-end
-]]
-
-TEST [[
-while true do
-end
-
-<!print(1)!>
-]]
-
-TEST [[
-while true do
-end
-
-<!print(1)!>
-]]
-
-TEST [[
-while X do
- X = 1
-end
-
-print(1)
-]]
-
-TEST [[
----@diagnostic disable: undefined-global
-
-while true do
- if not X then
- break
- end
-end
-
-print(1)
-
-do return end
-]]
-
-TEST [[
----@type unknown
-local t
-
-local _ <close> = t
-]]
-
-TEST [[
----@meta
----@diagnostic disable: duplicate-set-field
----@class A
-local m = {}
-
-function m.ff() end
-
-function m.ff(x) end
-
-m.ff(1)
-]]
-
-TEST [[
-local done = false
-
-local function set_done()
- done = true
-end
-
-while not done do
- set_done()
-end
-
-print(1)
-]]
-
-TEST [[
----@class A
----@field private x number
----@field protected y number
----@field public z number
-local t
-print(t.x)
-]]
-
-TEST [[
----@class A
----@field private x number
----@field protected y number
----@field public z number
-
----@type A
-local t
-
-print(t.<!x!>)
-]]
-
-TEST [[
----@class A
----@field private x number
----@field protected y number
----@field public z number
-
----@class B: A
-local t
-
-print(t.y)
-]]
-
-TEST [[
----@class A
----@field private x number
----@field protected y number
----@field public z number
-
----@class B: A
-
----@type B
-local t
-
-print(t.<!y!>)
-]]
-
-TEST [[
----@class A
----@field private x number
----@field protected y number
----@field public z number
-
----@class B: A
-
----@type B
-local t
-
-print(t.z)
-]]
-
-TEST [[
----@class A
----@field _id number
-
----@type A
-local t
-
-print(t._id)
-]]
-
-config.set(nil, 'Lua.doc.privateName', { '_*' })
-TEST [[
----@class A
----@field _id number
-
----@type A
-local t
-
-print(t.<!_id!>)
-
----@class B: A
-local t2
-
-print(t2.<!_id!>)
-]]
-config.set(nil, 'Lua.doc.privateName', nil)
-
-config.set(nil, 'Lua.doc.protectedName', { '_*' })
-TEST [[
----@class A
----@field _id number
-
----@type A
-local t
-
-print(t.<!_id!>)
-
----@class B: A
-local t2
-
-print(t2._id)
-]]
-config.set(nil, 'Lua.doc.protectedName', nil)
-
-TEST [[
----@class A
----@field private x number
-local mt = {}
-
-function mt:init()
- print(self.x)
-end
-]]
-
-TEST [[
----@diagnostic disable: unused-local
----@diagnostic disable: missing-fields
----@class A
----@field private x number
-local mt = {}
-
-function mt:init()
- ---@type A
- local obj = {}
-
- obj.x = 1
-end
-]]
-
-TEST [[
----@diagnostic disable: unused-local
----@diagnostic disable: missing-fields
----@class A
----@field private x number
-local mt = {}
-
-mt.init = function ()
- ---@type A
- local obj = {}
-
- obj.x = 1
-end
-]]
-
-TEST [[
----@class A
-X = {}
-
-function <!X.f!>() end
-
-function <!X.f!>() end
-]]
-
-TEST [[
----@meta
-
----@class A
-X = {}
-
-function X.f() end
-
-function X.f() end
-]]
-
-TEST [[
----@class A
-X = {}
-
-if true then
- function X.f() end
-else
- function X.f() end
-end
-]]
-
-TESTWITH 'global-in-nil-env' [[
-local function foo(_ENV)
- Joe = "human"
-end
-]]
-
-TEST [[
----@diagnostic disable: unused-local
----@class A
----@field x number
----@field y? number
----@field z number
-
----@type A
-local t = <!{}!>
-]]
-
-TEST [[
----@diagnostic disable: unused-local
----@class A
----@field x number
----@field y? number
----@field z number
-
----@type A
-local t = <!{
- x = 1,
-}!>
-]]
-
-TEST [[
----@diagnostic disable: unused-local
----@class A
----@field x number
----@field y? number
----@field z number
-
----@type A
-local t = <!{
- x = 1,
- y = 2,
-}!>
-]]
-
-TEST [[
----@diagnostic disable: unused-local
----@class A
----@field x number
----@field y? number
----@field z number
-
----@type A
-local t = {
- x = 1,
- y = 2,
- z = 3,
-}
-]]
-
-TEST [[
----@diagnostic disable: unused-local
----@class A
----@field x number
----@field y? number
----@field z number
-
----@type A
-local t = {
- x = 1,
- z = 3,
-}
-]]
-
-TEST [[
----@diagnostic disable: unused-local
----@class A
----@field x number
----@field y? number
----@field z number
-
----@param a A
-local function f(a) end
-
-f <!{}!>
-]]
-
-TEST [[
----@diagnostic disable: unused-local
----@class A
----@field x number
----@field y? number
----@field z number
-
----@param a A
-local function f(a) end
-
-f <!{
- x = 1,
-}!>
-]]
-
-TEST [[
----@diagnostic disable: unused-local
----@class A
----@field x number
----@field y? number
----@field z number
-
----@param a A
-local function f(a) end
-
-f <!{
- x = 1,
- y = 2,
-}!>
-]]
-
-TEST [[
----@diagnostic disable: unused-local
----@class A
----@field x number
----@field y? number
----@field z number
-
----@param a A
-local function f(a) end
-
-f {
- x = 1,
- y = 2,
- z = 3,
-}
-]]
-
-TEST [[
----@diagnostic disable: unused-local
----@class A
----@field x number
----@field y? number
----@field z number
-
----@param a A
-local function f(a) end
-
-f {
- x = 1,
- z = 3,
-}
-]]
-
-TEST [[
----@diagnostic disable: unused-local
----@class A
----@field x number
-local t = {}
-]]
-
-TEST [[
----@diagnostic disable: unused-local
-
----@class A
----@field x number
-
----@class A
-local t = {}
-]]
-
-TEST [[
----@diagnostic disable: unused-local
-
----@class Foo
----@field a number
----@field b number
----@field c number
-
----@type Foo|Foo[]
-local a = {
- {
- a = 1,
- b = 2,
- c = 3,
- }
-}
-]]
-
-TEST [[
----@diagnostic disable: unused-local
-
----@class Foo
----@field a number
----@field b number
----@field c number
-
----@class Bar
----@field ba number
----@field bb number
----@field bc number
-
----@type Foo|Bar
-local b = {
- a = 1,
- b = 2,
- c = 3,
-}
-]]
diff --git a/test/diagnostics/duplicate-doc-field.lua b/test/diagnostics/duplicate-doc-field.lua
index 937e2ea4..8f385335 100644
--- a/test/diagnostics/duplicate-doc-field.lua
+++ b/test/diagnostics/duplicate-doc-field.lua
@@ -20,3 +20,19 @@ TEST [[
--- @field <!on!> fun(eventName: '"died"', cb: fun(i: integer))
local emit = {}
]]
+
+TEST [[
+---@class A
+
+---@class B
+---@field [integer] A
+---@field [A] true
+]]
+
+TEST [[
+---@class A
+
+---@class B
+---@field [<!A!>] A
+---@field [<!A!>] true
+]]
diff --git a/test/diagnostics/duplicate-set-field.lua b/test/diagnostics/duplicate-set-field.lua
index 52f70c9d..469bc3ea 100644
--- a/test/diagnostics/duplicate-set-field.lua
+++ b/test/diagnostics/duplicate-set-field.lua
@@ -41,3 +41,34 @@ m.x = nil
return m
]]
+
+TEST [[
+---@class A
+X = {}
+
+function <!X.f!>() end
+
+function <!X.f!>() end
+]]
+
+TEST [[
+---@meta
+
+---@class A
+X = {}
+
+function X.f() end
+
+function X.f() end
+]]
+
+TEST [[
+---@class A
+X = {}
+
+if true then
+ function X.f() end
+else
+ function X.f() end
+end
+]]
diff --git a/test/diagnostics/global-in-nil-env.lua b/test/diagnostics/global-in-nil-env.lua
index 1dc97bd1..a0b8cd3e 100644
--- a/test/diagnostics/global-in-nil-env.lua
+++ b/test/diagnostics/global-in-nil-env.lua
@@ -36,3 +36,9 @@ TEST [[
_ENV = nil
local _ = <!print!> --> local _ = _ENV.print
]]
+
+TEST [[
+local function foo(_ENV)
+ Joe = "human"
+end
+]]
diff --git a/test/diagnostics/init.lua b/test/diagnostics/init.lua
index d1acd31e..cd6a5c03 100644
--- a/test/diagnostics/init.lua
+++ b/test/diagnostics/init.lua
@@ -69,47 +69,59 @@ local function check(name)
require('diagnostics.' .. name)
end
-check 'unused-local'
-check 'unused-function'
-check 'undefined-global'
-check 'unused-label'
-check 'trailing-space'
-check 'redefined-local'
-check 'global-in-nil-env'
-check 'undefined-env-child'
-check 'newline-call'
-check 'newfield-call'
-check 'redundant-parameter'
-check 'cast-local-type'
+check 'ambiguity-1'
check 'assign-type-mismatch'
+check 'await-in-sync'
+check 'cast-local-type'
check 'cast-type-mismatch'
-check 'need-check-nil'
-check 'return-type-mismatch'
-check 'missing-return'
-check 'missing-return-value'
-check 'redundant-return-value'
-check 'incomplete-signature-doc'
-check 'missing-global-doc'
-check 'missing-local-export-doc'
-check 'global-element'
-check 'missing-parameter'
+check 'circle-doc-class'
check 'close-non-object'
-check 'duplicate-doc-field'
-check 'lowercase-global'
+check 'code-after-break'
+check 'count-down-loop'
check 'deprecated'
+check 'discard-returns'
+check 'doc-field-no-class'
+check 'duplicate-doc-alias'
+check 'duplicate-doc-field'
+check 'duplicate-doc-param'
check 'duplicate-index'
+check 'duplicate-set-field'
check 'empty-block'
+check 'global-element'
+check 'global-in-nil-env'
+check 'incomplete-signature-doc'
+check 'invisible'
+check 'lowercase-global'
+check 'missing-fields'
+check 'missing-global-doc'
+check 'missing-local-export-doc'
+check 'missing-parameter'
+check 'missing-return-value'
+check 'missing-return'
+check 'need-check-nil'
+check 'newfield-call'
+check 'newline-call'
+check 'not-yieldable'
+check 'param-type-mismatch'
+check 'redefined-local'
+check 'redundant-parameter'
+check 'redundant-return-value'
+check 'redundant-return'
check 'redundant-value'
-check 'code-after-break'
-check 'duplicate-doc-alias'
-check 'circle-doc-class'
+check 'return-type-mismatch'
+check 'trailing-space'
+check 'unbalanced-assignments'
+check 'undefined-doc-class'
+check 'undefined-doc-name'
check 'undefined-doc-param'
-check 'duplicate-doc-param'
-check 'doc-field-no-class'
+check 'undefined-env-child'
check 'undefined-field'
-check 'count-down-loop'
-check 'duplicate-set-field'
-check 'redundant-return'
-check 'discard-returns'
-
-require 'diagnostics.common'
+check 'undefined-global'
+check 'unknown-cast-variable'
+check 'unknown-diag-code'
+check 'unknown-operator'
+check 'unreachable-code'
+check 'unused-function'
+check 'unused-label'
+check 'unused-local'
+check 'unused-vararg'
diff --git a/test/diagnostics/invisible.lua b/test/diagnostics/invisible.lua
new file mode 100644
index 00000000..2fc6791e
--- /dev/null
+++ b/test/diagnostics/invisible.lua
@@ -0,0 +1,145 @@
+local config = require 'config'
+
+TEST [[
+---@class A
+---@field private x number
+---@field protected y number
+---@field public z number
+local t
+print(t.x)
+]]
+
+TEST [[
+---@class A
+---@field private x number
+---@field protected y number
+---@field public z number
+
+---@type A
+local t
+
+print(t.<!x!>)
+]]
+
+TEST [[
+---@class A
+---@field private x number
+---@field protected y number
+---@field public z number
+
+---@class B: A
+local t
+
+print(t.y)
+]]
+
+TEST [[
+---@class A
+---@field private x number
+---@field protected y number
+---@field public z number
+
+---@class B: A
+
+---@type B
+local t
+
+print(t.<!y!>)
+]]
+
+TEST [[
+---@class A
+---@field private x number
+---@field protected y number
+---@field public z number
+
+---@class B: A
+
+---@type B
+local t
+
+print(t.z)
+]]
+TEST [[
+---@class A
+---@field _id number
+
+---@type A
+local t
+
+print(t._id)
+]]
+
+config.set(nil, 'Lua.doc.privateName', { '_*' })
+TEST [[
+---@class A
+---@field _id number
+
+---@type A
+local t
+
+print(t.<!_id!>)
+
+---@class B: A
+local t2
+
+print(t2.<!_id!>)
+]]
+config.set(nil, 'Lua.doc.privateName', nil)
+
+config.set(nil, 'Lua.doc.protectedName', { '_*' })
+TEST [[
+---@class A
+---@field _id number
+
+---@type A
+local t
+
+print(t.<!_id!>)
+
+---@class B: A
+local t2
+
+print(t2._id)
+]]
+config.set(nil, 'Lua.doc.protectedName', nil)
+
+TEST [[
+---@class A
+---@field private x number
+local mt = {}
+
+function mt:init()
+ print(self.x)
+end
+]]
+
+TEST [[
+---@diagnostic disable: unused-local
+---@diagnostic disable: missing-fields
+---@class A
+---@field private x number
+local mt = {}
+
+function mt:init()
+ ---@type A
+ local obj = {}
+
+ obj.x = 1
+end
+]]
+
+TEST [[
+---@diagnostic disable: unused-local
+---@diagnostic disable: missing-fields
+---@class A
+---@field private x number
+local mt = {}
+
+mt.init = function ()
+ ---@type A
+ local obj = {}
+
+ obj.x = 1
+end
+]]
diff --git a/test/diagnostics/missing-fields.lua b/test/diagnostics/missing-fields.lua
new file mode 100644
index 00000000..d8731775
--- /dev/null
+++ b/test/diagnostics/missing-fields.lua
@@ -0,0 +1,199 @@
+TEST [[
+---@diagnostic disable: unused-local
+---@class A
+---@field x number
+---@field y? number
+---@field z number
+
+---@type A
+local t = <!{}!>
+]]
+
+TEST [[
+---@diagnostic disable: unused-local
+---@class A
+---@field x number
+---@field y? number
+---@field z number
+
+---@type A
+local t = <!{
+ x = 1,
+}!>
+]]
+
+TEST [[
+---@diagnostic disable: unused-local
+---@class A
+---@field x number
+---@field y? number
+---@field z number
+
+---@type A
+local t = <!{
+ x = 1,
+ y = 2,
+}!>
+]]
+
+TEST [[
+---@diagnostic disable: unused-local
+---@class A
+---@field x number
+---@field y? number
+---@field z number
+
+---@type A
+local t = {
+ x = 1,
+ y = 2,
+ z = 3,
+}
+]]
+
+TEST [[
+---@diagnostic disable: unused-local
+---@class A
+---@field x number
+---@field y? number
+---@field z number
+
+---@type A
+local t = {
+ x = 1,
+ z = 3,
+}
+]]
+
+TEST [[
+---@diagnostic disable: unused-local
+---@class A
+---@field x number
+---@field y? number
+---@field z number
+
+---@param a A
+local function f(a) end
+
+f <!{}!>
+]]
+
+TEST [[
+---@diagnostic disable: unused-local
+---@class A
+---@field x number
+---@field y? number
+---@field z number
+
+---@param a A
+local function f(a) end
+
+f <!{
+ x = 1,
+}!>
+]]
+
+TEST [[
+---@diagnostic disable: unused-local
+---@class A
+---@field x number
+---@field y? number
+---@field z number
+
+---@param a A
+local function f(a) end
+
+f <!{
+ x = 1,
+ y = 2,
+}!>
+]]
+
+TEST [[
+---@diagnostic disable: unused-local
+---@class A
+---@field x number
+---@field y? number
+---@field z number
+
+---@param a A
+local function f(a) end
+
+f {
+ x = 1,
+ y = 2,
+ z = 3,
+}
+]]
+
+TEST [[
+---@diagnostic disable: unused-local
+---@class A
+---@field x number
+---@field y? number
+---@field z number
+
+---@param a A
+local function f(a) end
+
+f {
+ x = 1,
+ z = 3,
+}
+]]
+
+TEST [[
+---@diagnostic disable: unused-local
+---@class A
+---@field x number
+local t = {}
+]]
+
+TEST [[
+---@diagnostic disable: unused-local
+
+---@class A
+---@field x number
+
+---@class A
+local t = {}
+]]
+
+TEST [[
+---@diagnostic disable: unused-local
+
+---@class Foo
+---@field a number
+---@field b number
+---@field c number
+
+---@type Foo|Foo[]
+local a = {
+ {
+ a = 1,
+ b = 2,
+ c = 3,
+ }
+}
+]]
+
+TEST [[
+---@diagnostic disable: unused-local
+
+---@class Foo
+---@field a number
+---@field b number
+---@field c number
+
+---@class Bar
+---@field ba number
+---@field bb number
+---@field bc number
+
+---@type Foo|Bar
+local b = {
+ a = 1,
+ b = 2,
+ c = 3,
+}
+]]
diff --git a/test/diagnostics/missing-parameter.lua b/test/diagnostics/missing-parameter.lua
index 91e9b88d..154d630b 100644
--- a/test/diagnostics/missing-parameter.lua
+++ b/test/diagnostics/missing-parameter.lua
@@ -80,3 +80,11 @@ local function x(a, b)
end
x(1)
]]
+
+TEST [[
+local t = {}
+
+function t:init() end
+
+<!t.init()!>
+]]
diff --git a/test/diagnostics/missing-return-value.lua b/test/diagnostics/missing-return-value.lua
index e45bb4d2..3bad7974 100644
--- a/test/diagnostics/missing-return-value.lua
+++ b/test/diagnostics/missing-return-value.lua
@@ -4,3 +4,31 @@ local function f()
<!return!>
end
]]
+
+TEST [[
+---@return number
+function F()
+ <!return!>
+end
+]]
+
+TEST [[
+---@return number, number
+function F()
+ <!return!> 1
+end
+]]
+
+TEST [[
+---@return number, number?
+function F()
+ return 1
+end
+]]
+
+TEST [[
+---@return ...
+function F()
+ return
+end
+]]
diff --git a/test/diagnostics/missing-return.lua b/test/diagnostics/missing-return.lua
index 9e5a99c9..b8c1e7d3 100644
--- a/test/diagnostics/missing-return.lua
+++ b/test/diagnostics/missing-return.lua
@@ -15,3 +15,144 @@ TEST [[
local function f()
end
]]
+
+TEST [[
+---@return number
+function F()
+ X = 1<!!>
+end
+]]
+TEST [[
+local A
+---@return number
+function F()
+ if A then
+ return 1
+ end<!!>
+end
+]]
+
+TEST [[
+local A, B
+---@return number
+function F()
+ if A then
+ return 1
+ elseif B then
+ return 2
+ end<!!>
+end
+]]
+
+TEST [[
+local A, B
+---@return number
+function F()
+ if A then
+ return 1
+ elseif B then
+ return 2
+ else
+ return 3
+ end
+end
+]]
+
+TEST [[
+local A, B
+---@return number
+function F()
+ if A then
+ elseif B then
+ return 2
+ else
+ return 3
+ end<!!>
+end
+]]
+
+TEST [[
+---@return any
+function F()
+ X = 1
+end
+]]
+
+TEST [[
+---@return any, number
+function F()
+ X = 1<!!>
+end
+]]
+
+TEST [[
+---@return number, any
+function F()
+ X = 1<!!>
+end
+]]
+
+TEST [[
+---@return any, any
+function F()
+ X = 1
+end
+]]
+
+TEST [[
+local A
+---@return number
+function F()
+ for _ = 1, 10 do
+ if A then
+ return 1
+ end
+ end
+ error('should not be here')
+end
+]]
+
+TEST [[
+local A
+---@return number
+function F()
+ while true do
+ if A then
+ return 1
+ end
+ end
+end
+]]
+
+TEST [[
+local A
+---@return number
+function F()
+ while A do
+ if A then
+ return 1
+ end
+ end<!!>
+end
+]]
+
+TEST [[
+local A
+---@return number
+function F()
+ while A do
+ if A then
+ return 1
+ else
+ return 2
+ end
+ end
+end
+]]
+
+TEST [[
+---@return number?
+function F()
+
+end
+]]
diff --git a/test/diagnostics/not-yieldable.lua b/test/diagnostics/not-yieldable.lua
new file mode 100644
index 00000000..81e972ee
--- /dev/null
+++ b/test/diagnostics/not-yieldable.lua
@@ -0,0 +1,48 @@
+TEST [[
+---@param cb fun()
+local function f(cb)
+ return cb
+end
+
+---@async
+local function af()
+ return nil
+end
+
+f(<!af!>)
+]]
+
+TEST [[
+---@param cb async fun()
+local function f(cb)
+ return cb
+end
+
+---@async
+local function af()
+ return nil
+end
+
+f(af)
+]]
+
+TEST [[
+local function f(cb)
+ cb()
+end
+
+---@async
+local function af()
+ f(function () ---@async
+ return nil
+ end)
+end
+
+return af
+]]
+
+TEST [[
+local _ = type(function () ---@async
+ return nil
+end)
+]]
diff --git a/test/diagnostics/redundant-parameter.lua b/test/diagnostics/redundant-parameter.lua
index 3bbb50f6..fabe3340 100644
--- a/test/diagnostics/redundant-parameter.lua
+++ b/test/diagnostics/redundant-parameter.lua
@@ -199,3 +199,16 @@ local function foo(x) end
foo(f())
]]
+
+TEST [[
+---@meta
+---@diagnostic disable: duplicate-set-field
+---@class A
+local m = {}
+
+function m.ff() end
+
+function m.ff(x) end
+
+m.ff(1)
+]]
diff --git a/test/diagnostics/redundant-return-value.lua b/test/diagnostics/redundant-return-value.lua
index c406e69e..f3e2c584 100644
--- a/test/diagnostics/redundant-return-value.lua
+++ b/test/diagnostics/redundant-return-value.lua
@@ -4,3 +4,29 @@ local function f()
return 1, <!true!>
end
]]
+
+TEST [[
+---@return number, number?
+function F()
+ return 1, 1, <!1!>
+end
+]]
+
+TEST [[
+---@return number, number?
+function F()
+ return 1, 1, <!1!>, <!2!>, <!3!>
+end
+]]
+
+TEST [[
+---@meta
+
+---@return number, number
+local function r2() end
+
+---@return number, number?
+function F()
+ return 1, <!r2()!>
+end
+]]
diff --git a/test/diagnostics/undefined-doc-class.lua b/test/diagnostics/undefined-doc-class.lua
index 6b7acfd1..d10b89d8 100644
--- a/test/diagnostics/undefined-doc-class.lua
+++ b/test/diagnostics/undefined-doc-class.lua
@@ -1,23 +1,3 @@
TEST [[
---@class A : <!B!>
]]
-
-TEST [[
----@type <!A!>
-]]
-
-TEST [[
----@class A
----@type A|<!B!>|<!C!>
-]]
-
-TEST [[
----@class AAA
----@alias B AAA
-
----@type B
-]]
-
-TEST [[
----@alias B <!AAA!>
-]]
diff --git a/test/diagnostics/undefined-doc-name.lua b/test/diagnostics/undefined-doc-name.lua
new file mode 100644
index 00000000..9a55108a
--- /dev/null
+++ b/test/diagnostics/undefined-doc-name.lua
@@ -0,0 +1,19 @@
+TEST [[
+---@type <!A!>
+]]
+
+TEST [[
+---@class A
+---@type A|<!B!>|<!C!>
+]]
+
+TEST [[
+---@class AAA
+---@alias B AAA
+
+---@type B
+]]
+
+TEST [[
+---@alias B <!AAA!>
+]]
diff --git a/test/diagnostics/undefined-field.lua b/test/diagnostics/undefined-field.lua
index 4bca5195..aff329fb 100644
--- a/test/diagnostics/undefined-field.lua
+++ b/test/diagnostics/undefined-field.lua
@@ -130,3 +130,19 @@ local n
print(n.x)
]]
+
+TEST [[
+---@type 'x'
+local t
+
+local n = t:upper()
+]]
+
+TEST [[
+---@alias A 'x'
+
+---@type A
+local t
+
+local n = t:upper()
+]]
diff --git a/test/diagnostics/unknown-cast-variable.lua b/test/diagnostics/unknown-cast-variable.lua
new file mode 100644
index 00000000..a347083f
--- /dev/null
+++ b/test/diagnostics/unknown-cast-variable.lua
@@ -0,0 +1,8 @@
+TEST [[
+---@cast <!x!> integer
+]]
+
+TEST [[
+local x, y
+---@cast y number
+]]
diff --git a/test/diagnostics/unknown-operator.lua b/test/diagnostics/unknown-operator.lua
new file mode 100644
index 00000000..bb193f6a
--- /dev/null
+++ b/test/diagnostics/unknown-operator.lua
@@ -0,0 +1,4 @@
+TEST [[
+---@class A
+---@operator <!xxx!>: A
+]]
diff --git a/test/diagnostics/unreachable-code.lua b/test/diagnostics/unreachable-code.lua
new file mode 100644
index 00000000..4444252f
--- /dev/null
+++ b/test/diagnostics/unreachable-code.lua
@@ -0,0 +1,71 @@
+TEST [[
+if X then
+ return false
+elseif X then
+ return false
+else
+ return false
+end
+<!return true!>
+]]
+
+TEST [[
+function X()
+ if X then
+ return false
+ elseif X then
+ return false
+ else
+ return false
+ end
+ <!return true!>
+end
+]]
+
+TEST [[
+while true do
+end
+
+<!print(1)!>
+]]
+
+TEST [[
+while true do
+end
+
+<!print(1)!>
+]]
+
+TEST [[
+while X do
+ X = 1
+end
+
+print(1)
+]]
+
+TEST [[
+while true do
+ if not X then
+ break
+ end
+end
+
+print(1)
+
+do return end
+]]
+
+TEST [[
+local done = false
+
+local function set_done()
+ done = true
+end
+
+while not done do
+ set_done()
+end
+
+print(1)
+]]
diff --git a/test/diagnostics/unused-local.lua b/test/diagnostics/unused-local.lua
index 1faace25..425f3e1e 100644
--- a/test/diagnostics/unused-local.lua
+++ b/test/diagnostics/unused-local.lua
@@ -1,3 +1,5 @@
+local config = require 'config'
+
TEST [[
local <!x!>
]]
@@ -84,3 +86,14 @@ TEST [[
local <!t!> = {}
<!t!>[1] = 1
]]
+
+config.add(nil, 'Lua.diagnostics.unusedLocalExclude', 'll_*')
+
+TEST [[
+local <!xx!>
+local ll_1
+local ll_2
+local <!ll!>
+]]
+
+config.remove(nil, 'Lua.diagnostics.unusedLocalExclude', 'll_*')