2021-10-12 08:10:47 -07:00
|
|
|
local helpers = require('test.functional.helpers')(after_each)
|
|
|
|
local eq = helpers.eq
|
|
|
|
local exec_lua = helpers.exec_lua
|
|
|
|
local clear = helpers.clear
|
|
|
|
|
|
|
|
before_each(clear)
|
|
|
|
|
|
|
|
describe('ffi.cdef', function()
|
|
|
|
it('can use Neovim core functions', function()
|
|
|
|
if not exec_lua("return pcall(require, 'ffi')") then
|
|
|
|
pending('missing LuaJIT FFI')
|
|
|
|
end
|
|
|
|
|
|
|
|
eq(
|
|
|
|
12,
|
2024-03-11 05:19:49 -07:00
|
|
|
exec_lua [=[
|
2021-10-12 08:10:47 -07:00
|
|
|
local ffi = require('ffi')
|
|
|
|
|
2024-03-11 05:19:49 -07:00
|
|
|
ffi.cdef [[
|
|
|
|
typedef struct window_S win_T;
|
|
|
|
int win_col_off(win_T *wp);
|
|
|
|
extern win_T *curwin;
|
|
|
|
]]
|
2021-10-12 08:10:47 -07:00
|
|
|
|
|
|
|
vim.cmd('set number numberwidth=4 signcolumn=yes:4')
|
|
|
|
|
2024-03-11 05:19:49 -07:00
|
|
|
return ffi.C.win_col_off(ffi.C.curwin)
|
|
|
|
]=]
|
2021-10-12 08:10:47 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
eq(
|
|
|
|
20,
|
|
|
|
exec_lua [=[
|
|
|
|
local ffi = require('ffi')
|
|
|
|
|
|
|
|
ffi.cdef[[
|
|
|
|
typedef struct {} stl_hlrec_t;
|
|
|
|
typedef struct {} StlClickRecord;
|
2023-01-09 10:12:06 -07:00
|
|
|
typedef struct {} statuscol_T;
|
2021-10-12 08:10:47 -07:00
|
|
|
typedef struct {} Error;
|
|
|
|
|
|
|
|
win_T *find_window_by_handle(int Window, Error *err);
|
|
|
|
|
|
|
|
int build_stl_str_hl(
|
|
|
|
win_T *wp,
|
2022-11-07 16:21:22 -07:00
|
|
|
char *out,
|
2021-10-12 08:10:47 -07:00
|
|
|
size_t outlen,
|
2022-11-07 16:21:22 -07:00
|
|
|
char *fmt,
|
2023-12-07 10:46:57 -07:00
|
|
|
int opt_idx,
|
2022-11-07 16:21:22 -07:00
|
|
|
int opt_scope,
|
|
|
|
int fillchar,
|
2021-10-12 08:10:47 -07:00
|
|
|
int maxwidth,
|
|
|
|
stl_hlrec_t **hltab,
|
2023-01-09 10:12:06 -07:00
|
|
|
StlClickRecord **tabtab,
|
|
|
|
statuscol_T *scp
|
2021-10-12 08:10:47 -07:00
|
|
|
);
|
|
|
|
]]
|
|
|
|
|
|
|
|
return ffi.C.build_stl_str_hl(
|
|
|
|
ffi.C.find_window_by_handle(0, ffi.new('Error')),
|
2022-11-07 16:21:22 -07:00
|
|
|
ffi.new('char[1024]'),
|
2021-10-12 08:10:47 -07:00
|
|
|
1024,
|
2022-11-07 16:21:22 -07:00
|
|
|
ffi.cast('char*', 'StatusLineOfLength20'),
|
2023-12-07 10:46:57 -07:00
|
|
|
-1,
|
2021-10-12 08:10:47 -07:00
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
nil,
|
2023-01-09 10:12:06 -07:00
|
|
|
nil,
|
2021-10-12 08:10:47 -07:00
|
|
|
nil
|
|
|
|
)
|
|
|
|
]=]
|
|
|
|
)
|
2023-03-23 04:58:50 -07:00
|
|
|
|
|
|
|
-- Check that extern symbols are exported and accessible
|
|
|
|
eq(
|
|
|
|
true,
|
|
|
|
exec_lua [[
|
|
|
|
local ffi = require('ffi')
|
|
|
|
|
|
|
|
ffi.cdef('uint64_t display_tick;')
|
|
|
|
|
|
|
|
return ffi.C.display_tick >= 0
|
|
|
|
]]
|
|
|
|
)
|
2021-10-12 08:10:47 -07:00
|
|
|
end)
|
|
|
|
end)
|