diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/completion/common.lua | 26 | ||||
-rw-r--r-- | test/diagnostics/missing-fields.lua | 122 | ||||
-rw-r--r-- | test/type_formatting/init.lua | 209 | ||||
-rw-r--r-- | test/type_inference/common.lua | 236 | ||||
-rw-r--r-- | test/type_inference/param_match.lua | 24 |
5 files changed, 395 insertions, 222 deletions
diff --git a/test/completion/common.lua b/test/completion/common.lua index ec2372a0..30350642 100644 --- a/test/completion/common.lua +++ b/test/completion/common.lua @@ -3235,7 +3235,7 @@ xx@pcall<??> { [1] = { label = 'pcall', - kind = define.CompletionItemKind.Event, + kind = define.CompletionItemKind.Snippet, textEdit = { start = 3, finish = 8, @@ -3257,7 +3257,7 @@ xx()@pcall<??> { [1] = { label = 'pcall', - kind = define.CompletionItemKind.Event, + kind = define.CompletionItemKind.Snippet, textEdit = { start = 5, finish = 10, @@ -3279,7 +3279,7 @@ xx(1, 2, 3)@pcall<??> { [1] = { label = 'pcall', - kind = define.CompletionItemKind.Event, + kind = define.CompletionItemKind.Snippet, textEdit = { start = 12, finish = 17, @@ -3301,7 +3301,7 @@ xx@xpcall<??> { [1] = { label = 'xpcall', - kind = define.CompletionItemKind.Event, + kind = define.CompletionItemKind.Snippet, textEdit = { start = 3, finish = 9, @@ -3323,7 +3323,7 @@ xx()@xpcall<??> { [1] = { label = 'xpcall', - kind = define.CompletionItemKind.Event, + kind = define.CompletionItemKind.Snippet, textEdit = { start = 5, finish = 11, @@ -3345,7 +3345,7 @@ xx(1, 2, 3)@xpcall<??> { [1] = { label = 'xpcall', - kind = define.CompletionItemKind.Event, + kind = define.CompletionItemKind.Snippet, textEdit = { start = 12, finish = 18, @@ -3367,7 +3367,7 @@ xx@function<??> { [1] = { label = 'function', - kind = define.CompletionItemKind.Event, + kind = define.CompletionItemKind.Snippet, textEdit = { start = 3, finish = 11, @@ -3389,7 +3389,7 @@ xx.yy@method<??> { [1] = { label = 'method', - kind = define.CompletionItemKind.Event, + kind = define.CompletionItemKind.Snippet, textEdit = { start = 6, finish = 12, @@ -3411,7 +3411,7 @@ xx:yy@method<??> { [1] = { label = 'method', - kind = define.CompletionItemKind.Event, + kind = define.CompletionItemKind.Snippet, textEdit = { start = 6, finish = 12, @@ -3433,7 +3433,7 @@ xx@insert<??> { [1] = { label = 'insert', - kind = define.CompletionItemKind.Event, + kind = define.CompletionItemKind.Snippet, textEdit = { start = 3, finish = 9, @@ -3455,7 +3455,7 @@ xx++<??> { [1] = { label = '++', - kind = define.CompletionItemKind.Event, + kind = define.CompletionItemKind.Snippet, textEdit = { start = 2, finish = 4, @@ -3471,7 +3471,7 @@ xx++<??> }, [2] = { label = '++?', - kind = define.CompletionItemKind.Event, + kind = define.CompletionItemKind.Snippet, textEdit = { start = 2, finish = 4, @@ -3495,7 +3495,7 @@ end) { [1] = { label = 'xpcall', - kind = define.CompletionItemKind.Event, + kind = define.CompletionItemKind.Snippet, textEdit = { start = 10007, finish = 10013, diff --git a/test/diagnostics/missing-fields.lua b/test/diagnostics/missing-fields.lua index ab87f81d..8c1ffbbb 100644 --- a/test/diagnostics/missing-fields.lua +++ b/test/diagnostics/missing-fields.lua @@ -231,3 +231,125 @@ local t = { y = 1, } ]] + +TEST [[ +---@diagnostic disable: unused-local + +---@class Foo +---@field a number +---@field b number +---@field c number + +---@class Foo + +---@class Bar +---@field ba number +---@field bb number +---@field bc number + +---@class Bar +---@field bd number + +---@type Foo|Bar +local x = { + ba = 1, + bb = 2, + bc = 3, + bd = 4, +} +]] + +TEST [[ +---@diagnostic disable: unused-local + +---@class Foo +---@field a number +---@field b number +---@field c number + +---@class Foo + +---@class Bar +---@field ba number +---@field bb number +---@field bc number + +---@class Bar +---@field bd number + +---@type Foo|Bar +local x = { + a = 1, + b = 2, + c = 3, +} +]] + +TEST [[ +---@diagnostic disable: unused-local + +---@class Foo +---@field a number +---@field b number +---@field c number + +---@class Foo + +---@class Bar +---@field ba number +---@field bb number +---@field bc number + +---@class Bar +---@field bd number + +---@type Foo|Bar +local x = <!{ + a = 1, + b = 2, +}!> +]] + +TEST [[ +---@diagnostic disable: unused-local + +---@class Foo +---@field a number +---@field b number +---@field c number + +---@class Foo + +---@class Bar +---@field ba number +---@field bb number +---@field bc number + +---@class Bar +---@field bd number + +---@type Foo|Bar +local x = <!{ + ba = 1, + bb = 2, + bd = 4, +}!> +]] + +TEST[[ +---@class A +---@field [1] string +---@field x number + +---@type A +local t = {x = 1, ""} +]] + +TEST[[ +---@class A +---@field [1] string +---@field x number + +---@type A +local t = <!{x = 1}!> +]]
\ No newline at end of file diff --git a/test/type_formatting/init.lua b/test/type_formatting/init.lua deleted file mode 100644 index 4e9ce556..00000000 --- a/test/type_formatting/init.lua +++ /dev/null @@ -1,209 +0,0 @@ -local core = require 'core.type-formatting' -local files = require 'files' -local util = require 'utility' -local catch = require 'catch' - -rawset(_G, 'TEST', true) - -function TEST(script) - return function(expect) - local newScript, catched = catch(script, '?') - files.setText(TESTURI, newScript) - local edits = core(TESTURI, catched['?'][1][1], expect.ch) - if edits then - assert(expect.edits) - assert(util.equal(edits, expect.edits)) - else - assert(expect.edits == nil) - end - files.remove(TESTURI) - end -end - -TEST [[ -if true then <??> end -]] -{ - ch = '\n', - edits = { - { - start = 12, - finish = 13, - text = '\n\t', - }, - { - start = 13, - finish = 15, - text = '', - }, - { - start = 15, - finish = 15, - text = '\ne', - }, - } -} - -TEST [[ -if true then <??>end -]] -{ - ch = '\n', - edits = { - { - start = 12, - finish = 13, - text = '\n\t', - }, - { - start = 13, - finish = 14, - text = '', - }, - { - start = 14, - finish = 14, - text = '\ne', - }, - } -} - -TEST [[ -if true then<??>end -]] -{ - ch = '\n', - edits = { - { - start = 12, - finish = 12, - text = '\n\t', - }, - { - start = 12, - finish = 13, - text = '', - }, - { - start = 13, - finish = 13, - text = '\ne', - }, - } -} - -TEST [[ - if true then<??>end -]] -{ - ch = '\n', - edits = { - { - start = 16, - finish = 16, - text = '\n \t', - }, - { - start = 16, - finish = 17, - text = '', - }, - { - start = 17, - finish = 17, - text = '\n e', - }, - } -} - -TEST [[ -local x = 1 -<??> -]] -{ - ch = '\n', - edits = nil, -} - -TEST [[ -local x = 'if 1 then' - <??> -]] -{ - ch = '\n', - edits = { - { - start = 10000, - finish = 10004, - text = '', - } - } -} - -TEST [[ -local x = 'do' - <??> -]] -{ - ch = '\n', - edits = { - { - start = 10000, - finish = 10004, - text = '', - } - } -} - -TEST [[ -local x = 'function' - <??> -]] -{ - ch = '\n', - edits = { - { - start = 10000, - finish = 10004, - text = '', - } - } -} - -TEST [[ -do - <??> -]] -{ - ch = '\n', - edits = nil -} - -TEST [[ -do - <??> -end -]] -{ - ch = '\n', - edits = nil -} - -TEST [[ -function () - <??> -]] -{ - ch = '\n', - edits = nil -} - -TEST [[ -function () - <??> -end -]] -{ - ch = '\n', - edits = nil -} diff --git a/test/type_inference/common.lua b/test/type_inference/common.lua index 5922832b..5fcec805 100644 --- a/test/type_inference/common.lua +++ b/test/type_inference/common.lua @@ -4192,3 +4192,239 @@ TEST 'boolean|number' [[ ---@type A local <?x?> ]] + +--reverse binary operator tests + +TEST 'A' [[ +---@class A +---@operator add(number): A + +---@type A +local x +local <?y?> = x + 1 +]] + +TEST 'A' [[ +---@class A +---@operator add(number): A + +---@type A +local x +local <?y?> = 1 + x +]] + +TEST 'A' [[ +---@class A +---@operator sub(number): A + +---@type A +local x +local <?y?> = x - 1 +]] + +TEST 'A' [[ +---@class A +---@operator sub(number): A + +---@type A +local x +local <?y?> = 1 - x +]] + +TEST 'A' [[ +---@class A +---@operator mul(number): A + +---@type A +local x +local <?y?> = x * 1 +]] + +TEST 'A' [[ +---@class A +---@operator mul(number): A + +---@type A +local x +local <?y?> = 1 * x +]] + +TEST 'A' [[ +---@class A +---@operator div(number): A + +---@type A +local x +local <?y?> = x / 1 +]] + +TEST 'A' [[ +---@class A +---@operator div(number): A + +---@type A +local x +local <?y?> = 1 / x +]] + +TEST 'A' [[ +---@class A +---@operator idiv(number): A + +---@type A +local x +local <?y?> = x // 1 +]] + +TEST 'A' [[ +---@class A +---@operator idiv(number): A + +---@type A +local x +local <?y?> = 1 // x +]] + +TEST 'A' [[ +---@class A +---@operator mod(number): A + +---@type A +local x +local <?y?> = x % 1 +]] + +TEST 'A' [[ +---@class A +---@operator mod(number): A + +---@type A +local x +local <?y?> = 1 % x +]] + +TEST 'A' [[ +---@class A +---@operator pow(number): A + +---@type A +local x +local <?y?> = x ^ 1 +]] + +TEST 'A' [[ +---@class A +---@operator pow(number): A + +---@type A +local x +local <?y?> = 1 ^ x +]] + +TEST 'A' [[ +---@class A +---@operator concat(number): A + +---@type A +local x +local <?y?> = x .. 1 +]] + +TEST 'A' [[ +---@class A +---@operator concat(number): A + +---@type A +local x +local <?y?> = 1 .. x +]] + +TEST 'A' [[ +---@class A +---@operator band(number): A + +---@type A +local x +local <?y?> = x & 1 +]] + +TEST 'A' [[ +---@class A +---@operator band(number): A + +---@type A +local x +local <?y?> = 1 & x +]] + +TEST 'A' [[ +---@class A +---@operator bor(number): A + +---@type A +local x +local <?y?> = x | 1 +]] + +TEST 'A' [[ +---@class A +---@operator bor(number): A + +---@type A +local x +local <?y?> = 1 | x +]] + +TEST 'A' [[ +---@class A +---@operator bxor(number): A + +---@type A +local x +local <?y?> = x ~ 1 +]] + +TEST 'A' [[ +---@class A +---@operator bxor(number): A + +---@type A +local x +local <?y?> = 1 ~ x +]] + +TEST 'A' [[ +---@class A +---@operator shl(number): A + +---@type A +local x +local <?y?> = x << 1 +]] + +TEST 'A' [[ +---@class A +---@operator shl(number): A + +---@type A +local x +local <?y?> = 1 << x +]] + +TEST 'A' [[ +---@class A +---@operator shr(number): A + +---@type A +local x +local <?y?> = x >> 1 +]] + +TEST 'A' [[ +---@class A +---@operator shr(number): A + +---@type A +local x +local <?y?> = 1 >> x +]] diff --git a/test/type_inference/param_match.lua b/test/type_inference/param_match.lua index 8ead05ef..1079e433 100644 --- a/test/type_inference/param_match.lua +++ b/test/type_inference/param_match.lua @@ -137,3 +137,27 @@ local function f(...) end local <?r?> = f(10) ]] + +TEST 'number' [[ +---@overload fun(a: 1, c: fun(x: number)) +---@overload fun(a: 2, c: fun(x: string)) +local function f(...) end + +f(1, function (<?a?>) end) +]] + +TEST 'string' [[ +---@overload fun(a: 1, c: fun(x: number)) +---@overload fun(a: 2, c: fun(x: string)) +local function f(...) end + +f(2, function (<?a?>) end) +]] + +TEST 'any' [[ +---@overload fun(a: 1) +---@overload fun(a: 2) +local function f(...) end + +f(1, function (<?a?>) end) +]] |