diff options
author | NeOzay <colpaert.benoit@gmail.com> | 2024-07-28 22:29:32 +0200 |
---|---|---|
committer | NeOzay <colpaert.benoit@gmail.com> | 2024-07-28 22:29:32 +0200 |
commit | b7c5809d6c5b08f295e60c5e53ee8d8e1074667c (patch) | |
tree | 505f874d593657f683ce91313162fee7f429eabf | |
parent | 6cd10388ab56fed330706f90628b44c77d778310 (diff) | |
download | lua-language-server-b7c5809d6c5b08f295e60c5e53ee8d8e1074667c.zip |
add test
-rw-r--r-- | test/diagnostics/cast-local-type.lua | 66 | ||||
-rw-r--r-- | test/diagnostics/param-type-mismatch.lua | 84 |
2 files changed, 150 insertions, 0 deletions
diff --git a/test/diagnostics/cast-local-type.lua b/test/diagnostics/cast-local-type.lua index f79bf48d..93452a92 100644 --- a/test/diagnostics/cast-local-type.lua +++ b/test/diagnostics/cast-local-type.lua @@ -332,3 +332,69 @@ local x - 类型 `nil` 无法匹配 `'B'` - 类型 `nil` 无法匹配 `'A'`]]) end) + +TEST [[ +---@class A +---@field x string +---@field y number + +local a = {x = "", y = 0} + +---@type A +local v +v = a +]] + +TEST [[ +---@class A +---@field x string +---@field y number + +local a = {x = ""} + +---@type A +local v +<!v!> = a +]] + +TEST [[ +---@class A +---@field x string +---@field y number + +local a = {x = "", y = ""} + +---@type A +local v +<!v!> = a +]] + +TEST [[ +---@class A +---@field x string +---@field y? B + +---@class B +---@field x string + +local a = {x = "b", y = {x = "c"}} + +---@type A +local v +v = a +]] + +TEST [[ +---@class A +---@field x string +---@field y B + +---@class B +---@field x string + +local a = {x = "b", y = {}} + +---@type A +local v +<!v!> = a +]] diff --git a/test/diagnostics/param-type-mismatch.lua b/test/diagnostics/param-type-mismatch.lua index b11068db..bb602cab 100644 --- a/test/diagnostics/param-type-mismatch.lua +++ b/test/diagnostics/param-type-mismatch.lua @@ -264,3 +264,87 @@ local function f(v) end f 'x' f 'y' ]] + +TEST [[ +---@class A +---@field x string +---@field y number + +local a = {x = "", y = 0} + +---@param a A +function f(a) end + +f(a) +]] + +TEST [[ +---@class A +---@field x string +---@field y number + +local a = {x = ""} + +---@param a A +function f(a) end + +f(<!a!>) +]] + +TEST [[ +---@class A +---@field x string +---@field y number + +local a = {x = "", y = ""} + +---@param a A +function f(a) end + +f(<!a!>) +]] + +TEST [[ +---@class A +---@field x string +---@field y? B + +---@class B +---@field x string + +local a = {x = "b", y = {x = "c"}} + +---@param a A +function f(a) end + +f(a) +]] + +TEST [[ +---@class A +---@field x string +---@field y B + +---@class B +---@field x string + +local a = {x = "b", y = {}} + +---@param a A +function f(a) end + +f(<!a!>) +]] + +TEST [[ +---@class A +---@field x string + +---@type A +local a = {} + +---@param a A +function f(a) end + +f(a) +]]
\ No newline at end of file |