summaryrefslogtreecommitdiff
path: root/server/test/signature/init.lua
blob: 0c343384e6f6fb414bd10e815756500d97c35af6 (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
local parser = require 'parser'
local matcher = require 'matcher'

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 = matcher.vm(ast)
        assert(vm)
        local hovers = matcher.signature(vm, pos)
        assert(hovers)
        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)
    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'
}