diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-09-22 21:50:50 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-09-22 21:50:50 +0800 |
commit | c608e84003aed61a16484296edad3fe4ff363322 (patch) | |
tree | 5b1c7fd404dde785973ea6fa56e80fa0f990aa73 /test/signature | |
parent | 087a93d3df198aef7f0b7fb5a5af34b09fa630a9 (diff) | |
download | lua-language-server-c608e84003aed61a16484296edad3fe4ff363322.zip |
update
Diffstat (limited to 'test/signature')
-rw-r--r-- | test/signature/init.lua | 193 |
1 files changed, 55 insertions, 138 deletions
diff --git a/test/signature/init.lua b/test/signature/init.lua index 27051310..43bce29e 100644 --- a/test/signature/init.lua +++ b/test/signature/init.lua @@ -1,26 +1,25 @@ -local core = require 'core.signature' +local core = require 'core.signature' local files = require 'files' +local catch = require 'catch' rawset(_G, 'TEST', true) function TEST(script) return function (expect) - local pos = script:find('$', 1, true) - 1 - local new_script = script:gsub('%$', '') + local newScript, catched1 = catch(script, '?') + local newExpect, catched2 = catch(expect or '', '!') files.removeAll() - files.setText('', new_script) - local hovers = core('', pos) + files.setText('', newScript) + local hovers = core('', catched1['?'][1][1]) if hovers then assert(expect) local hover = hovers[#hovers] - local label = hover.label:gsub('^[\r\n]*(.-)[\r\n]*$', '%1'):gsub('\r\n', '\n') - expect.label = expect.label:gsub('^[\r\n]*(.-)[\r\n]*$', '%1'):gsub('\r\n', '\n') local arg = hover.params[hover.index].label - assert(expect.label == label) - assert(expect.arg[1] == arg[1]) - assert(expect.arg[2] == arg[2]) + assert(newExpect == hover.label) + assert(catched2['!'][1][1] == arg[1]) + assert(catched2['!'][1][2] == arg[2]) else assert(expect == nil) end @@ -31,93 +30,67 @@ TEST [[ local function x(a, b) end -x($ +x(<??> ]] -{ - label = "function x(a: any, b: any)", - arg = {12, 17}, -} +'function x(<!a: any!>, b: any)' TEST [[ local function x(a, b) end -x($) +x(<??>) ]] -{ - label = "function x(a: any, b: any)", - arg = {12, 17}, -} +'function x(<!a: any!>, b: any)' TEST [[ local function x(a, b) end -x(xxx$) +x(xxx<??>) ]] -{ - label = "function x(a: any, b: any)", - arg = {12, 17}, -} +'function x(<!a: any!>, b: any)' TEST [[ local function x(a, b) end -x(xxx, $) +x(xxx, <??>) ]] -{ - label = "function x(a: any, b: any)", - arg = {20, 25}, -} +'function x(a: any, <!b: any!>)' TEST [[ function mt:f(a) end -mt:f($ +mt:f(<??> ]] -{ - label = 'function mt:f(a: any)', - arg = {15, 20}, -} +'function mt:f(<!a: any!>)' TEST [[ local function x(a, b) return 1 end -x($ +x(<??> ]] -{ - label = "function x(a: any, b: any)", - arg = {12, 17}, -} +'function x(<!a: any!>, b: any)' TEST [[ local function x(a, ...) return 1 end -x(1, 2, 3, $ +x(1, 2, 3, <??> ]] -{ - label = "function x(a: any, ...)", - arg = {20, 22}, -} +'function x(a: any, <!...!>)' TEST [[ -(''):sub($ +(''):sub(<??> ]] -{ - label = [[ -function string:sub(i: integer, j?: integer) -]], - arg = {21, 30}, -} +'function string:sub(<!i: integer!>, j?: integer)' TEST [[ -(''):sub(1)$ +(''):sub(1)<??> ]] (nil) @@ -125,39 +98,29 @@ TEST [[ local function f(a, b, c) end -f(1, 'string$') +f(1, 'string<??>') ]] -{ - label = [[ -function f(a: any, b: any, c: any) -]], - arg = {20, 25}, -} +'function f(a: any, <!b: any!>, c: any)' TEST [[ -pcall(function () $ end) +pcall(function () <??> end) ]] (nil) TEST [[ -table.unpack {$} +table.unpack {<??>} ]] (nil) TEST [[ ---@type fun(x: number, y: number):boolean local zzzz -zzzz($) +zzzz(<??>) ]] -{ - label = [[ -function zzzz(x: number, y: number) -]], - arg = {15, 23}, -} +'function zzzz(<!x: number!>, y: number)' TEST [[ -('abc'):format(f($)) +('abc'):format(f(<??>)) ]] (nil) @@ -166,14 +129,9 @@ function Foo(param01, param02) end -Foo($) +Foo(<??>) ]] -{ - label = [[ -function Foo(param01: any, param02: any) -]], - arg = {14, 25}, -} +'function Foo(<!param01: any!>, param02: any)' TEST [[ function f1(a, b) @@ -182,51 +140,31 @@ end function f2(c, d) end -f2(f1(),$) +f2(f1(),<??>) ]] -{ - label = [[ -function f2(c: any, d: any) -]], - arg = {21, 26}, -} +'function f2(c: any, <!d: any!>)' TEST [[ local function f(a, b, c) end -f({},$) +f({},<??>) ]] -{ - label = [[ -function f(a: any, b: any, c: any) -]], - arg = {20, 25}, -} +'function f(a: any, <!b: any!>, c: any)' TEST [[ -for _ in pairs($) do +for _ in pairs(<??>) do end ]] -{ - label = [[ -function pairs(t: <T>) -]], - arg = {16, 21}, -} +'function pairs(<!t: <T>!>)' TEST [[ function m:f() end -m.f($) +m.f(<??>) ]] -{ - label = [[ -function m.f(self: table) -]], - arg = {14, 24}, -} +'function m.f(<!self: table!>)' TEST [[ ---@alias nnn table<number, string> @@ -234,59 +172,41 @@ TEST [[ ---@param x nnn local function f(x, y, z) end -f($) +f(<??>) ]] -{ - label = [[ -function f(x: table<number, string>, y: any, z: any) -]], - arg = {12, 35}, -} - +'function f(<!x: table<number, string>!>, y: any, z: any)' TEST [[ local function x(a, b) end -x( aaaa $, 2) +x( aaaa <??>, 2) ]] -{ - label = "function x(a: any, b: any)", - arg = {12, 17}, -} +"function x(<!a: any!>, b: any)" TEST [[ local function x(a, b) end -x($ aaaa , 2) +x(<??> aaaa , 2) ]] -{ - label = "function x(a: any, b: any)", - arg = {12, 17}, -} +'function x(<!a: any!>, b: any)' TEST [[ local function x(a, b) end -x(aaaa ,$ 2) +x(aaaa ,<??> 2) ]] -{ - label = "function x(a: any, b: any)", - arg = {20, 25}, -} +'function x(a: any, <!b: any!>)' TEST [[ local function x(a, b) end -x(aaaa , 2 $) +x(aaaa , 2 <??>) ]] -{ - label = "function x(a: any, b: any)", - arg = {20, 25}, -} +'function x(a: any, <!b: any!>)' TEST [[ local fooC @@ -298,9 +218,6 @@ function fooC(callback, par) end fooC(function (x, s) -end,$) +end,<??>) ]] -{ - label = 'function fooC(callback: fun(x: number, s: string):nil, par: number)', - arg = {56, 66}, -} +'function fooC(callback: fun(x: number, s: string):nil, <!par: number!>)' |