summaryrefslogtreecommitdiff
path: root/server/test/signature/init.lua
blob: 4110c585c7518c341a201d8cd12ec4a2331930fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
local parser = require 'parser'
local core = require 'core'

rawset(_G, 'TEST', true)

function TEST(script)
    return function (expect)
        local pos = script:find('@', 1, true)
        local new_script = script:gsub('@', '')
        local ast = parser:ast(new_script)
        local vm = core.vm(ast)
        assert(vm)
        local hovers = core.signature(vm, pos)
        if hovers then
            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.argLabel

            assert(expect.label == label)
            assert(expect.arg == arg)
        else
            assert(expect == nil)
        end
    end
end

TEST [[
local function x(a, b)
end

x(@
]]
{
    label = "function x(a: any, b: any)",
    arg = 'a: any'
}

TEST [[
local function x(a, b)
end

x(@)
]]
{
    label = "function x(a: any, b: any)",
    arg = 'a: any'
}

TEST [[
function mt:f(a)
end

mt:f(@
]]
{
    label = 'function mt:f(a: any)',
    arg = 'a: any'
}

TEST [[
(''):sub(@
]]
{
    label = [[
function *string:sub(i: integer [, j: integer(-1)])
  -> string
]],
    arg = 'i: integer'
}

TEST [[
(''):sub(1)@
]]
(nil)