2024-04-20 08:44:13 -07:00
|
|
|
local t = require('test.testutil')
|
|
|
|
local n = require('test.functional.testnvim')()
|
|
|
|
|
2024-04-08 02:03:20 -07:00
|
|
|
local eq = t.eq
|
2024-04-20 08:44:13 -07:00
|
|
|
local exec_lua = n.exec_lua
|
|
|
|
local clear = n.clear
|
2021-10-12 08:10:47 -07:00
|
|
|
|
|
|
|
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-08-11 01:27:48 -07:00
|
|
|
exec_lua(function()
|
|
|
|
local ffi = require('ffi')
|
2021-10-12 08:10:47 -07:00
|
|
|
|
2024-08-11 01:27:48 -07:00
|
|
|
ffi.cdef [[
|
2024-03-11 05:19:49 -07:00
|
|
|
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
|
|
|
|
2024-08-11 01:27:48 -07:00
|
|
|
vim.cmd('set number numberwidth=4 signcolumn=yes:4')
|
2021-10-12 08:10:47 -07:00
|
|
|
|
2024-08-11 01:27:48 -07:00
|
|
|
return ffi.C.win_col_off(ffi.C.curwin)
|
|
|
|
end)
|
2021-10-12 08:10:47 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
eq(
|
|
|
|
20,
|
2024-08-11 01:27:48 -07:00
|
|
|
exec_lua(function()
|
|
|
|
local ffi = require('ffi')
|
2021-10-12 08:10:47 -07:00
|
|
|
|
2024-08-11 01:27:48 -07:00
|
|
|
ffi.cdef [[
|
2021-10-12 08:10:47 -07:00
|
|
|
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
|
|
|
);
|
|
|
|
]]
|
|
|
|
|
2024-08-11 01:27:48 -07:00
|
|
|
return ffi.C.build_stl_str_hl(
|
|
|
|
ffi.C.find_window_by_handle(0, ffi.new('Error')),
|
|
|
|
ffi.new('char[1024]'),
|
|
|
|
1024,
|
|
|
|
ffi.cast('char*', 'StatusLineOfLength20'),
|
|
|
|
-1,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
nil
|
|
|
|
)
|
|
|
|
end)
|
2021-10-12 08:10:47 -07:00
|
|
|
)
|
2023-03-23 04:58:50 -07:00
|
|
|
|
|
|
|
-- Check that extern symbols are exported and accessible
|
|
|
|
eq(
|
|
|
|
true,
|
2024-08-11 01:27:48 -07:00
|
|
|
exec_lua(function()
|
|
|
|
local ffi = require('ffi')
|
2023-03-23 04:58:50 -07:00
|
|
|
|
2024-08-11 01:27:48 -07:00
|
|
|
ffi.cdef('uint64_t display_tick;')
|
2023-03-23 04:58:50 -07:00
|
|
|
|
2024-08-11 01:27:48 -07:00
|
|
|
return ffi.C.display_tick >= 0
|
|
|
|
end)
|
2023-03-23 04:58:50 -07:00
|
|
|
)
|
2021-10-12 08:10:47 -07:00
|
|
|
end)
|
|
|
|
end)
|