mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 03:18:16 +00:00
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.
This commit is contained in:
@@ -72,6 +72,31 @@ autocmd! nvim.popupmenu
|
|||||||
" Undo the 'grepprg' and 'grepformat' setting in _defaults.lua.
|
" Undo the 'grepprg' and 'grepformat' setting in _defaults.lua.
|
||||||
set grepprg& grepformat&
|
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
|
" roughly equivalent to test_setmouse() in Vim
|
||||||
func Ntest_setmouse(row, col)
|
func Ntest_setmouse(row, col)
|
||||||
call nvim_input_mouse('move', '', '', 0, a:row - 1, a:col - 1)
|
call nvim_input_mouse('move', '', '', 0, a:row - 1, a:col - 1)
|
||||||
|
@@ -128,8 +128,7 @@ if has('timers')
|
|||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_OptionSet_modeline()
|
func Test_OptionSet_modeline()
|
||||||
CheckFunction test_override
|
call Ntest_override('starting', 1)
|
||||||
call test_override('starting', 1)
|
|
||||||
au! OptionSet
|
au! OptionSet
|
||||||
augroup set_tabstop
|
augroup set_tabstop
|
||||||
au OptionSet tabstop call timer_start(1, {-> execute("echo 'Handler called'", "")})
|
au OptionSet tabstop call timer_start(1, {-> execute("echo 'Handler called'", "")})
|
||||||
@@ -146,7 +145,7 @@ if has('timers')
|
|||||||
augroup END
|
augroup END
|
||||||
bwipe!
|
bwipe!
|
||||||
set ts&
|
set ts&
|
||||||
call test_override('starting', 0)
|
call Ntest_override('starting', 0)
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
endif "has('timers')
|
endif "has('timers')
|
||||||
@@ -1103,7 +1102,8 @@ func s:AutoCommandOptionSet(match)
|
|||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_OptionSet()
|
func Test_OptionSet()
|
||||||
CheckFunction test_override
|
" Use test/functional/legacy/autocmd_option_spec.lua
|
||||||
|
throw 'Skipped: Nvim changed types of OptionSet v: variables'
|
||||||
CheckOption autochdir
|
CheckOption autochdir
|
||||||
|
|
||||||
call test_override('starting', 1)
|
call test_override('starting', 1)
|
||||||
@@ -1705,8 +1705,7 @@ func Test_OptionSet()
|
|||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_OptionSet_diffmode()
|
func Test_OptionSet_diffmode()
|
||||||
CheckFunction test_override
|
call Ntest_override('starting', 1)
|
||||||
call test_override('starting', 1)
|
|
||||||
" 18: Changing an option when entering diff mode
|
" 18: Changing an option when entering diff mode
|
||||||
new
|
new
|
||||||
au OptionSet diff :let &l:cul = v:option_new
|
au OptionSet diff :let &l:cul = v:option_new
|
||||||
@@ -1735,12 +1734,11 @@ func Test_OptionSet_diffmode()
|
|||||||
|
|
||||||
" Cleanup
|
" Cleanup
|
||||||
au! OptionSet
|
au! OptionSet
|
||||||
call test_override('starting', 0)
|
call Ntest_override('starting', 0)
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_OptionSet_diffmode_close()
|
func Test_OptionSet_diffmode_close()
|
||||||
CheckFunction test_override
|
call Ntest_override('starting', 1)
|
||||||
call test_override('starting', 1)
|
|
||||||
" 19: Try to close the current window when entering diff mode
|
" 19: Try to close the current window when entering diff mode
|
||||||
" should not segfault
|
" should not segfault
|
||||||
new
|
new
|
||||||
@@ -1760,7 +1758,7 @@ func Test_OptionSet_diffmode_close()
|
|||||||
|
|
||||||
" Cleanup
|
" Cleanup
|
||||||
au! OptionSet
|
au! OptionSet
|
||||||
call test_override('starting', 0)
|
call Ntest_override('starting', 0)
|
||||||
"delfunc! AutoCommandOptionSet
|
"delfunc! AutoCommandOptionSet
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
@@ -3599,8 +3597,7 @@ func Test_Visual_doautoall_redraw()
|
|||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_get_Visual_selection_in_curbuf_autocmd()
|
func Test_get_Visual_selection_in_curbuf_autocmd()
|
||||||
throw 'Skipped: use test/functional/legacy/autocmd_spec.lua'
|
call Ntest_override('starting', 1)
|
||||||
call test_override('starting', 1)
|
|
||||||
new
|
new
|
||||||
autocmd OptionSet list let b:text = getregion(getpos('.'), getpos('v'))
|
autocmd OptionSet list let b:text = getregion(getpos('.'), getpos('v'))
|
||||||
call setline(1, 'foo bar baz')
|
call setline(1, 'foo bar baz')
|
||||||
@@ -3617,7 +3614,7 @@ func Test_get_Visual_selection_in_curbuf_autocmd()
|
|||||||
|
|
||||||
autocmd! OptionSet list
|
autocmd! OptionSet list
|
||||||
bwipe!
|
bwipe!
|
||||||
call test_override('starting', 0)
|
call Ntest_override('starting', 0)
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
" This was using freed memory.
|
" This was using freed memory.
|
||||||
|
@@ -199,10 +199,9 @@ func Test_gf_error()
|
|||||||
au OptionSet diff norm! gf
|
au OptionSet diff norm! gf
|
||||||
augroup END
|
augroup END
|
||||||
call setline(1, ['Xfile1', 'line2', 'line3', 'line4'])
|
call setline(1, ['Xfile1', 'line2', 'line3', 'line4'])
|
||||||
" Nvim does not support test_override()
|
call Ntest_override('starting', 1)
|
||||||
" call test_override('starting', 1)
|
call assert_fails('diffthis', 'E788:')
|
||||||
" call assert_fails('diffthis', 'E788:')
|
call Ntest_override('starting', 0)
|
||||||
" call test_override('starting', 0)
|
|
||||||
augroup Test_gf
|
augroup Test_gf
|
||||||
au!
|
au!
|
||||||
augroup END
|
augroup END
|
||||||
|
@@ -3284,7 +3284,7 @@ endfunc
|
|||||||
func Test_cclose_in_autocmd()
|
func Test_cclose_in_autocmd()
|
||||||
" Problem is only triggered if "starting" is zero, so that the OptionSet
|
" Problem is only triggered if "starting" is zero, so that the OptionSet
|
||||||
" event will be triggered.
|
" event will be triggered.
|
||||||
" call test_override('starting', 1)
|
call Ntest_override('starting', 1)
|
||||||
augroup QF_Test
|
augroup QF_Test
|
||||||
au!
|
au!
|
||||||
au FileType qf :call assert_fails(':cclose', 'E788')
|
au FileType qf :call assert_fails(':cclose', 'E788')
|
||||||
@@ -3294,7 +3294,7 @@ func Test_cclose_in_autocmd()
|
|||||||
au!
|
au!
|
||||||
augroup END
|
augroup END
|
||||||
augroup! QF_Test
|
augroup! QF_Test
|
||||||
" call test_override('starting', 0)
|
call Ntest_override('starting', 0)
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
" Check that ":file" without an argument is possible even when "curbuf->b_ro_locked"
|
" Check that ":file" without an argument is possible even when "curbuf->b_ro_locked"
|
||||||
|
Reference in New Issue
Block a user