aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/functional/editor/defaults_spec.lua48
-rw-r--r--test/functional/editor/mode_normal_spec.lua20
-rw-r--r--test/functional/lua/runtime_spec.lua4
-rw-r--r--test/functional/testnvim.lua48
-rw-r--r--test/functional/ui/mouse_spec.lua31
-rw-r--r--test/functional/ui/popupmenu_spec.lua24
-rw-r--r--test/old/testdir/gen_opt_test.vim2
-rw-r--r--test/old/testdir/shared.vim12
-rw-r--r--test/old/testdir/test_autocmd.vim5
-rw-r--r--test/old/testdir/test_cmdline.vim5
-rw-r--r--test/old/testdir/test_compiler.vim7
-rw-r--r--test/old/testdir/test_expr.vim8
-rw-r--r--test/old/testdir/test_filetype.vim5
-rw-r--r--test/old/testdir/test_findfile.vim532
-rw-r--r--test/old/testdir/test_ins_complete.vim93
-rw-r--r--test/old/testdir/test_modeline.vim2
-rw-r--r--test/old/testdir/test_normal.vim4
-rw-r--r--test/old/testdir/test_options.vim2
-rw-r--r--test/old/testdir/test_popup.vim22
-rw-r--r--test/old/testdir/test_tagfunc.vim4
-rw-r--r--test/testutil.lua68
21 files changed, 737 insertions, 209 deletions
diff --git a/test/functional/editor/defaults_spec.lua b/test/functional/editor/defaults_spec.lua
index 70f12ab475..9786bfeaac 100644
--- a/test/functional/editor/defaults_spec.lua
+++ b/test/functional/editor/defaults_spec.lua
@@ -152,6 +152,54 @@ describe('default', function()
]],
})
end)
+
+ describe('[<Space>', function()
+ it('adds an empty line above the current line', function()
+ n.clear({ args_rm = { '--cmd' } })
+ n.insert([[first line]])
+ n.feed('[<Space>')
+ n.expect([[
+
+ first line]])
+ end)
+
+ it('works with a count', function()
+ n.clear({ args_rm = { '--cmd' } })
+ n.insert([[first line]])
+ n.feed('5[<Space>')
+ n.expect([[
+
+
+
+
+
+ first line]])
+ end)
+ end)
+
+ describe(']<Space>', function()
+ it('adds an empty line below the current line', function()
+ n.clear({ args_rm = { '--cmd' } })
+ n.insert([[first line]])
+ n.feed(']<Space>')
+ n.expect([[
+ first line
+ ]])
+ end)
+
+ it('works with a count', function()
+ n.clear({ args_rm = { '--cmd' } })
+ n.insert([[first line]])
+ n.feed('5]<Space>')
+ n.expect([[
+ first line
+
+
+
+
+ ]])
+ end)
+ end)
end)
end)
end)
diff --git a/test/functional/editor/mode_normal_spec.lua b/test/functional/editor/mode_normal_spec.lua
index b3ef4866dc..cca244e06c 100644
--- a/test/functional/editor/mode_normal_spec.lua
+++ b/test/functional/editor/mode_normal_spec.lua
@@ -9,6 +9,7 @@ local feed = n.feed
local fn = n.fn
local command = n.command
local eq = t.eq
+local api = n.api
describe('Normal mode', function()
before_each(clear)
@@ -41,4 +42,23 @@ describe('Normal mode', function()
attr_ids = {},
})
end)
+
+ it('replacing with ZWJ emoji sequences', function()
+ local screen = Screen.new(30, 8)
+ screen:attach()
+ api.nvim_buf_set_lines(0, 0, -1, true, { 'abcdefg' })
+ feed('05rπŸ§‘β€πŸŒΎ') -- ZWJ
+ screen:expect([[
+ πŸ§‘β€πŸŒΎπŸ§‘β€πŸŒΎπŸ§‘β€πŸŒΎπŸ§‘β€πŸŒΎ^πŸ§‘β€πŸŒΎfg |
+ {1:~ }|*6
+ |
+ ]])
+
+ feed('2rπŸ³οΈβ€βš§οΈ') -- ZWJ and variant selectors
+ screen:expect([[
+ πŸ§‘β€πŸŒΎπŸ§‘β€πŸŒΎπŸ§‘β€πŸŒΎπŸ§‘β€πŸŒΎπŸ³οΈβ€βš§οΈ^πŸ³οΈβ€βš§οΈg |
+ {1:~ }|*6
+ |
+ ]])
+ end)
end)
diff --git a/test/functional/lua/runtime_spec.lua b/test/functional/lua/runtime_spec.lua
index f63363d6d9..6705dff847 100644
--- a/test/functional/lua/runtime_spec.lua
+++ b/test/functional/lua/runtime_spec.lua
@@ -21,7 +21,9 @@ describe('runtime:', function()
exec('set rtp+=' .. plug_dir)
exec([[
set shell=doesnotexist
- set completeslash=slash
+ if exists('+completeslash')
+ set completeslash=slash
+ endif
set isfname+=(,)
]])
end)
diff --git a/test/functional/testnvim.lua b/test/functional/testnvim.lua
index 8a2281e2a1..60b2f872fc 100644
--- a/test/functional/testnvim.lua
+++ b/test/functional/testnvim.lua
@@ -920,36 +920,38 @@ function M.exec_lua(code, ...)
return M.api.nvim_exec_lua(code, { ... })
end
- assert(session)
+ assert(session, 'no Nvim session')
if not session.exec_lua_setup then
- M.api.nvim_exec_lua(
- [[
- _G.__test_exec_lua = {
- get_upvalues = loadstring((select(1,...))),
- set_upvalues = loadstring((select(2,...))),
- handler = loadstring((select(3,...)))
- }
- setmetatable(_G.__test_exec_lua, { __index = _G.__test_exec_lua })
- ]],
- { string.dump(get_upvalues), string.dump(set_upvalues), string.dump(exec_lua_handler) }
+ assert(
+ session:request(
+ 'nvim_exec_lua',
+ [[
+ _G.__test_exec_lua = {
+ get_upvalues = loadstring((select(1,...))),
+ set_upvalues = loadstring((select(2,...))),
+ handler = loadstring((select(3,...)))
+ }
+ setmetatable(_G.__test_exec_lua, { __index = _G.__test_exec_lua })
+ ]],
+ { string.dump(get_upvalues), string.dump(set_upvalues), string.dump(exec_lua_handler) }
+ )
)
session.exec_lua_setup = true
end
+ local stat, rv = session:request(
+ 'nvim_exec_lua',
+ 'return { _G.__test_exec_lua:handler(...) }',
+ { string.dump(code), get_upvalues(code), ... }
+ )
+
+ if not stat then
+ error(rv[2])
+ end
+
--- @type any[], table<string,any>
- local ret, upvalues = unpack(M.api.nvim_exec_lua(
- [[
- return {
- _G.__test_exec_lua:handler(...)
- }
- ]],
- {
- string.dump(code),
- get_upvalues(code),
- ...,
- }
- ))
+ local ret, upvalues = unpack(rv)
-- Update upvalues
if next(upvalues) then
diff --git a/test/functional/ui/mouse_spec.lua b/test/functional/ui/mouse_spec.lua
index bc18680749..471ee70906 100644
--- a/test/functional/ui/mouse_spec.lua
+++ b/test/functional/ui/mouse_spec.lua
@@ -1908,19 +1908,40 @@ describe('ui/mouse/input', function()
eq(0, api.nvim_get_var('mouse_up2'))
end)
- it('<MouseMove> is not translated into multiclicks and can be mapped', function()
+ it('<MouseMove> to different locations can be mapped', function()
api.nvim_set_var('mouse_move', 0)
api.nvim_set_var('mouse_move2', 0)
command('nnoremap <MouseMove> <Cmd>let g:mouse_move += 1<CR>')
command('nnoremap <2-MouseMove> <Cmd>let g:mouse_move2 += 1<CR>')
- feed('<MouseMove><0,0>')
- feed('<MouseMove><0,0>')
- api.nvim_input_mouse('move', '', '', 0, 0, 0)
- api.nvim_input_mouse('move', '', '', 0, 0, 0)
+ feed('<MouseMove><1,0>')
+ feed('<MouseMove><2,0>')
+ api.nvim_input_mouse('move', '', '', 0, 0, 3)
+ api.nvim_input_mouse('move', '', '', 0, 0, 4)
eq(4, api.nvim_get_var('mouse_move'))
eq(0, api.nvim_get_var('mouse_move2'))
end)
+ it('<MouseMove> to same location does not generate events #31103', function()
+ api.nvim_set_var('mouse_move', 0)
+ api.nvim_set_var('mouse_move2', 0)
+ command('nnoremap <MouseMove> <Cmd>let g:mouse_move += 1<CR>')
+ command('nnoremap <2-MouseMove> <Cmd>let g:mouse_move2 += 1<CR>')
+ api.nvim_input_mouse('move', '', '', 0, 0, 3)
+ eq(1, api.nvim_get_var('mouse_move'))
+ eq(0, api.nvim_get_var('mouse_move2'))
+ feed('<MouseMove><3,0>')
+ feed('<MouseMove><3,0>')
+ api.nvim_input_mouse('move', '', '', 0, 0, 3)
+ api.nvim_input_mouse('move', '', '', 0, 0, 3)
+ eq(1, api.nvim_get_var('mouse_move'))
+ eq(0, api.nvim_get_var('mouse_move2'))
+ eq({ mode = 'n', blocking = false }, api.nvim_get_mode())
+ feed('<MouseMove><3,0><Insert>')
+ eq(1, api.nvim_get_var('mouse_move'))
+ eq(0, api.nvim_get_var('mouse_move2'))
+ eq({ mode = 'i', blocking = false }, api.nvim_get_mode())
+ end)
+
it('feeding <MouseMove> in Normal mode does not use uninitialized memory #19480', function()
feed('<MouseMove>')
n.poke_eventloop()
diff --git a/test/functional/ui/popupmenu_spec.lua b/test/functional/ui/popupmenu_spec.lua
index 295d677aa0..d096311703 100644
--- a/test/functional/ui/popupmenu_spec.lua
+++ b/test/functional/ui/popupmenu_spec.lua
@@ -5190,10 +5190,18 @@ describe('builtin popupmenu', function()
-- oldtest: Test_pum_user_abbr_hlgroup()
it('custom abbr_hlgroup override', function()
exec([[
- func CompleteFunc( findstart, base )
+ let s:var = 0
+ func CompleteFunc(findstart, base)
if a:findstart
return 0
endif
+ if s:var == 1
+ return {
+ \ 'words': [
+ \ { 'word': 'aword1', 'abbr_hlgroup': 'StrikeFake' },
+ \ { 'word': 'δ½ ε₯½', 'abbr_hlgroup': 'StrikeFake' },
+ \]}
+ endif
return {
\ 'words': [
\ { 'word': 'aword1', 'menu': 'extra text 1', 'kind': 'W', 'abbr_hlgroup': 'StrikeFake' },
@@ -5201,6 +5209,9 @@ describe('builtin popupmenu', function()
\ { 'word': 'δ½ ε₯½', 'menu': 'extra text 3', 'kind': 'W', 'abbr_hlgroup': 'StrikeFake' },
\]}
endfunc
+ func ChangeVar()
+ let s:var = 1
+ endfunc
set completeopt=menu
set completefunc=CompleteFunc
@@ -5243,6 +5254,17 @@ describe('builtin popupmenu', function()
{2:-- }{5:match 2 of 3} |
]])
feed('<C-E><Esc>')
+
+ command('call ChangeVar()')
+ feed('S<C-X><C-U>')
+ screen:expect([[
+ aword1^ |
+ {ds:aword1}{s: }{1: }|
+ {dn:δ½ ε₯½}{n: }{1: }|
+ {1:~ }|*16
+ {2:-- }{5:match 1 of 2} |
+ ]])
+ feed('<C-E><Esc>')
end)
-- oldtest: Test_pum_user_kind_hlgroup()
diff --git a/test/old/testdir/gen_opt_test.vim b/test/old/testdir/gen_opt_test.vim
index 51f260cc5e..532ec965d1 100644
--- a/test/old/testdir/gen_opt_test.vim
+++ b/test/old/testdir/gen_opt_test.vim
@@ -392,7 +392,7 @@ for option in options
let fullname = option.full_name
let shortname = get(option, 'abbreviation', fullname)
- if get(option, 'immutable', v:false)
+ if !exists('+' .. fullname)
continue
endif
diff --git a/test/old/testdir/shared.vim b/test/old/testdir/shared.vim
index fc7e6b643a..bb1a6c8f5b 100644
--- a/test/old/testdir/shared.vim
+++ b/test/old/testdir/shared.vim
@@ -35,12 +35,20 @@ func PythonProg()
if has('unix')
" We also need the job feature or the pkill command to make sure the server
" can be stopped.
- if !(executable('python') && (has('job') || executable('pkill')))
+ if !(has('job') || executable('pkill'))
return ''
endif
- let s:python = 'python'
+ if executable('python3')
+ let s:python = 'python3'
+ elseif executable('python')
+ let s:python = 'python'
+ else
+ return ''
+ end
elseif has('win32')
" Use Python Launcher for Windows (py.exe) if available.
+ " NOTE: if you get a "Python was not found" error, disable the Python
+ " shortcuts in "Windows menu / Settings / Manage App Execution Aliases".
if executable('py.exe')
let s:python = 'py.exe'
elseif executable('python.exe')
diff --git a/test/old/testdir/test_autocmd.vim b/test/old/testdir/test_autocmd.vim
index c2bba8fafc..64599c869a 100644
--- a/test/old/testdir/test_autocmd.vim
+++ b/test/old/testdir/test_autocmd.vim
@@ -2003,7 +2003,10 @@ func Test_Cmdline()
au! CmdlineLeave
let save_shellslash = &shellslash
- set noshellslash
+ " Nvim doesn't allow setting value of a hidden option to non-default value
+ if exists('+shellslash')
+ set noshellslash
+ endif
au! CmdlineEnter / let g:entered = expand('<afile>')
au! CmdlineLeave / let g:left = expand('<afile>')
let g:entered = 0
diff --git a/test/old/testdir/test_cmdline.vim b/test/old/testdir/test_cmdline.vim
index 0ef2c33c03..8d405790e9 100644
--- a/test/old/testdir/test_cmdline.vim
+++ b/test/old/testdir/test_cmdline.vim
@@ -727,8 +727,8 @@ func Test_fullcommand()
\ ':5s': 'substitute',
\ "'<,'>s": 'substitute',
\ ":'<,'>s": 'substitute',
- \ 'CheckUni': 'CheckUnix',
- \ 'CheckUnix': 'CheckUnix',
+ \ 'CheckLin': 'CheckLinux',
+ \ 'CheckLinux': 'CheckLinux',
\ }
for [in, want] in items(tests)
@@ -2319,6 +2319,7 @@ endfunc
" Test for 'imcmdline' and 'imsearch'
" This test doesn't actually test the input method functionality.
func Test_cmdline_inputmethod()
+ throw 'Skipped: Nvim does not allow setting the value of a hidden option'
new
call setline(1, ['', 'abc', ''])
set imcmdline
diff --git a/test/old/testdir/test_compiler.vim b/test/old/testdir/test_compiler.vim
index 69420b4b7f..07b57b76d9 100644
--- a/test/old/testdir/test_compiler.vim
+++ b/test/old/testdir/test_compiler.vim
@@ -10,9 +10,12 @@ func Test_compiler()
let save_LC_ALL = $LC_ALL
let $LC_ALL= "C"
- " %:S does not work properly with 'shellslash' set
let save_shellslash = &shellslash
- set noshellslash
+ " Nvim doesn't allow setting value of a hidden option to non-default value
+ if exists('+shellslash')
+ " %:S does not work properly with 'shellslash' set
+ set noshellslash
+ endif
e Xfoo.pl
compiler perl
diff --git a/test/old/testdir/test_expr.vim b/test/old/testdir/test_expr.vim
index 58a385cba8..56a4c3bffa 100644
--- a/test/old/testdir/test_expr.vim
+++ b/test/old/testdir/test_expr.vim
@@ -799,10 +799,10 @@ func Test_expr_completion()
call assert_equal('"echo 1 || g:tvar1 g:tvar2', @:)
" completion for options
- call feedkeys(":echo &compat\<C-A>\<C-B>\"\<CR>", 'xt')
- call assert_equal('"echo &compatible', @:)
- call feedkeys(":echo 1 && &compat\<C-A>\<C-B>\"\<CR>", 'xt')
- call assert_equal('"echo 1 && &compatible', @:)
+ "call feedkeys(":echo &compat\<C-A>\<C-B>\"\<CR>", 'xt')
+ "call assert_equal('"echo &compatible', @:)
+ "call feedkeys(":echo 1 && &compat\<C-A>\<C-B>\"\<CR>", 'xt')
+ "call assert_equal('"echo 1 && &compatible', @:)
call feedkeys(":echo &g:equala\<C-A>\<C-B>\"\<CR>", 'xt')
call assert_equal('"echo &g:equalalways', @:)
diff --git a/test/old/testdir/test_filetype.vim b/test/old/testdir/test_filetype.vim
index 6fc9f8e65c..f957eb23a1 100644
--- a/test/old/testdir/test_filetype.vim
+++ b/test/old/testdir/test_filetype.vim
@@ -358,12 +358,14 @@ func s:GetFilenameChecks() abort
\ 'ibasic': ['file.iba', 'file.ibi'],
\ 'icemenu': ['/.icewm/menu', 'any/.icewm/menu'],
\ 'icon': ['file.icn'],
+ \ 'idris2': ['file.idr'],
\ 'indent': ['.indent.pro', 'indentrc'],
\ 'inform': ['file.inf', 'file.INF'],
\ 'initng': ['/etc/initng/any/file.i', 'file.ii', 'any/etc/initng/any/file.i'],
\ 'inittab': ['inittab'],
\ 'inko': ['file.inko'],
\ 'ipfilter': ['ipf.conf', 'ipf6.conf', 'ipf.rules'],
+ \ 'ipkg': ['file.ipkg'],
\ 'iss': ['file.iss'],
\ 'ist': ['file.ist', 'file.mst'],
\ 'j': ['file.ijs'],
@@ -406,11 +408,13 @@ func s:GetFilenameChecks() abort
\ 'lean': ['file.lean'],
\ 'ledger': ['file.ldg', 'file.ledger', 'file.journal'],
\ 'less': ['file.less'],
+ \ 'leo': ['file.leo'],
\ 'lex': ['file.lex', 'file.l', 'file.lxx', 'file.l++'],
\ 'lf': ['lfrc'],
\ 'lftp': ['lftp.conf', '.lftprc', 'anylftp/rc', 'lftp/rc', 'some-lftp/rc'],
\ 'lhaskell': ['file.lhs'],
\ 'libao': ['/etc/libao.conf', '/.libao', 'any/.libao', 'any/etc/libao.conf'],
+ \ 'lidris2': ['file.lidr'],
\ 'lifelines': ['file.ll'],
\ 'lilo': ['lilo.conf', 'lilo.conf-file'],
\ 'lilypond': ['file.ly', 'file.ily'],
@@ -726,6 +730,7 @@ func s:GetFilenameChecks() abort
\ 'svelte': ['file.svelte'],
\ 'svg': ['file.svg'],
\ 'svn': ['svn-commitfile.tmp', 'svn-commit-file.tmp', 'svn-commit.tmp'],
+ \ 'sway': ['file.sw'],
\ 'swayconfig': ['/home/user/.sway/config', '/home/user/.config/sway/config', '/etc/sway/config', '/etc/xdg/sway/config'],
\ 'swift': ['file.swift', 'file.swiftinterface'],
\ 'swiftgyb': ['file.swift.gyb'],
diff --git a/test/old/testdir/test_findfile.vim b/test/old/testdir/test_findfile.vim
index d3fdcad045..539c7a661a 100644
--- a/test/old/testdir/test_findfile.vim
+++ b/test/old/testdir/test_findfile.vim
@@ -1,6 +1,7 @@
" Test findfile() and finddir()
source check.vim
+source vim9.vim
let s:files = [ 'Xfinddir1/foo',
\ 'Xfinddir1/bar',
@@ -288,223 +289,526 @@ func Test_find_non_existing_path()
let &path = save_path
endfunc
-" Test for 'findexpr'
-func Test_findexpr()
+" Test for 'findfunc'
+func Test_findfunc()
CheckUnix
- call assert_equal('', &findexpr)
- call writefile(['aFile'], 'Xfindexpr1.c', 'D')
- call writefile(['bFile'], 'Xfindexpr2.c', 'D')
- call writefile(['cFile'], 'Xfindexpr3.c', 'D')
+ call assert_equal('', &findfunc)
+ call writefile(['aFile'], 'Xfindfunc1.c', 'D')
+ call writefile(['bFile'], 'Xfindfunc2.c', 'D')
+ call writefile(['cFile'], 'Xfindfunc3.c', 'D')
" basic tests
- func FindExpr1()
- let fnames = ['Xfindexpr1.c', 'Xfindexpr2.c', 'Xfindexpr3.c']
- return fnames->copy()->filter('v:val =~? v:fname')
+ func FindFuncBasic(pat, cmdcomplete)
+ let fnames = ['Xfindfunc1.c', 'Xfindfunc2.c', 'Xfindfunc3.c']
+ return fnames->copy()->filter('v:val =~? a:pat')
endfunc
- set findexpr=FindExpr1()
- find Xfindexpr3
- call assert_match('Xfindexpr3.c', @%)
+ set findfunc=FindFuncBasic
+ find Xfindfunc3
+ call assert_match('Xfindfunc3.c', @%)
bw!
2find Xfind
- call assert_match('Xfindexpr2.c', @%)
+ call assert_match('Xfindfunc2.c', @%)
bw!
call assert_fails('4find Xfind', 'E347: No more file "Xfind" found in path')
call assert_fails('find foobar', 'E345: Can''t find file "foobar" in path')
- sfind Xfindexpr2.c
- call assert_match('Xfindexpr2.c', @%)
+ sfind Xfindfunc2.c
+ call assert_match('Xfindfunc2.c', @%)
call assert_equal(2, winnr('$'))
%bw!
call assert_fails('sfind foobar', 'E345: Can''t find file "foobar" in path')
- tabfind Xfindexpr3.c
- call assert_match('Xfindexpr3.c', @%)
+ tabfind Xfindfunc3.c
+ call assert_match('Xfindfunc3.c', @%)
call assert_equal(2, tabpagenr())
%bw!
call assert_fails('tabfind foobar', 'E345: Can''t find file "foobar" in path')
+ " Test garbage collection
+ call test_garbagecollect_now()
+ find Xfindfunc2
+ call assert_match('Xfindfunc2.c', @%)
+ bw!
+ delfunc FindFuncBasic
+ call test_garbagecollect_now()
+ call assert_fails('find Xfindfunc2', 'E117: Unknown function: FindFuncBasic')
+
" Buffer-local option
- set findexpr=['abc']
+ func GlobalFindFunc(pat, cmdcomplete)
+ return ['global']
+ endfunc
+ func LocalFindFunc(pat, cmdcomplete)
+ return ['local']
+ endfunc
+ set findfunc=GlobalFindFunc
new
- setlocal findexpr=['def']
+ setlocal findfunc=LocalFindFunc
find xxxx
- call assert_equal('def', @%)
+ call assert_equal('local', @%)
wincmd w
find xxxx
- call assert_equal('abc', @%)
+ call assert_equal('global', @%)
aboveleft new
- call assert_equal("['abc']", &findexpr)
+ call assert_equal("GlobalFindFunc", &findfunc)
wincmd k
aboveleft new
- call assert_equal("['abc']", &findexpr)
+ call assert_equal("GlobalFindFunc", &findfunc)
%bw!
+ delfunc GlobalFindFunc
+ delfunc LocalFindFunc
- " Empty list
- set findexpr=[]
- call assert_fails('find xxxx', 'E345: Can''t find file "xxxx" in path')
+ " Assign an expression
+ set findfunc=[]
+ call assert_fails('find xxxx', 'E117: Unknown function: []')
" Error cases
- " Syntax error in the expression
- set findexpr=FindExpr1{}
- call assert_fails('find Xfindexpr1.c', 'E15: Invalid expression')
+ " Function that doesn't take any arguments
+ func FindFuncNoArg()
+ endfunc
+ set findfunc=FindFuncNoArg
+ call assert_fails('find Xfindfunc1.c', 'E118: Too many arguments for function: FindFuncNoArg')
+ delfunc FindFuncNoArg
- " Find expression throws an error
- func FindExpr2()
+ " Syntax error in the function
+ func FindFuncSyntaxError(pat, cmdcomplete)
+ return l
+ endfunc
+ set findfunc=FindFuncSyntaxError
+ call assert_fails('find Xfindfunc1.c', 'E121: Undefined variable: l')
+ delfunc FindFuncSyntaxError
+
+ " Find function throws an error
+ func FindFuncWithThrow(pat, cmdcomplete)
throw 'find error'
endfunc
- set findexpr=FindExpr2()
- call assert_fails('find Xfindexpr1.c', 'find error')
+ set findfunc=FindFuncWithThrow
+ call assert_fails('find Xfindfunc1.c', 'find error')
+ delfunc FindFuncWithThrow
- " Try using a null List as the expression
- set findexpr=v:_null_list
- call assert_fails('find Xfindexpr1.c', 'E345: Can''t find file "Xfindexpr1.c" in path')
+ " Try using a null function
+ "call assert_fails('let &findfunc = test_null_function()', 'E129: Function name required')
- " Try to create a new window from the find expression
- func FindExpr3()
+ " Try to create a new window from the find function
+ func FindFuncNewWindow(pat, cmdexpand)
new
return ["foo"]
endfunc
- set findexpr=FindExpr3()
- call assert_fails('find Xfindexpr1.c', 'E565: Not allowed to change text or change window')
+ set findfunc=FindFuncNewWindow
+ call assert_fails('find Xfindfunc1.c', 'E565: Not allowed to change text or change window')
+ delfunc FindFuncNewWindow
- " Try to modify the current buffer from the find expression
- func FindExpr4()
+ " Try to modify the current buffer from the find function
+ func FindFuncModifyBuf(pat, cmdexpand)
call setline(1, ['abc'])
return ["foo"]
endfunc
- set findexpr=FindExpr4()
- call assert_fails('find Xfindexpr1.c', 'E565: Not allowed to change text or change window')
-
- " Expression returning a string
- set findexpr='abc'
- call assert_fails('find Xfindexpr1.c', "E1514: 'findexpr' did not return a List type")
-
- set findexpr&
- delfunc! FindExpr1
- delfunc! FindExpr2
- delfunc! FindExpr3
- delfunc! FindExpr4
+ set findfunc=FindFuncModifyBuf
+ call assert_fails('find Xfindfunc1.c', 'E565: Not allowed to change text or change window')
+ delfunc FindFuncModifyBuf
+
+ " Return the wrong type from the function
+ func FindFuncWrongRet(pat, cmdexpand)
+ return 'foo'
+ endfunc
+ set findfunc=FindFuncWrongRet
+ call assert_fails('find Xfindfunc1.c', "E1514: 'findfunc' did not return a List type")
+ delfunc FindFuncWrongRet
+
+ set findfunc&
endfunc
-" Test for using a script-local function for 'findexpr'
-func Test_findexpr_scriptlocal_func()
- func! s:FindExprScript()
- let g:FindExprArg = v:fname
+" Test for using a script-local function for 'findfunc'
+func Test_findfunc_scriptlocal_func()
+ func! s:FindFuncScript(pat, cmdexpand)
+ let g:FindFuncArg = a:pat
return ['xxx']
endfunc
- set findexpr=s:FindExprScript()
- call assert_equal(expand('<SID>') .. 'FindExprScript()', &findexpr)
- call assert_equal(expand('<SID>') .. 'FindExprScript()', &g:findexpr)
+ set findfunc=s:FindFuncScript
+ call assert_equal(expand('<SID>') .. 'FindFuncScript', &findfunc)
+ call assert_equal(expand('<SID>') .. 'FindFuncScript', &g:findfunc)
+ new | only
+ let g:FindFuncArg = ''
+ find abc
+ call assert_equal('abc', g:FindFuncArg)
+ bw!
+
+ set findfunc=<SID>FindFuncScript
+ call assert_equal(expand('<SID>') .. 'FindFuncScript', &findfunc)
+ call assert_equal(expand('<SID>') .. 'FindFuncScript', &g:findfunc)
new | only
- let g:FindExprArg = ''
+ let g:FindFuncArg = ''
find abc
- call assert_equal('abc', g:FindExprArg)
+ call assert_equal('abc', g:FindFuncArg)
bw!
- set findexpr=<SID>FindExprScript()
- call assert_equal(expand('<SID>') .. 'FindExprScript()', &findexpr)
- call assert_equal(expand('<SID>') .. 'FindExprScript()', &g:findexpr)
+ let &findfunc = 's:FindFuncScript'
+ call assert_equal(expand('<SID>') .. 'FindFuncScript', &g:findfunc)
new | only
- let g:FindExprArg = ''
+ let g:FindFuncArg = ''
find abc
- call assert_equal('abc', g:FindExprArg)
+ call assert_equal('abc', g:FindFuncArg)
bw!
- let &findexpr = 's:FindExprScript()'
- call assert_equal(expand('<SID>') .. 'FindExprScript()', &g:findexpr)
+ let &findfunc = '<SID>FindFuncScript'
+ call assert_equal(expand('<SID>') .. 'FindFuncScript', &g:findfunc)
new | only
- let g:FindExprArg = ''
+ let g:FindFuncArg = ''
find abc
- call assert_equal('abc', g:FindExprArg)
+ call assert_equal('abc', g:FindFuncArg)
bw!
- let &findexpr = '<SID>FindExprScript()'
- call assert_equal(expand('<SID>') .. 'FindExprScript()', &g:findexpr)
+ set findfunc=
+ setglobal findfunc=s:FindFuncScript
+ setlocal findfunc=
+ call assert_equal(expand('<SID>') .. 'FindFuncScript', &findfunc)
+ call assert_equal(expand('<SID>') .. 'FindFuncScript', &g:findfunc)
+ call assert_equal('', &l:findfunc)
new | only
- let g:FindExprArg = ''
+ let g:FindFuncArg = ''
find abc
- call assert_equal('abc', g:FindExprArg)
+ call assert_equal('abc', g:FindFuncArg)
bw!
- set findexpr=
- setglobal findexpr=s:FindExprScript()
- setlocal findexpr=
- call assert_equal(expand('<SID>') .. 'FindExprScript()', &findexpr)
- call assert_equal(expand('<SID>') .. 'FindExprScript()', &g:findexpr)
- call assert_equal('', &l:findexpr)
new | only
- let g:FindExprArg = ''
+ set findfunc=
+ setglobal findfunc=
+ setlocal findfunc=s:FindFuncScript
+ call assert_equal(expand('<SID>') .. 'FindFuncScript', &findfunc)
+ call assert_equal(expand('<SID>') .. 'FindFuncScript', &l:findfunc)
+ call assert_equal('', &g:findfunc)
+ let g:FindFuncArg = ''
find abc
- call assert_equal('abc', g:FindExprArg)
+ call assert_equal('abc', g:FindFuncArg)
bw!
new | only
- set findexpr=
- setglobal findexpr=
- setlocal findexpr=s:FindExprScript()
- call assert_equal(expand('<SID>') .. 'FindExprScript()', &findexpr)
- call assert_equal(expand('<SID>') .. 'FindExprScript()', &l:findexpr)
- call assert_equal('', &g:findexpr)
- let g:FindExprArg = ''
+ set findfunc=
+ setlocal findfunc=NoSuchFunc
+ setglobal findfunc=s:FindFuncScript
+ call assert_equal('NoSuchFunc', &findfunc)
+ call assert_equal('NoSuchFunc', &l:findfunc)
+ call assert_equal(expand('<SID>') .. 'FindFuncScript', &g:findfunc)
+ new | only
+ call assert_equal(expand('<SID>') .. 'FindFuncScript', &findfunc)
+ call assert_equal(expand('<SID>') .. 'FindFuncScript', &g:findfunc)
+ call assert_equal('', &l:findfunc)
+ let g:FindFuncArg = ''
find abc
- call assert_equal('abc', g:FindExprArg)
+ call assert_equal('abc', g:FindFuncArg)
bw!
- set findexpr=
- delfunc s:FindExprScript
+ new | only
+ set findfunc=
+ setlocal findfunc=NoSuchFunc
+ set findfunc=s:FindFuncScript
+ call assert_equal(expand('<SID>') .. 'FindFuncScript', &findfunc)
+ call assert_equal(expand('<SID>') .. 'FindFuncScript', &g:findfunc)
+ call assert_equal('', &l:findfunc)
+ let g:FindFuncArg = ''
+ find abc
+ call assert_equal('abc', g:FindFuncArg)
+ new | only
+ call assert_equal(expand('<SID>') .. 'FindFuncScript', &findfunc)
+ call assert_equal(expand('<SID>') .. 'FindFuncScript', &g:findfunc)
+ call assert_equal('', &l:findfunc)
+ let g:FindFuncArg = ''
+ find abc
+ call assert_equal('abc', g:FindFuncArg)
+ bw!
+
+ set findfunc=
+ delfunc s:FindFuncScript
endfunc
-" Test for expanding the argument to the :find command using 'findexpr'
-func Test_findexpr_expand_arg()
- let s:fnames = ['Xfindexpr1.c', 'Xfindexpr2.c', 'Xfindexpr3.c']
+" Test for expanding the argument to the :find command using 'findfunc'
+func Test_findfunc_expand_arg()
+ let s:fnames = ['Xfindfunc1.c', 'Xfindfunc2.c', 'Xfindfunc3.c']
- " 'findexpr' that accepts a regular expression
- func FindExprRegexp()
- return s:fnames->copy()->filter('v:val =~? v:fname')
+ " 'findfunc' that accepts a regular expression
+ func FindFuncRegexp(pat, cmdcomplete)
+ return s:fnames->copy()->filter('v:val =~? a:pat')
endfunc
- " 'findexpr' that accepts a glob
- func FindExprGlob()
- let pat = glob2regpat(v:cmdcomplete ? $'*{v:fname}*' : v:fname)
+ " 'findfunc' that accepts a glob
+ func FindFuncGlob(pat_arg, cmdcomplete)
+ let pat = glob2regpat(a:cmdcomplete ? $'*{a:pat_arg}*' : a:pat_arg)
return s:fnames->copy()->filter('v:val =~? pat')
endfunc
for regexp in [v:true, v:false]
- let &findexpr = regexp ? 'FindExprRegexp()' : 'FindExprGlob()'
+ let &findfunc = regexp ? 'FindFuncRegexp' : 'FindFuncGlob'
call feedkeys(":find \<Tab>\<C-B>\"\<CR>", "xt")
- call assert_equal('"find Xfindexpr1.c', @:)
+ call assert_equal('"find Xfindfunc1.c', @:)
call feedkeys(":find Xfind\<Tab>\<Tab>\<C-B>\"\<CR>", "xt")
- call assert_equal('"find Xfindexpr2.c', @:)
+ call assert_equal('"find Xfindfunc2.c', @:)
call assert_equal(s:fnames, getcompletion('find ', 'cmdline'))
call assert_equal(s:fnames, getcompletion('find Xfind', 'cmdline'))
let pat = regexp ? 'X.*1\.c' : 'X*1.c'
call feedkeys($":find {pat}\<Tab>\<C-B>\"\<CR>", "xt")
- call assert_equal('"find Xfindexpr1.c', @:)
- call assert_equal(['Xfindexpr1.c'], getcompletion($'find {pat}', 'cmdline'))
+ call assert_equal('"find Xfindfunc1.c', @:)
+ call assert_equal(['Xfindfunc1.c'], getcompletion($'find {pat}', 'cmdline'))
call feedkeys(":find 3\<Tab>\<C-B>\"\<CR>", "xt")
- call assert_equal('"find Xfindexpr3.c', @:)
- call assert_equal(['Xfindexpr3.c'], getcompletion($'find 3', 'cmdline'))
+ call assert_equal('"find Xfindfunc3.c', @:)
+ call assert_equal(['Xfindfunc3.c'], getcompletion($'find 3', 'cmdline'))
call feedkeys(":find Xfind\<C-A>\<C-B>\"\<CR>", "xt")
- call assert_equal('"find Xfindexpr1.c Xfindexpr2.c Xfindexpr3.c', @:)
+ call assert_equal('"find Xfindfunc1.c Xfindfunc2.c Xfindfunc3.c', @:)
call feedkeys(":find abc\<Tab>\<C-B>\"\<CR>", "xt")
call assert_equal('"find abc', @:)
call assert_equal([], getcompletion('find abc', 'cmdline'))
endfor
- set findexpr&
- delfunc! FindExprRegexp
- delfunc! FindExprGlob
+ set findfunc&
+ delfunc! FindFuncRegexp
+ delfunc! FindFuncGlob
unlet s:fnames
endfunc
+" Test for different ways of setting the 'findfunc' option
+func Test_findfunc_callback()
+ new
+ func FindFunc1(pat, cmdexpand)
+ let g:FindFunc1Args = [a:pat, a:cmdexpand]
+ return ['findfunc1']
+ endfunc
+
+ let lines =<< trim END
+ #" Test for using a function name
+ LET &findfunc = 'g:FindFunc1'
+ LET g:FindFunc1Args = []
+ find abc1
+ call assert_equal(['abc1', v:false], g:FindFunc1Args)
+
+ #" Test for using a function()
+ set findfunc=function('g:FindFunc1')
+ LET g:FindFunc1Args = []
+ find abc2
+ call assert_equal(['abc2', v:false], g:FindFunc1Args)
+
+ #" Using a funcref variable to set 'findfunc'
+ VAR Fn = function('g:FindFunc1')
+ LET &findfunc = Fn
+ LET g:FindFunc1Args = []
+ find abc3
+ call assert_equal(['abc3', v:false], g:FindFunc1Args)
+
+ #" Using a string(funcref_variable) to set 'findfunc'
+ LET Fn = function('g:FindFunc1')
+ LET &findfunc = string(Fn)
+ LET g:FindFunc1Args = []
+ find abc4
+ call assert_equal(['abc4', v:false], g:FindFunc1Args)
+
+ #" Test for using a funcref()
+ set findfunc=funcref('g:FindFunc1')
+ LET g:FindFunc1Args = []
+ find abc5
+ call assert_equal(['abc5', v:false], g:FindFunc1Args)
+
+ #" Using a funcref variable to set 'findfunc'
+ LET Fn = funcref('g:FindFunc1')
+ LET &findfunc = Fn
+ LET g:FindFunc1Args = []
+ find abc6
+ call assert_equal(['abc6', v:false], g:FindFunc1Args)
+
+ #" Using a string(funcref_variable) to set 'findfunc'
+ LET Fn = funcref('g:FindFunc1')
+ LET &findfunc = string(Fn)
+ LET g:FindFunc1Args = []
+ find abc7
+ call assert_equal(['abc7', v:false], g:FindFunc1Args)
+
+ #" Test for using a lambda function using set
+ VAR optval = "LSTART pat, cmdexpand LMIDDLE FindFunc1(pat, cmdexpand) LEND"
+ LET optval = substitute(optval, ' ', '\\ ', 'g')
+ exe "set findfunc=" .. optval
+ LET g:FindFunc1Args = []
+ find abc8
+ call assert_equal(['abc8', v:false], g:FindFunc1Args)
+
+ #" Test for using a lambda function using LET
+ LET &findfunc = LSTART pat, _ LMIDDLE FindFunc1(pat, v:false) LEND
+ LET g:FindFunc1Args = []
+ find abc9
+ call assert_equal(['abc9', v:false], g:FindFunc1Args)
+
+ #" Set 'findfunc' to a string(lambda expression)
+ LET &findfunc = 'LSTART pat, _ LMIDDLE FindFunc1(pat, v:false) LEND'
+ LET g:FindFunc1Args = []
+ find abc10
+ call assert_equal(['abc10', v:false], g:FindFunc1Args)
+
+ #" Set 'findfunc' to a variable with a lambda expression
+ VAR Lambda = LSTART pat, _ LMIDDLE FindFunc1(pat, v:false) LEND
+ LET &findfunc = Lambda
+ LET g:FindFunc1Args = []
+ find abc11
+ call assert_equal(['abc11', v:false], g:FindFunc1Args)
+
+ #" Set 'findfunc' to a string(variable with a lambda expression)
+ LET Lambda = LSTART pat, _ LMIDDLE FindFunc1(pat, v:false) LEND
+ LET &findfunc = string(Lambda)
+ LET g:FindFunc1Args = []
+ find abc12
+ call assert_equal(['abc12', v:false], g:FindFunc1Args)
+
+ #" Try to use 'findfunc' after the function is deleted
+ func g:TmpFindFunc(pat, cmdexpand)
+ let g:TmpFindFunc1Args = [a:pat, a:cmdexpand]
+ endfunc
+ LET &findfunc = function('g:TmpFindFunc')
+ delfunc g:TmpFindFunc
+ call test_garbagecollect_now()
+ LET g:TmpFindFunc1Args = []
+ call assert_fails('find abc13', 'E117:')
+ call assert_equal([], g:TmpFindFunc1Args)
+
+ #" Try to use a function with three arguments for 'findfunc'
+ func g:TmpFindFunc2(x, y, z)
+ let g:TmpFindFunc2Args = [a:x, a:y, a:z]
+ endfunc
+ set findfunc=TmpFindFunc2
+ LET g:TmpFindFunc2Args = []
+ call assert_fails('find abc14', 'E119:')
+ call assert_equal([], g:TmpFindFunc2Args)
+ delfunc TmpFindFunc2
+
+ #" Try to use a function with zero arguments for 'findfunc'
+ func g:TmpFindFunc3()
+ let g:TmpFindFunc3Called = v:true
+ endfunc
+ set findfunc=TmpFindFunc3
+ LET g:TmpFindFunc3Called = v:false
+ call assert_fails('find abc15', 'E118:')
+ call assert_equal(v:false, g:TmpFindFunc3Called)
+ delfunc TmpFindFunc3
+
+ #" Try to use a lambda function with three arguments for 'findfunc'
+ LET &findfunc = LSTART a, b, c LMIDDLE FindFunc1(a, v:false) LEND
+ LET g:FindFunc1Args = []
+ call assert_fails('find abc16', 'E119:')
+ call assert_equal([], g:FindFunc1Args)
+
+ #" Test for clearing the 'findfunc' option
+ set findfunc=''
+ set findfunc&
+ call assert_fails("set findfunc=function('abc')", "E700:")
+ call assert_fails("set findfunc=funcref('abc')", "E700:")
+
+ #" set 'findfunc' to a non-existing function
+ LET &findfunc = function('g:FindFunc1')
+ call assert_fails("set findfunc=function('NonExistingFunc')", 'E700:')
+ call assert_fails("LET &findfunc = function('NonExistingFunc')", 'E700:')
+ LET g:FindFunc1Args = []
+ find abc17
+ call assert_equal(['abc17', v:false], g:FindFunc1Args)
+ END
+ call CheckTransLegacySuccess(lines)
+
+ " Test for using a script-local function name
+ func s:FindFunc2(pat, cmdexpand)
+ let g:FindFunc2Args = [a:pat, a:cmdexpand]
+ return ['findfunc2']
+ endfunc
+ set findfunc=s:FindFunc2
+ let g:FindFunc2Args = []
+ find abc18
+ call assert_equal(['abc18', v:false], g:FindFunc2Args)
+
+ let &findfunc = 's:FindFunc2'
+ let g:FindFunc2Args = []
+ find abc19
+ call assert_equal(['abc19', v:false], g:FindFunc2Args)
+ delfunc s:FindFunc2
+
+ " Using Vim9 lambda expression in legacy context should fail
+ set findfunc=(pat,\ cmdexpand)\ =>\ FindFunc1(pat,\ v:false)
+ let g:FindFunc1Args = []
+ call assert_fails('find abc20', 'E117:')
+ call assert_equal([], g:FindFunc1Args)
+
+ " set 'findfunc' to a partial with dict.
+ func SetFindFunc()
+ let operator = {'execute': function('FindFuncExecute')}
+ let &findfunc = operator.execute
+ endfunc
+ func FindFuncExecute(pat, cmdexpand) dict
+ return ['findfuncexecute']
+ endfunc
+ call SetFindFunc()
+ call test_garbagecollect_now()
+ set findfunc=
+ delfunc SetFindFunc
+ delfunc FindFuncExecute
+
+ func FindFunc2(pat, cmdexpand)
+ let g:FindFunc2Args = [a:pat, a:cmdexpand]
+ return ['findfunc2']
+ endfunc
+
+ " Vim9 tests
+ let lines =<< trim END
+ vim9script
+
+ def g:Vim9findFunc(pat: string, cmdexpand: bool): list<string>
+ g:FindFunc1Args = [pat, cmdexpand]
+ return ['vim9findfunc']
+ enddef
+
+ # Test for using a def function with findfunc
+ set findfunc=function('g:Vim9findFunc')
+ g:FindFunc1Args = []
+ find abc21
+ assert_equal(['abc21', false], g:FindFunc1Args)
+
+ # Test for using a global function name
+ &findfunc = g:FindFunc2
+ g:FindFunc2Args = []
+ find abc22
+ assert_equal(['abc22', false], g:FindFunc2Args)
+ bw!
+
+ # Test for using a script-local function name
+ def LocalFindFunc(pat: string, cmdexpand: bool): list<string>
+ g:LocalFindFuncArgs = [pat, cmdexpand]
+ return ['localfindfunc']
+ enddef
+ &findfunc = LocalFindFunc
+ g:LocalFindFuncArgs = []
+ find abc23
+ assert_equal(['abc23', false], g:LocalFindFuncArgs)
+ bw!
+ END
+ call CheckScriptSuccess(lines)
+
+ " setting 'findfunc' to a script local function outside of a script context
+ " should fail
+ let cleanup =<< trim END
+ call writefile([execute('messages')], 'Xtest.out')
+ qall
+ END
+ call writefile(cleanup, 'Xverify.vim', 'D')
+ call RunVim([], [], "-c \"set findfunc=s:abc\" -S Xverify.vim")
+ call assert_match('E81: Using <SID> not in a', readfile('Xtest.out')[0])
+ call delete('Xtest.out')
+
+ " cleanup
+ set findfunc&
+ delfunc FindFunc1
+ delfunc FindFunc2
+ unlet g:FindFunc1Args g:FindFunc2Args
+ %bw!
+endfunc
+
+
" vim: shiftwidth=2 sts=2 expandtab
diff --git a/test/old/testdir/test_ins_complete.vim b/test/old/testdir/test_ins_complete.vim
index 48319f5017..c02aa1db62 100644
--- a/test/old/testdir/test_ins_complete.vim
+++ b/test/old/testdir/test_ins_complete.vim
@@ -950,6 +950,46 @@ func Test_completeopt_buffer_local()
call assert_equal('menu', &completeopt)
call assert_equal('menu', &g:completeopt)
+ new | only
+ call setline(1, ['foofoo', 'foobar', 'foobaz', ''])
+ set completeopt&
+ setlocal completeopt=menu,fuzzy,noinsert
+ setglobal completeopt=menu,longest
+ call assert_equal('menu,fuzzy,noinsert', &completeopt)
+ call assert_equal('menu,fuzzy,noinsert', &l:completeopt)
+ call assert_equal('menu,longest', &g:completeopt)
+ call feedkeys("Gccf\<C-X>\<C-N>bz\<C-Y>", 'tnix')
+ call assert_equal('foobaz', getline('.'))
+ setlocal bufhidden=wipe
+ new | only!
+ call setline(1, ['foofoo', 'foobar', 'foobaz', ''])
+ call assert_equal('menu,longest', &completeopt)
+ call assert_equal('menu,longest', &g:completeopt)
+ call assert_equal('', &l:completeopt)
+ call feedkeys("Gccf\<C-X>\<C-N>\<C-X>\<C-Z>", 'tnix')
+ call assert_equal('foo', getline('.'))
+ bwipe!
+
+ new | only
+ call setline(1, ['foofoo', 'foobar', 'foobaz', ''])
+ set completeopt&
+ setlocal completeopt=menu,fuzzy,noinsert
+ set completeopt=menu,longest
+ call assert_equal('menu,longest', &completeopt)
+ call assert_equal('menu,longest', &g:completeopt)
+ call assert_equal('', &l:completeopt)
+ call feedkeys("Gccf\<C-X>\<C-N>\<C-X>\<C-Z>", 'tnix')
+ call assert_equal('foo', getline('.'))
+ setlocal bufhidden=wipe
+ new | only!
+ call setline(1, ['foofoo', 'foobar', 'foobaz', ''])
+ call assert_equal('menu,longest', &completeopt)
+ call assert_equal('menu,longest', &g:completeopt)
+ call assert_equal('', &l:completeopt)
+ call feedkeys("Gccf\<C-X>\<C-N>\<C-X>\<C-Z>", 'tnix')
+ call assert_equal('foo', getline('.'))
+ bwipe!
+
set completeopt&
endfunc
@@ -1713,10 +1753,10 @@ func Test_completefunc_callback()
call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
" Using Vim9 lambda expression in legacy context should fail
- " set completefunc=(a,\ b)\ =>\ CompleteFunc1(21,\ a,\ b)
+ set completefunc=(a,\ b)\ =>\ CompleteFunc1(21,\ a,\ b)
new | only
let g:CompleteFunc1Args = []
- " call assert_fails('call feedkeys("A\<C-X>\<C-U>\<Esc>", "x")', 'E117:')
+ call assert_fails('call feedkeys("A\<C-X>\<C-U>\<Esc>", "x")', 'E117:')
call assert_equal([], g:CompleteFunc1Args)
" set 'completefunc' to a partial with dict. This used to cause a crash.
@@ -1970,10 +2010,10 @@ func Test_omnifunc_callback()
call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
" Using Vim9 lambda expression in legacy context should fail
- " set omnifunc=(a,\ b)\ =>\ OmniFunc1(21,\ a,\ b)
+ set omnifunc=(a,\ b)\ =>\ OmniFunc1(21,\ a,\ b)
new | only
let g:OmniFunc1Args = []
- " call assert_fails('call feedkeys("A\<C-X>\<C-O>\<Esc>", "x")', 'E117:')
+ call assert_fails('call feedkeys("A\<C-X>\<C-O>\<Esc>", "x")', 'E117:')
call assert_equal([], g:OmniFunc1Args)
" set 'omnifunc' to a partial with dict. This used to cause a crash.
@@ -2228,6 +2268,7 @@ func Test_thesaurusfunc_callback()
call add(g:TsrFunc3Args, [a:findstart, a:base])
return a:findstart ? 0 : []
endfunc
+
set tsrfu=s:TsrFunc3
new
call setline(1, 'script1')
@@ -2243,6 +2284,46 @@ func Test_thesaurusfunc_callback()
call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
call assert_equal([[1, ''], [0, 'script2']], g:TsrFunc3Args)
bw!
+
+ new | only
+ set thesaurusfunc=
+ setlocal thesaurusfunc=NoSuchFunc
+ setglobal thesaurusfunc=s:TsrFunc3
+ call assert_equal('NoSuchFunc', &thesaurusfunc)
+ call assert_equal('NoSuchFunc', &l:thesaurusfunc)
+ call assert_equal('s:TsrFunc3', &g:thesaurusfunc)
+ new | only
+ call assert_equal('s:TsrFunc3', &thesaurusfunc)
+ call assert_equal('s:TsrFunc3', &g:thesaurusfunc)
+ call assert_equal('', &l:thesaurusfunc)
+ call setline(1, 'script1')
+ let g:TsrFunc3Args = []
+ call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
+ call assert_equal([[1, ''], [0, 'script1']], g:TsrFunc3Args)
+ bw!
+
+ new | only
+ set thesaurusfunc=
+ setlocal thesaurusfunc=NoSuchFunc
+ set thesaurusfunc=s:TsrFunc3
+ call assert_equal('s:TsrFunc3', &thesaurusfunc)
+ call assert_equal('s:TsrFunc3', &g:thesaurusfunc)
+ call assert_equal('', &l:thesaurusfunc)
+ call setline(1, 'script1')
+ let g:TsrFunc3Args = []
+ call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
+ call assert_equal([[1, ''], [0, 'script1']], g:TsrFunc3Args)
+ setlocal bufhidden=wipe
+ new | only!
+ call assert_equal('s:TsrFunc3', &thesaurusfunc)
+ call assert_equal('s:TsrFunc3', &g:thesaurusfunc)
+ call assert_equal('', &l:thesaurusfunc)
+ call setline(1, 'script1')
+ let g:TsrFunc3Args = []
+ call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
+ call assert_equal([[1, ''], [0, 'script1']], g:TsrFunc3Args)
+ bw!
+
delfunc s:TsrFunc3
" invalid return value
@@ -2250,10 +2331,10 @@ func Test_thesaurusfunc_callback()
call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
" Using Vim9 lambda expression in legacy context should fail
- " set thesaurusfunc=(a,\ b)\ =>\ TsrFunc1(21,\ a,\ b)
+ set thesaurusfunc=(a,\ b)\ =>\ TsrFunc1(21,\ a,\ b)
new | only
let g:TsrFunc1Args = []
- " call assert_fails('call feedkeys("A\<C-X>\<C-T>\<Esc>", "x")', 'E117:')
+ call assert_fails('call feedkeys("A\<C-X>\<C-T>\<Esc>", "x")', 'E117:')
call assert_equal([], g:TsrFunc1Args)
bw!
diff --git a/test/old/testdir/test_modeline.vim b/test/old/testdir/test_modeline.vim
index 7b7163d372..2cd9e49a12 100644
--- a/test/old/testdir/test_modeline.vim
+++ b/test/old/testdir/test_modeline.vim
@@ -217,7 +217,7 @@ func Test_modeline_fails_always()
call s:modeline_fails('equalprg', 'equalprg=Something()', 'E520:')
call s:modeline_fails('errorfile', 'errorfile=Something()', 'E520:')
call s:modeline_fails('exrc', 'exrc=Something()', 'E520:')
- call s:modeline_fails('findexpr', 'findexpr=Something()', 'E520:')
+ call s:modeline_fails('findfunc', 'findfunc=Something', 'E520:')
call s:modeline_fails('formatprg', 'formatprg=Something()', 'E520:')
call s:modeline_fails('fsync', 'fsync=Something()', 'E520:')
call s:modeline_fails('grepprg', 'grepprg=Something()', 'E520:')
diff --git a/test/old/testdir/test_normal.vim b/test/old/testdir/test_normal.vim
index 46fddd6c1a..faa93c4b61 100644
--- a/test/old/testdir/test_normal.vim
+++ b/test/old/testdir/test_normal.vim
@@ -692,9 +692,9 @@ func Test_opfunc_callback()
delfunc s:OpFunc3
" Using Vim9 lambda expression in legacy context should fail
- " set opfunc=(a)\ =>\ OpFunc1(24,\ a)
+ set opfunc=(a)\ =>\ OpFunc1(24,\ a)
let g:OpFunc1Args = []
- " call assert_fails('normal! g@l', 'E117:')
+ call assert_fails('normal! g@l', 'E117:')
call assert_equal([], g:OpFunc1Args)
" set 'operatorfunc' to a partial with dict. This used to cause a crash.
diff --git a/test/old/testdir/test_options.vim b/test/old/testdir/test_options.vim
index 6902560518..540936e7ec 100644
--- a/test/old/testdir/test_options.vim
+++ b/test/old/testdir/test_options.vim
@@ -1559,7 +1559,7 @@ endfunc
" Test for changing options in a sandbox
func Test_opt_sandbox()
- for opt in ['backupdir', 'cdpath', 'exrc', 'findexpr']
+ for opt in ['backupdir', 'cdpath', 'exrc', 'findfunc']
call assert_fails('sandbox set ' .. opt .. '?', 'E48:')
call assert_fails('sandbox let &' .. opt .. ' = 1', 'E48:')
endfor
diff --git a/test/old/testdir/test_popup.vim b/test/old/testdir/test_popup.vim
index d35d32b13d..601ba6c688 100644
--- a/test/old/testdir/test_popup.vim
+++ b/test/old/testdir/test_popup.vim
@@ -1509,10 +1509,18 @@ endfunc
func Test_pum_user_abbr_hlgroup()
CheckScreendump
let lines =<< trim END
- func CompleteFunc( findstart, base )
+ let s:var = 0
+ func CompleteFunc(findstart, base)
if a:findstart
return 0
endif
+ if s:var == 1
+ return {
+ \ 'words': [
+ \ { 'word': 'aword1', 'abbr_hlgroup': 'StrikeFake' },
+ \ { 'word': 'δ½ ε₯½', 'abbr_hlgroup': 'StrikeFake' },
+ \]}
+ endif
return {
\ 'words': [
\ { 'word': 'aword1', 'menu': 'extra text 1', 'kind': 'W', 'abbr_hlgroup': 'StrikeFake' },
@@ -1520,6 +1528,9 @@ func Test_pum_user_abbr_hlgroup()
\ { 'word': 'δ½ ε₯½', 'menu': 'extra text 3', 'kind': 'W', 'abbr_hlgroup': 'StrikeFake' },
\]}
endfunc
+ func ChangeVar()
+ let s:var = 1
+ endfunc
set completeopt=menu
set completefunc=CompleteFunc
@@ -1547,13 +1558,20 @@ func Test_pum_user_abbr_hlgroup()
call VerifyScreenDump(buf, 'Test_pum_highlights_14', {})
call term_sendkeys(buf, "\<C-E>\<Esc>")
+ call TermWait(buf)
+ call term_sendkeys(buf, ":call ChangeVar()\<CR>")
+ call TermWait(buf)
+ call term_sendkeys(buf, "S\<C-X>\<C-U>")
+ call VerifyScreenDump(buf, 'Test_pum_highlights_17', {})
+ call term_sendkeys(buf, "\<C-E>\<Esc>")
+
call StopVimInTerminal(buf)
endfunc
func Test_pum_user_kind_hlgroup()
CheckScreendump
let lines =<< trim END
- func CompleteFunc( findstart, base )
+ func CompleteFunc(findstart, base)
if a:findstart
return 0
endif
diff --git a/test/old/testdir/test_tagfunc.vim b/test/old/testdir/test_tagfunc.vim
index 812603a430..ec1f93e9be 100644
--- a/test/old/testdir/test_tagfunc.vim
+++ b/test/old/testdir/test_tagfunc.vim
@@ -291,10 +291,10 @@ func Test_tagfunc_callback()
call assert_fails("echo taglist('a')", "E987:")
" Using Vim9 lambda expression in legacy context should fail
- " set tagfunc=(a,\ b,\ c)\ =>\ g:TagFunc1(21,\ a,\ b,\ c)
+ set tagfunc=(a,\ b,\ c)\ =>\ g:TagFunc1(21,\ a,\ b,\ c)
new
let g:TagFunc1Args = []
- " call assert_fails("tag a17", "E117:")
+ call assert_fails("tag a17", "E117:")
call assert_equal([], g:TagFunc1Args)
bw!
diff --git a/test/testutil.lua b/test/testutil.lua
index a920f658a1..00b30d74d5 100644
--- a/test/testutil.lua
+++ b/test/testutil.lua
@@ -392,9 +392,7 @@ function M.check_logs()
)
end
-local function sysname()
- return uv.os_uname().sysname:lower()
-end
+local sysname = uv.os_uname().sysname:lower()
--- @param s 'win'|'mac'|'freebsd'|'openbsd'|'bsd'
--- @return boolean
@@ -403,48 +401,27 @@ function M.is_os(s)
error('unknown platform: ' .. tostring(s))
end
return not not (
- (s == 'win' and (sysname():find('windows') or sysname():find('mingw')))
- or (s == 'mac' and sysname() == 'darwin')
- or (s == 'freebsd' and sysname() == 'freebsd')
- or (s == 'openbsd' and sysname() == 'openbsd')
- or (s == 'bsd' and sysname():find('bsd'))
+ (s == 'win' and (sysname:find('windows') or sysname:find('mingw')))
+ or (s == 'mac' and sysname == 'darwin')
+ or (s == 'freebsd' and sysname == 'freebsd')
+ or (s == 'openbsd' and sysname == 'openbsd')
+ or (s == 'bsd' and sysname:find('bsd'))
)
end
-local function tmpdir_get()
- return os.getenv('TMPDIR') and os.getenv('TMPDIR') or os.getenv('TEMP')
-end
-
---- Is temp directory `dir` defined local to the project workspace?
---- @param dir string?
---- @return boolean
-local function tmpdir_is_local(dir)
- return not not (dir and dir:find('Xtest'))
-end
-
local tmpname_id = 0
-local tmpdir = tmpdir_get()
+local tmpdir = os.getenv('TMPDIR') or os.getenv('TEMP')
+local tmpdir_is_local = not not (tmpdir and tmpdir:find('Xtest'))
---- Generates a unique filepath for use by tests, in a test-specific "…/Xtest_tmpdir/T42.7"
---- directory (which is cleaned up by the test runner), and writes the file unless `create=false`.
----
----@param create? boolean (default true) Write the file.
-function M.tmpname(create)
- if tmpdir_is_local(tmpdir) then
+local function get_tmpname()
+ if tmpdir_is_local then
-- Cannot control os.tmpname() dir, so hack our own tmpname() impl.
tmpname_id = tmpname_id + 1
-- "…/Xtest_tmpdir/T42.7"
- local fname = ('%s/%s.%d'):format(tmpdir, (_G._nvim_test_id or 'nvim-test'), tmpname_id)
- if create ~= false then
- io.open(fname, 'w'):close()
- end
- return fname
+ return ('%s/%s.%d'):format(tmpdir, (_G._nvim_test_id or 'nvim-test'), tmpname_id)
end
local fname = os.tmpname()
- if create == false then
- os.remove(fname)
- end
if M.is_os('win') and fname:sub(1, 2) == '\\s' then
-- In Windows tmpname() returns a filename starting with
@@ -454,7 +431,20 @@ function M.tmpname(create)
-- In OS X /tmp links to /private/tmp
return '/private' .. fname
end
+ return fname
+end
+--- Generates a unique filepath for use by tests, in a test-specific "…/Xtest_tmpdir/T42.7"
+--- directory (which is cleaned up by the test runner).
+---
+--- @param create? boolean (default true) Create the file.
+--- @return string
+function M.tmpname(create)
+ local fname = get_tmpname()
+ os.remove(fname)
+ if create ~= false then
+ assert(io.open(fname, 'w')):close()
+ end
return fname
end
@@ -479,11 +469,11 @@ function M.check_cores(app, force) -- luacheck: ignore
local random_skip = false
-- Workspace-local $TMPDIR, scrubbed and pattern-escaped.
-- "./Xtest-tmpdir/" => "Xtest%-tmpdir"
- local local_tmpdir = (
- tmpdir_is_local(tmpdir_get())
- and relpath(tmpdir_get()):gsub('^[ ./]+', ''):gsub('%/+$', ''):gsub('([^%w])', '%%%1')
- or nil
- )
+ local local_tmpdir = nil
+ if tmpdir_is_local and tmpdir then
+ local_tmpdir = vim.pesc(relpath(tmpdir):gsub('^[ ./]+', ''):gsub('%/+$', ''))
+ end
+
local db_cmd --- @type string
local test_glob_dir = os.getenv('NVIM_TEST_CORE_GLOB_DIRECTORY')
if test_glob_dir and test_glob_dir ~= '' then