From 297ac3aabb38c22648f501038e1e66b6c8f9f936 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Thu, 20 Jul 2023 18:08:35 +0800 Subject: new diagnostic: `missing-fields` --- test/diagnostics/common.lua | 150 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 148 insertions(+), 2 deletions(-) (limited to 'test/diagnostics/common.lua') diff --git a/test/diagnostics/common.lua b/test/diagnostics/common.lua index a1dbe819..d061b4e4 100644 --- a/test/diagnostics/common.lua +++ b/test/diagnostics/common.lua @@ -156,13 +156,13 @@ print(A) -- no warning TEST [[ ---@type iolib -_ENV = {} +_ENV = io (stderr) -- `print` is warning but `stderr` is not ]] TEST [[ ---@type iolib -local _ENV = {} +local _ENV = io (stderr) -- `print` is warning but `stderr` is not ]] @@ -2206,6 +2206,7 @@ end TEST [[ ---@diagnostic disable: unused-local +---@diagnostic disable: missing-fields ---@class A ---@field private x number local mt = {} @@ -2220,6 +2221,7 @@ end TEST [[ ---@diagnostic disable: unused-local +---@diagnostic disable: missing-fields ---@class A ---@field private x number local mt = {} @@ -2268,3 +2270,147 @@ 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 = +]] + +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, + 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 +]] + +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, + 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, +} +]] -- cgit v1.2.3 From f074686c59f033566b3fb44aa3f73d1a2ec0e7ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Fri, 21 Jul 2023 15:21:37 +0800 Subject: fix `missing-fields` --- test/diagnostics/common.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'test/diagnostics/common.lua') diff --git a/test/diagnostics/common.lua b/test/diagnostics/common.lua index d061b4e4..aff97c77 100644 --- a/test/diagnostics/common.lua +++ b/test/diagnostics/common.lua @@ -2414,3 +2414,20 @@ f { 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 = {} +]] -- cgit v1.2.3 From f1c9b931d6eb1918b29497dcbf162f228e207126 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Tue, 25 Jul 2023 11:44:31 +0800 Subject: fix #2214 --- test/diagnostics/common.lua | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'test/diagnostics/common.lua') diff --git a/test/diagnostics/common.lua b/test/diagnostics/common.lua index aff97c77..28a3a32a 100644 --- a/test/diagnostics/common.lua +++ b/test/diagnostics/common.lua @@ -2431,3 +2431,42 @@ TEST [[ ---@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, +} +]] -- cgit v1.2.3 From 5a0804e9869382b8d2f1fa1fffd362dc2fea9c52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Thu, 10 Aug 2023 17:44:22 +0800 Subject: clean up tests --- test/diagnostics/common.lua | 296 -------------------------------------------- 1 file changed, 296 deletions(-) (limited to 'test/diagnostics/common.lua') diff --git a/test/diagnostics/common.lua b/test/diagnostics/common.lua index 28a3a32a..e0a3e342 100644 --- a/test/diagnostics/common.lua +++ b/test/diagnostics/common.lua @@ -1,298 +1,6 @@ local config = require 'config' local util = require 'utility' -local disables = config.get(nil, 'Lua.diagnostics.disable') - -TEST [[ -local -]] - -TEST [[ -local y -local x = y -]] - -TEST [[ -local function x() -end -x() -]] - -TEST [[ -return function (x) - x.a = 1 -end -]] - -TEST [[ -local = {} -.a = 1 -]] - -TEST [[ -local () -end!> -]] - - -TEST [[ -local = -]] - -TEST [[ -local - = -]] - -TEST [[ -local -local () - x() -end!> -]] - -TEST [[ -local print, _G -print() -print() -print() -print() -print() -print(Z) -print(_G) -Z = 1 -]] - -TEST [[ -:::: -]] - -TEST [[ - -]] - -TEST [[ - - -]] - -TEST [[ -X = 1 -]] - -TEST [[ -X = [=[ - ]=] -]] - -TEST [[ --- xxxx -]] - -TEST [[ --- [=[ - ]=] -]] - -TEST [[ -local x -print(x) -local -print(x) -]] - -TEST [[ -local x -print(x) -local -print(x) -local -print(x) -]] - -TEST [[ -local _ -print(_) -local _ -print(_) -local _ENV -(_ENV) -- 由于重定义了_ENV,因此print变为了未定义全局变量 -]] - -TEST [[ -local x -return x, function () - return x -end -]] - -TEST [[ -print(1) -_ENV = nil -]] - -TEST [[ ----@diagnostic disable: undefined-global -_ENV = nil -() -- `print` and `A` should warning -]] - -TEST [[ ----@diagnostic disable: undefined-global -local _ENV = nil -() -- `print` and `A` should warning -]] - -TEST [[ -_ENV = {} -print(A) -- no warning -]] - -TEST [[ -local _ENV = {} -print(A) -- no warning -]] - -TEST [[ ----@type iolib -_ENV = io -(stderr) -- `print` is warning but `stderr` is not -]] - -TEST [[ ----@type iolib -local _ENV = io -(stderr) -- `print` is warning but `stderr` is not -]] - -TEST [[ -local _ENV = { print = print } -print(1) -]] - -util.arrayInsert(disables, 'undefined-env-child') -TEST [[ -_ENV = nil - = 1 --> _ENV.GLOBAL = 1 -]] - -TEST [[ -_ENV = nil -local _ = --> local _ = _ENV.print -]] - -TEST [[ -_ENV = {} -GLOBAL = 1 --> _ENV.GLOBAL = 1 -]] - -TEST [[ -_ENV = {} -local _ = print --> local _ = _ENV.print -]] - -TEST [[ -GLOBAL = 1 -_ENV = nil -]] - -util.arrayRemove(disables, 'undefined-env-child') -TEST [[ -:sub(1, 1) -]] - -TEST [[ -print() -('string') -]] - -TEST [[ -print -{} -{} -]] - -TEST [[ -local x -return x - : f(1) - : f(1) -]] - -TEST [[ -return { - -} -]] - -TEST [[ -return { - -} -]] - -TEST [[ -print() -'string' -]] - -TEST [[ -print -{ - x = 1, -} -]] - -TEST [[ -local function x(a, b) - return a, b -end -x(1, 2, ) -]] - -TEST [[ -local function x(a, b, ...) - return a, b, ... -end -x(1, 2, 3, 4, 5) -]] - -TEST [[ ----@type fun(a, b, ...) -local x -x(1, 2, 3, 4, 5) -]] - -TEST [[ -local m = {} -function m:x(a, b) - return a, b -end -m:x(1, 2, ) -]] - -TEST [[ -local m = {} -function m:x(a, b) - return a, b -end -m.x(m, 2, 3, ) -]] - -TEST [[ -local m = {} -function m.x(a, b) - return a, b -end -m:x(1, , , ) -]] - TEST [[ local function x(a, b) return a, b @@ -329,8 +37,6 @@ x(1, 2) ]] TEST [[ ----@diagnostic disable: unused-local - ---@param a integer ---@param b integer local function f(a, b) @@ -340,8 +46,6 @@ f(...) ]] TEST [[ ----@diagnostic disable: unused-local - ---@param a integer ---@param b integer local function f(a, b) -- cgit v1.2.3 From 6fe0ea884f692a460cdf084c28900fc44dec0018 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Fri, 11 Aug 2023 16:28:47 +0800 Subject: cleanup tests --- test/diagnostics/common.lua | 443 -------------------------------------------- 1 file changed, 443 deletions(-) (limited to 'test/diagnostics/common.lua') diff --git a/test/diagnostics/common.lua b/test/diagnostics/common.lua index e0a3e342..24ec4c8c 100644 --- a/test/diagnostics/common.lua +++ b/test/diagnostics/common.lua @@ -1,455 +1,12 @@ local config = require 'config' local util = require 'utility' -TEST [[ -local function x(a, b) - return a, b -end -x(1) -]] - -TEST [[ ----@param a integer ----@param b integer -local function x(a, b) - return a, b -end - -]] - -TEST [[ ----@param a integer ----@param b integer -local function x(a, b) - return a, b -end - -]] - -TEST [[ ----@param a integer ----@param b integer ----@param ... integer -local function x(a, b, ...) - return a, b, ... -end -x(1, 2) -]] - -TEST [[ ----@param a integer ----@param b integer -local function f(a, b) -end - -f(...) -]] - -TEST [[ ----@param a integer ----@param b integer -local function f(a, b) -end - -local function return2Numbers() - return 1, 2 -end - -f(return2Numbers()) -]] - -TEST [[ ----@param a integer ----@param b? integer -local function x(a, b) - return a, b -end -x(1) -]] - -TEST [[ ----@param b integer? -local function x(a, b) - return a, b -end -x(1) -]] - -TEST [[ ----@param b integer|nil -local function x(a, b) - return a, b -end -x(1) -]] - -TEST [[ -local m = {} -function m.x() -end -m:x() -]] - -TEST [[ -InstanceName = 1 -Instance = _G[InstanceName] -]] - -TEST [[ -local _ = (''):sub(1, 2) -]] - -TEST [=[ -return [[ - -]] -]=] - -util.arrayInsert(disables, 'close-non-object') -TEST [[ -local _ = function () end -]] -util.arrayRemove(disables, 'close-non-object') - -TEST [[ -local _ = -]] - -TEST [[ -local _ = -]] - -TEST [[ -local c = -]] - -util.arrayInsert(disables, 'unused-local') -TEST [[ -local f = -]] - -TEST [[ -local f;f = -]] - -TEST [[ -local -]] - -TEST [[ -local -]] - - -TEST [[ -local - -local -]] - -util.arrayRemove(disables, 'unused-local') -TEST [[ -local mt, x -function mt:m() - function x:m() - end -end -return mt, x -]] - -TEST [[ -local mt = {} -function mt:f() -end -return mt -]] - -TEST [[ -local = {} -function :f() -end -]] - -TEST [[ -local = {} -.a = 1 -]] - -TEST [[ -local = {} -['a'] = 1 -]] - -TEST [[ -local function f() - return 'something' -end -f() -]] - -TEST [[ -local function f() - return 'something' -end -f() -]] - -TEST [[ -local function f(var) - print(var) -end -local var -f(var) -]] - -TEST [[ -local function f(a, b) - return a, b -end -f(1, 2, , ) -]] - -TEST [[ -local mt = {} -function mt:f(a, b) - return a, b -end -mt.f(mt, 2, 3, ) -]] - - -TEST [[ -local mt = {} -function mt.f(a, b) - return a, b -end -mt:f(1, , , ) -]] - -TEST [[ -local mt = {} -function mt:f(a, b) - return a, b -end -mt:f(1, 2, , ) -]] - -TEST [[ -local function f(a, b, ...) - return a, b, ... -end -f(1, 2, 3, 4) -]] - -TEST [[ -local _ = next({}, 1, ) -print(1, 2, 3, 4, 5) -]] - -TEST [[ -local function f(callback) - callback(1, 2, 3) -end -f(function () end) -]] - ---TEST [[ ---local realTostring = tostring ---tostring = function () end ---tostring() ---tostring = realTostring ---tostring(1) ---]] - -TEST [[ - = 1 -tostring = 1 -ROOT = 1 -_G.bb = 1 -]] - -TEST [[ -local f = load('') -if f then - f(1, 2, 3) -end -]] - -TEST [[ -local _ = -]] - -TEST [[ -X = table[] -]] - -TEST [[ -return { - = 1, - y = 2, - = 3, -} -]] -TEST [[ -return { - x = 1, - y = 2, -}, { - x = 1, - y = 2, -} -]] - -TEST [[ -local m = {} -function m.open() -end - -m:open() -]] - -TEST [[ -local m = {} -function m:open() -end -m.open(m) -]] -TEST [[ - -]] -TEST [[ - -]] -TEST [[ -if true then -else - return -end -]] -TEST [[ -while true do -end -]] - -TEST [[ - -]] - -TEST [[ - -]] - -TEST [[ -local _ = 1, -]] - -TEST [[ -_ = 1, -]] - -TEST [[ -function X() - do - local k - print(k) - end - local k = 1 - print(k) -end -]] - -TEST [[ -function X() - local loc - print(loc) -end -]] - -TEST [[ -local = {} -[1] = 1 -]] - -TEST [[ -T1 = 1 -_ENV.T2 = 1 -_G.T3 = 1 -_ENV._G.T4 = 1 -_G._G._G.T5 = 1 -rawset(_G, 'T6', 1) -rawset(_ENV, 'T7', 1) -print(T1) -print(T2) -print(T3) -print(T4) -print(T5) -print(T6) -print(T7) -]] - -TEST [[ -local x -x = -]] - -TEST [[ -local x, y -x = -]] - -TEST [[ -local x, y, z -x = x and y or '' .. z -]] - -TEST [[ -local x -x = x or -1 -]] - -TEST [[ -local x -x = x or (0 + 1) -]] - -TEST [[ -local x, y -x = (x + y) or 0 -]] - -TEST [[ -local t = {} -t.a = 1 -t.a = 2 -return t -]] - -TEST [[ -table.insert({}, 1, 2, ) -]] - -TEST [[ -while true do - break - -end -]] TEST [[ local x, , = 1 -- cgit v1.2.3 From cd370225fc4eaf6e2f6baadfb5a8501943c86783 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Fri, 11 Aug 2023 17:05:18 +0800 Subject: cleanup tests --- test/diagnostics/common.lua | 977 -------------------------------------------- 1 file changed, 977 deletions(-) (limited to 'test/diagnostics/common.lua') diff --git a/test/diagnostics/common.lua b/test/diagnostics/common.lua index 24ec4c8c..9352765f 100644 --- a/test/diagnostics/common.lua +++ b/test/diagnostics/common.lua @@ -1,982 +1,5 @@ -local config = require 'config' -local util = require 'utility' - - - - - - -TEST [[ -local x, , = 1 -print(x, y, z) -]] - -TEST [[ -local x, y, = 1, 2 -print(x, y, z) -]] - -TEST [[ -local x, y, z = print() -print(x, y, z) -]] - -TEST [[ -local x, y, z -print(x, y, z) -]] - -TEST [[ -local x, y, z -x, , = 1 -print(x, y, z) -]] - -TEST [[ -X, , = 1 -]] - -TEST [[ -T = {} -T.x, , = 1 -]] - -TEST [[ -T = {} -T['x'], , = 1 -]] - ---TEST [[ ------@class ------@class ---]] - -TEST [[ ----@alias integer ----@alias integer -]] - -TEST [[ ----@class A : -]] - -TEST [[ ----@class ----@class ----@class ----@class -]] - -TEST [[ ----@class A : B ----@class B : C ----@class C : D ----@class D -]] - -TEST [[ ----@type -]] - -TEST [[ ----@class A ----@type A|| -]] - -TEST [[ ----@class AAA ----@alias B AAA - ----@type B -]] - -TEST [[ ----@alias B -]] - -TEST [[ ----@class A ----@class B ----@alias B -]] - -TEST [[ ----@param -]] - -TEST [[ ----@class Class ----@param Class -local function f(x) - return x -end -f() -]] - -TEST [[ ----@class Class ----@param Class -function F(x) - return x -end -F() -]] - -TEST [[ ----@class Class ----@param Class ----@param y Class ----@param Class -local function f(x, y) - return x, y -end - -local _ -f(_, _) -]] - -TEST [[ ----@field ----@class Class -]] - -TEST [[ ----@class Class - ----@field -]] - -TEST [[ ----@class Class ---- ----@field x Class -]] - -TEST [[ ----@class Class ----@field Class ----@field Class -]] - -TEST [[ ----@class Class : any -]] - -TEST [[ ----@type fun(a: integer) -local f -f(1) -]] - -TEST [[ ----@class c -c = {} -]] - -TEST [[ ----@generic T: any ----@param v T ----@param message any ----@return T ----@return any message -function assert(v, message) - return v, message -end -]] - -TEST [[ ----@type string ----| -]] - -TEST [[ ----@type ----| 'xx' -]] - -TEST [[ ----@class class -local t -]] ----[==[ --- checkUndefinedField 通用 -TEST [[ ----@class Foo ----@field field1 integer -local mt = {} -function mt:Constructor() - self.field2 = 1 -end -function mt:method1() return 1 end -function mt.method2() return 2 end - ----@class Bar: Foo ----@field field4 integer -local mt2 = {} - ----@type Foo -local v -print(v.field1 + 1) -print(v.field2 + 1) -print(v. + 1) -print(v:method1()) -print(v.method2()) -print(v:()) - ----@type Bar -local v2 -print(v2.field1 + 1) -print(v2.field2 + 1) -print(v2. + 1) -print(v2.field4 + 1) -print(v2:method1()) -print(v2.method2()) -print(v2:()) - -local v3 = {} -print(v3.abc) - ----@class Bar2 -local mt3 -function mt3:method() return 1 end -print(mt3:method()) -]] - --- checkUndefinedField 通过type找到class -TEST [[ ----@class Foo -local Foo -function Foo:method1() end - ----@type Foo -local v -v:method1() -v:() -- doc.class.name -]] - --- checkUndefinedField 通过type找到class,涉及到 class 继承版 -TEST [[ ----@class Foo -local Foo -function Foo:method1() end ----@class Bar: Foo -local Bar -function Bar:method3() end - ----@type Bar -local v -v:method1() -v:() -- doc.class.name -v:method3() -]] - --- checkUndefinedField 类名和类变量同名,类变量被直接使用 -TEST [[ ----@class Foo -local Foo -function Foo:method1() end -Foo:() -- doc.class -Foo:() -- doc.class -]] - --- checkUndefinedField 没有@class的不检测 -TEST [[ -local Foo -function Foo:method1() - return Foo:method2() -- table -end -]] - --- checkUndefinedField 类名和类变量不同名,类变量被直接使用、使用self -TEST [[ ----@class Foo -local mt -function mt:method1() - mt.() -- doc.class - self:method1() - return self.() -- doc.class.name -end -]] - --- checkUndefinedField 当会推导成多个class类型时 -TEST [[ ----@class Foo -local mt -function mt:method1() end - ----@class Bar -local mt2 -function mt2:method2() end - ----@type Foo -local v ----@type Bar -local v2 - = v -v2:method1() -v2:() -]] - -TEST [[ ----@type table -T1 = {} -print(T1.f1) ----@type tablelib -T2 = {} -print(T2.) -]] ---]==] -TEST [[ ----@overload fun(...) -local function f() end - -f(1) -]] - -TEST [[ -for i = do - print(i) -end -]] - -TEST [[ -for i = do - print(i) -end -]] - -TEST [[ -for i = do - print(i) -end -]] - -TEST [[ -for i = do - print(i) -end -]] - -TEST [[ -for i = 1, 1 do - print(i) -end -]] - -TEST [[ -local m = {} - -function () -end - -function () -end - -return m -]] - -TEST [[ -local m = {} - -function () -end - -do - function () - end -end - -return m -]] - -TEST [[ -local m = {} - -m.x = true -m.x = false - -return m -]] - -TEST [[ -local m = {} - -m.x = io.open('') -m.x = nil - -return m -]] - -TEST [[ ----@meta - ----@class A ----@field a boolean - ----@return A -local function f() end - -local r = f() -r.x = 1 - -return r.x -]] - -TEST [[ ----@diagnostic disable-next-line -x = 1 -]] - -TEST [[ ----@diagnostic disable-next-line: lowercase-global -x = 1 -]] - -TEST [[ ----@diagnostic disable-next-line: unused-local - = 1 -]] - -TEST [[ ----@diagnostic disable -x = 1 -]] - -TEST [[ ----@diagnostic disable ----@diagnostic enable - = 1 -]] - -TEST [[ ----@diagnostic disable ----@diagnostic disable ----@diagnostic enable -x = 1 -]] - -TEST [[ ----@diagnostic disable-next-line: -]] - -TEST [[ -local mt = {} - -function mt:a(x) - return self, x -end - -function mt:b(y) - self:a(1):b(2) - return y -end - -return mt -]] - -TEST [[ -local function each() - return function () - end -end - -for x in each() do - print(x) -end -]] - -TEST [[ ----@type string -local s - -print(s:upper()) -]] - -TEST [[ -local t = (). -return t -]] - -TEST [[ -return { - [1] = 1, - ['1'] = 1, -} -]] - -TEST [[ -return { - [print()] = 1, - [print()] = 1, -} -]] - -TEST [[ ----@type { x: number, y: number} ----| "'resume'" -]] - -TEST [[ -return { - 1, , 3, - [] = 4, -} -]] - -TEST [[ ---- @class Emit ---- @field on fun(eventName: string, cb: function) ---- @field on fun(eventName: '"died"', cb: fun(i: integer)) ---- @field on fun(eventName: '"won"', cb: fun(s: string)) -local emit = {} -]] - -TEST [[ ---- @class Emit ---- @field on fun(eventName: string, cb: function) ---- @field fun(eventName: '"died"', cb: fun(i: integer)) ---- @field on fun(eventName: '"won"', cb: fun(s: string)) ---- @field fun(eventName: '"died"', cb: fun(i: integer)) -local emit = {} -]] - --- redundant-return -TEST [[ -local function f() - -end -f() -]] - -TEST [[ -local function f() - return nil -end -f() -]] - -TEST [[ -local function f() - local function x() - - end - x() - return true -end -f() -]] - -TEST [[ -local function f() - local function x() - return true - end - return x() -end -f() -]] - -TEST [[ ----@type file* -local f -local _ = f:read '*a' -local _ = f:read('*a') -]] - -TEST [[ -function F() - () -end -]] - -TEST [[ ----@async -function F() - coroutine.yield() -end -]] - -TEST [[ ----@type async fun() -local f - -function F() - () -end -]] - -TEST [[ ----@type async fun() -local f - ----@async -function F() - f() -end -]] - -TEST [[ -local function f(cb) - cb() -end - -return function() - (function () ---@async - return nil - end) -end -]] - -TEST [[ -local function f(cb) - pcall(cb) -end - -return function() - (function () ---@async - return nil - end) -end -]] - -TEST [[ ----@param c any -local function f(c) - return c -end - -return function () - f(function () ---@async - return nil - end) -end -]] - -TEST [[ ----@param ... any -local function f(...) - return ... -end - -return function () - f(function () ---@async - return nil - end) -end -]] - -TEST [[ ----@vararg any -local function f(...) - return ... -end - -return function () - f(function () ---@async - return nil - end) -end -]] - -TEST [[ -local function f(...) - return ... -end - -return function () - f(function () ---@async - return nil - end) -end -]] - -TEST [[ -local function f(...) - return ... -end - -return function () - f(function () ---@async - return nil - end) -end -]] - -TEST [[ ----@nodiscard -local function f() - return 1 -end - - -]] - -TEST [[ ----@nodiscard -local function f() - return 1 -end - -X = f() -]] - -config.get(nil, 'Lua.diagnostics.neededFileStatus')['not-yieldable'] = 'Any' -TEST [[ ----@param cb fun() -local function f(cb) - return cb -end - ----@async -local function af() - return nil -end - -f() -]] - -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 - -local function af() - (function () ---@async - return nil - end) -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) -]] - -TEST [[ ----@param ... number -local function f(...) - return ... -end - -return f -]] - -TEST [[ ----@type fun(...: string) -]] - -TEST [[ ----@type fun(xxx, yyy, ...): boolean -]] - -TEST [[ -local - -return { - x = 1, -} -]] - -TEST [[ ----@class A #1 -]] - -TEST [[ ----@class A 1 -]] - -TEST [[ -return ('1'):upper() -]] - -TEST [[ -local value -value = '1' -value = value:upper() -]] - -TEST [[ -T = {} ----@deprecated # comment -T.x = 1 - -print() -]] - -TEST [[ -T = {} - ----@deprecated -function T:ff() -end - -() -]] - -TEST [[ ----@type string? -local x - -S = :upper() -]] - -TEST [[ ----@type string? -local x - -if x then - S = x:upper() -end -]] - -TEST [[ ----@type string? -local x - -if not x then - x = '' -end - -S = x:upper() -]] - -TEST [[ ----@type fun()? -local x - -S = () -]] - -TEST [[ ----@type integer? -local x - -T = {} -T[] = 1 -]] - -TEST [[ -local x, y -local z = x and y - -print(z.y) -]] - -TEST [[ -local x, y -function x() - y() -end - -function y() - x() -end - -x() -]] - -TEST [[ ----@meta - ----@param x fun() -local function f1(x) -end - ----@return fun() -local function f2() -end - -f1(f2()) -]] - -TEST [[ ----@meta - ----@type fun():integer -local f - ----@param x integer -local function foo(x) end - -foo(f()) -]] - -TEST [[ ----@type string|table -local n - -print(n.x) -]] - -TEST [[ ----@diagnostic disable: unused-local, unused-function, undefined-global - -function F() end - ----@param x boolean -function F(x) end - -F(k()) -]] - -TEST [[ -local function f() - return 1, 2, 3 -end - -local function k() -end - -k() -]] - -TEST [[ ----@diagnostic disable: unused-local -local function f() - return 1, 2, 3 -end - ----@param x integer -local function k(x) -end - -k(f()) -]] - TEST [[ ---@cast integer ]] -- cgit v1.2.3 From 5e5a1b2ebb103625bbbb686ab31abc11a78e9d73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Fri, 11 Aug 2023 17:57:22 +0800 Subject: cleanup tests --- test/diagnostics/common.lua | 756 -------------------------------------------- 1 file changed, 756 deletions(-) delete mode 100644 test/diagnostics/common.lua (limited to 'test/diagnostics/common.lua') 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 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 ----@field [] 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 - - -]] - -TEST [[ ----@meta - -return function f(x, y, z) end -]] - -util.arrayInsert(disables, 'redundant-return') -TEST [[ ----@return number -function F() - -end -]] - -TEST [[ ----@return number, number -function F() - 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, -end -]] - -TEST [[ ----@return number, number? -function F() - return 1, 1, , , -end -]] - -TEST [[ ----@meta - ----@return number, number -local function r2() end - ----@return number, number? -function F() - return 1, -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 : A -]] - -config.add(nil, 'Lua.diagnostics.unusedLocalExclude', 'll_*') - -TEST [[ -local -local ll_1 -local ll_2 -local -]] - -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 - -]] - -TEST [[ ----@diagnostic disable: undefined-global - -function X() - if X then - return false - elseif X then - return false - else - return false - end - -end -]] - -TEST [[ -while true do -end - - -]] - -TEST [[ -while true do -end - - -]] - -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 _ = 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.) -]] - -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.) -]] - -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.) - ----@class B: A -local t2 - -print(t2.) -]] -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.) - ----@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 () end - -function () 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 = -]] - -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, - 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 -]] - -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, - 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, -} -]] -- cgit v1.2.3