diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-11-20 21:57:09 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-11-20 21:57:09 +0800 |
commit | 4ca61ec457822dd14966afa0752340ae8ce180a1 (patch) | |
tree | ae8adb1ad82c717868e551e699fd3cf3bb290089 /test/signature | |
parent | c63b2e404d8d2bb984afe3678a5ba2b2836380cc (diff) | |
download | lua-language-server-4ca61ec457822dd14966afa0752340ae8ce180a1.zip |
no longer beta
Diffstat (limited to 'test/signature')
-rw-r--r-- | test/signature/init.lua | 162 |
1 files changed, 162 insertions, 0 deletions
diff --git a/test/signature/init.lua b/test/signature/init.lua new file mode 100644 index 00000000..f06f8193 --- /dev/null +++ b/test/signature/init.lua @@ -0,0 +1,162 @@ +local core = require 'core.signature' +local files = require 'files' + +rawset(_G, 'TEST', true) + +function TEST(script) + return function (expect) + local pos = script:find('$', 1, true) - 1 + local new_script = script:gsub('%$', '') + files.removeAll() + files.setText('', new_script) + local hovers = core('', pos) + 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]) + else + assert(expect == nil) + end + end +end + +TEST [[ +local function x(a, b) +end + +x($ +]] +{ + label = "function x(a: any, b: any)", + arg = {12, 17}, +} + +TEST [[ +local function x(a, b) +end + +x($) +]] +{ + label = "function x(a: any, b: any)", + arg = {12, 17}, +} + +TEST [[ +local function x(a, b) +end + +x(xxx$) +]] +{ + label = "function x(a: any, b: any)", + arg = {12, 17}, +} + +TEST [[ +local function x(a, b) +end + +x(xxx, $) +]] +{ + label = "function x(a: any, b: any)", + arg = {20, 25}, +} + +TEST [[ +function mt:f(a) +end + +mt:f($ +]] +{ + label = 'function mt:f(a: any)', + arg = {15, 20}, +} + +TEST [[ +local function x(a, b) + return 1 +end + +x($ +]] +{ + label = "function x(a: any, b: any)", + arg = {12, 17}, +} + +TEST [[ +local function x(a, ...) + return 1 +end + +x(1, 2, 3, $ +]] +{ + label = "function x(a: any, ...)", + arg = {20, 22}, +} + +TEST [[ +(''):sub($ +]] +{ + label = [[ +function string:sub(i: integer, j?: integer) +]], + arg = {21, 30}, +} + +TEST [[ +(''):sub(1)$ +]] +(nil) + +TEST [[ +local function f(a, b, c) +end + +f(1, 'string$') +]] +{ + label = [[ +function f(a: any, b: any, c: any) +]], + arg = {20, 25}, +} + +TEST [[ +pcall(function () $ end) +]] +(nil) + +TEST [[ +table.unpack {$} +]] +(nil) + +TEST [[ +---@type fun(x: number, y: number):boolean +local zzzz +zzzz($) +]] +{ + label = [[ +function zzzz(x: number, y: number) +]], + arg = {15, 23}, +} + +TEST [[ +('abc'):format(f($)) +]] +(nil) |