test(old): emulate test_override('starting') with FFI (#34742)

I was initially trying to port several cmdline tests from Vim involving
test_override('char_avail') without having to rewrite entire tests in
Lua, but haven't figured out a good way achieve that yet. Nevertheless
emulating test_override('starting') is easier.

(cherry picked from commit 715c28d67f)
This commit is contained in:
zeertzjq
2025-07-03 19:21:58 +08:00
committed by github-actions[bot]
parent 0f81af53b0
commit b9dbdfef0e
4 changed files with 40 additions and 19 deletions

View File

@@ -71,6 +71,31 @@ autocmd! nvim.popupmenu
" Undo the 'grepprg' and 'grepformat' setting in _defaults.lua.
set grepprg& grepformat&
let s:has_ffi = luaeval('pcall(require, "ffi")')
if s:has_ffi
lua require("ffi").cdef("int starting;")
endif
" This can emulate test_override('starting', val) if LuaJIT FFI is enabled.
" Other flags are not supported.
func Ntest_override(name, val)
if a:name !=# 'starting'
throw "Do not use Ntest_override() for this"
endif
if !s:has_ffi
throw 'Skipped: missing LuaJIT FFI'
endif
if a:val
if !exists('s:save_starting')
let s:save_starting = luaeval('require("ffi").C.starting')
endif
lua require("ffi").C.starting = 0
else
exe 'lua require("ffi").C.starting =' s:save_starting
unlet s:save_starting
endif
endfunc
" roughly equivalent to test_setmouse() in Vim
func Ntest_setmouse(row, col)
call nvim_input_mouse('move', '', '', 0, a:row - 1, a:col - 1)