summaryrefslogtreecommitdiff
path: root/test/plugins/ffi/cdef.lua
blob: cf3992d351973695624fa53377bc6faa07901fd0 (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

local files = require 'files'
local code  = require 'plugins.ffi.searchCode'
local cdefRerence = require 'plugins.ffi.cdefRerence'

rawset(_G, 'TEST', true)

function TEST(wanted)
    ---@async
    return function (script)
        files.setText(TESTURI, script)
        local codeResults = code(cdefRerence(), TESTURI)
        assert(codeResults)
        table.sort(codeResults)
        assert(table.concat(codeResults, '|') == wanted, table.concat(codeResults, '|') .. ' ~= ' .. wanted)
        files.remove(TESTURI)
    end
end

TEST 'aaa|bbb' [[
local ffi = require 'ffi'
local cdef = ffi.cdef
cdef('aaa')
cdef = function ()
end
cdef('bbb')
]]

TEST 'aaa' [[
local ffi = require 'ffi'

ffi.cdef('aaa')
]]

TEST 'aa.aa' [[
local ffi = require 'ffi'
local t1 = ffi

t1.cdef"aa.aa"
]]

TEST 'aaa' [[
local ffi = require 'ffi'
local code = 'aaa'
ffi.cdef(code)
]]

TEST 'aaa|bbb' [[
local ffi = require 'ffi'
local code = 'aaa'
code = 'bbb'
local t1 = ffi
t1.cdef(code)
]]

TEST 'aa.aa' [[
local ffi = require 'ffi'
local cdef = ffi.cdef

cdef"aa.aa"
]]