diff options
author | zeertzjq <zeertzjq@outlook.com> | 2024-10-29 09:01:46 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-29 09:01:46 +0800 |
commit | 0e32c480604d76a319602656f2d8e2722497606e (patch) | |
tree | b18deb6eaae322957f27ae87e134f7c8bb3ee5e9 /test/old/testdir | |
parent | 42fa3d080ec170b7927e36ec563efdd526c712d7 (diff) | |
parent | 60b3ccd850ca038af6fc0a19cad12578f63d67ec (diff) | |
download | rneovim-0e32c480604d76a319602656f2d8e2722497606e.tar.gz rneovim-0e32c480604d76a319602656f2d8e2722497606e.tar.bz2 rneovim-0e32c480604d76a319602656f2d8e2722497606e.zip |
Merge pull request #30979 from zeertzjq/vim-9.1.0810
vim-patch:9.1.{0810,0811,0821}: 'findexpr'
Diffstat (limited to 'test/old/testdir')
-rw-r--r-- | test/old/testdir/test_findfile.vim | 221 | ||||
-rw-r--r-- | test/old/testdir/test_modeline.vim | 1 | ||||
-rw-r--r-- | test/old/testdir/test_options.vim | 2 |
3 files changed, 223 insertions, 1 deletions
diff --git a/test/old/testdir/test_findfile.vim b/test/old/testdir/test_findfile.vim index 06d781ed69..d3fdcad045 100644 --- a/test/old/testdir/test_findfile.vim +++ b/test/old/testdir/test_findfile.vim @@ -1,5 +1,7 @@ " Test findfile() and finddir() +source check.vim + let s:files = [ 'Xfinddir1/foo', \ 'Xfinddir1/bar', \ 'Xfinddir1/Xdir2/foo', @@ -286,4 +288,223 @@ func Test_find_non_existing_path() let &path = save_path endfunc +" Test for 'findexpr' +func Test_findexpr() + CheckUnix + call assert_equal('', &findexpr) + call writefile(['aFile'], 'Xfindexpr1.c', 'D') + call writefile(['bFile'], 'Xfindexpr2.c', 'D') + call writefile(['cFile'], 'Xfindexpr3.c', 'D') + + " basic tests + func FindExpr1() + let fnames = ['Xfindexpr1.c', 'Xfindexpr2.c', 'Xfindexpr3.c'] + return fnames->copy()->filter('v:val =~? v:fname') + endfunc + + set findexpr=FindExpr1() + find Xfindexpr3 + call assert_match('Xfindexpr3.c', @%) + bw! + 2find Xfind + call assert_match('Xfindexpr2.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', @%) + 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', @%) + call assert_equal(2, tabpagenr()) + %bw! + call assert_fails('tabfind foobar', 'E345: Can''t find file "foobar" in path') + + " Buffer-local option + set findexpr=['abc'] + new + setlocal findexpr=['def'] + find xxxx + call assert_equal('def', @%) + wincmd w + find xxxx + call assert_equal('abc', @%) + aboveleft new + call assert_equal("['abc']", &findexpr) + wincmd k + aboveleft new + call assert_equal("['abc']", &findexpr) + %bw! + + " Empty list + set findexpr=[] + call assert_fails('find xxxx', 'E345: Can''t find file "xxxx" in path') + + " Error cases + + " Syntax error in the expression + set findexpr=FindExpr1{} + call assert_fails('find Xfindexpr1.c', 'E15: Invalid expression') + + " Find expression throws an error + func FindExpr2() + throw 'find error' + endfunc + set findexpr=FindExpr2() + call assert_fails('find Xfindexpr1.c', 'find error') + + " 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 to create a new window from the find expression + func FindExpr3() + new + return ["foo"] + endfunc + set findexpr=FindExpr3() + call assert_fails('find Xfindexpr1.c', 'E565: Not allowed to change text or change window') + + " Try to modify the current buffer from the find expression + func FindExpr4() + 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 +endfunc + +" Test for using a script-local function for 'findexpr' +func Test_findexpr_scriptlocal_func() + func! s:FindExprScript() + let g:FindExprArg = v:fname + return ['xxx'] + endfunc + + set findexpr=s:FindExprScript() + call assert_equal(expand('<SID>') .. 'FindExprScript()', &findexpr) + call assert_equal(expand('<SID>') .. 'FindExprScript()', &g:findexpr) + new | only + let g:FindExprArg = '' + find abc + call assert_equal('abc', g:FindExprArg) + bw! + + set findexpr=<SID>FindExprScript() + call assert_equal(expand('<SID>') .. 'FindExprScript()', &findexpr) + call assert_equal(expand('<SID>') .. 'FindExprScript()', &g:findexpr) + new | only + let g:FindExprArg = '' + find abc + call assert_equal('abc', g:FindExprArg) + bw! + + let &findexpr = 's:FindExprScript()' + call assert_equal(expand('<SID>') .. 'FindExprScript()', &g:findexpr) + new | only + let g:FindExprArg = '' + find abc + call assert_equal('abc', g:FindExprArg) + bw! + + let &findexpr = '<SID>FindExprScript()' + call assert_equal(expand('<SID>') .. 'FindExprScript()', &g:findexpr) + new | only + let g:FindExprArg = '' + find abc + call assert_equal('abc', g:FindExprArg) + 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 = '' + find abc + call assert_equal('abc', g:FindExprArg) + 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 = '' + find abc + call assert_equal('abc', g:FindExprArg) + bw! + + set findexpr= + delfunc s:FindExprScript +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'] + + " 'findexpr' that accepts a regular expression + func FindExprRegexp() + return s:fnames->copy()->filter('v:val =~? v:fname') + endfunc + + " 'findexpr' that accepts a glob + func FindExprGlob() + let pat = glob2regpat(v:cmdcomplete ? $'*{v:fname}*' : v:fname) + return s:fnames->copy()->filter('v:val =~? pat') + endfunc + + for regexp in [v:true, v:false] + let &findexpr = regexp ? 'FindExprRegexp()' : 'FindExprGlob()' + + call feedkeys(":find \<Tab>\<C-B>\"\<CR>", "xt") + call assert_equal('"find Xfindexpr1.c', @:) + + call feedkeys(":find Xfind\<Tab>\<Tab>\<C-B>\"\<CR>", "xt") + call assert_equal('"find Xfindexpr2.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 feedkeys(":find 3\<Tab>\<C-B>\"\<CR>", "xt") + call assert_equal('"find Xfindexpr3.c', @:) + call assert_equal(['Xfindexpr3.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 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 + unlet s:fnames +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/test/old/testdir/test_modeline.vim b/test/old/testdir/test_modeline.vim index 487a89e038..7b7163d372 100644 --- a/test/old/testdir/test_modeline.vim +++ b/test/old/testdir/test_modeline.vim @@ -217,6 +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('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_options.vim b/test/old/testdir/test_options.vim index ba93778404..6902560518 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'] + for opt in ['backupdir', 'cdpath', 'exrc', 'findexpr'] call assert_fails('sandbox set ' .. opt .. '?', 'E48:') call assert_fails('sandbox let &' .. opt .. ' = 1', 'E48:') endfor |