From c608e84003aed61a16484296edad3fe4ff363322 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Wed, 22 Sep 2021 21:50:50 +0800 Subject: update --- test/signature/init.lua | 193 ++++++++++++++---------------------------------- 1 file changed, 55 insertions(+), 138 deletions(-) (limited to 'test/signature') 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(, b: any)' TEST [[ local function x(a, b) end -x($) +x() ]] -{ - label = "function x(a: any, b: any)", - arg = {12, 17}, -} +'function x(, 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(, 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, )' TEST [[ function mt:f(a) end -mt:f($ +mt:f( ]] -{ - label = 'function mt:f(a: any)', - arg = {15, 20}, -} +'function mt:f()' TEST [[ local function x(a, b) return 1 end -x($ +x( ]] -{ - label = "function x(a: any, b: any)", - arg = {12, 17}, -} +'function x(, 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(, 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, , 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(, 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(, 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, )' 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, , c: any)' TEST [[ -for _ in pairs($) do +for _ in pairs() do end ]] -{ - label = [[ -function pairs(t: ) -]], - arg = {16, 21}, -} +'function pairs(!>)' TEST [[ function m:f() end -m.f($) +m.f() ]] -{ - label = [[ -function m.f(self: table) -]], - arg = {14, 24}, -} +'function m.f()' TEST [[ ---@alias nnn table @@ -234,59 +172,41 @@ TEST [[ ---@param x nnn local function f(x, y, z) end -f($) +f() ]] -{ - label = [[ -function f(x: table, y: any, z: any) -]], - arg = {12, 35}, -} - +'function f(!>, 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(, 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(, 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, )' 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, )' 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, )' -- cgit v1.2.3