vim-patch:9.1.0419: eval.c not sufficiently tested

Problem:  eval.c not sufficiently tested
Solution: Add a few more additional tests for eval.c,
          (Yegappan Lakshmanan)

closes: vim/vim#14799

4776e64e72

Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
This commit is contained in:
zeertzjq
2024-07-31 09:39:31 +08:00
parent 619cb143f9
commit 30f85fcb7f
5 changed files with 57 additions and 14 deletions

View File

@@ -21,5 +21,4 @@ func Test_source_autoload()
call assert_equal(1, g:loaded_sourced_vim) call assert_equal(1, g:loaded_sourced_vim)
endfunc endfunc
" vim: shiftwidth=2 sts=2 expandtab " vim: shiftwidth=2 sts=2 expandtab

View File

@@ -1497,6 +1497,35 @@ func Test_foldtext_in_modeline()
delfunc ModelineFoldText delfunc ModelineFoldText
endfunc endfunc
" Test for setting 'foldexpr' from the modeline and executing the expression
" in a sandbox
func Test_foldexpr_in_modeline()
func ModelineFoldExpr()
call feedkeys('aFoo', 'xt')
return strlen(matchstr(getline(v:lnum),'^\s*'))
endfunc
let lines =<< trim END
aaa
bbb
ccc
ccc
bbb
aaa
" vim: foldenable foldmethod=expr foldexpr=ModelineFoldExpr()
END
call writefile(lines, 'Xmodelinefoldexpr', 'D')
set modeline modelineexpr
split Xmodelinefoldexpr
call assert_equal(2, foldlevel(3))
call assert_equal(lines, getbufline('', 1, '$'))
bw!
set modeline& modelineexpr&
delfunc ModelineFoldExpr
endfunc
" Make sure a fold containing a nested fold is split correctly when using " Make sure a fold containing a nested fold is split correctly when using
" foldmethod=indent " foldmethod=indent
func Test_fold_split() func Test_fold_split()

View File

@@ -11,15 +11,15 @@ func Test_spellrareword()
" Create a small word list to test that spellbadword('...') " Create a small word list to test that spellbadword('...')
" can return ['...', 'rare']. " can return ['...', 'rare'].
let lines =<< trim END let lines =<< trim END
foo foo
foobar/? foobar/?
foobara/? foobara/?
END END
call writefile(lines, 'Xwords', 'D') call writefile(lines, 'Xwords', 'D')
mkspell! Xwords.spl Xwords mkspell! Xwords.spl Xwords
set spelllang=Xwords.spl set spelllang=Xwords.spl
call assert_equal(['foobar', 'rare'], spellbadword('foo foobar')) call assert_equal(['foobar', 'rare'], spellbadword('foo foobar'))
new new
call setline(1, ['foo', '', 'foo bar foo bar foobara foo foo foo foobar', '', 'End']) call setline(1, ['foo', '', 'foo bar foo bar foobara foo foo foo foobar', '', 'End'])

View File

@@ -1507,4 +1507,18 @@ func Test_substitute_expr_recursive()
exe bufnr .. "bw!" exe bufnr .. "bw!"
endfunc endfunc
" Test for changing 'cpo' in a substitute expression
func Test_substitute_expr_cpo()
func XSubExpr()
set cpo=
return 'x'
endfunc
let save_cpo = &cpo
call assert_equal('xxx', substitute('abc', '.', '\=XSubExpr()', 'g'))
call assert_equal(save_cpo, &cpo)
delfunc XSubExpr
endfunc
" vim: shiftwidth=2 sts=2 expandtab " vim: shiftwidth=2 sts=2 expandtab

View File

@@ -7450,12 +7450,13 @@ func Test_for_over_string()
endfor endfor
call assert_equal('', res) call assert_equal('', res)
" Test for ignoring loop var assignment " Test for using "_" as the loop variable
let c = 0 let i = 0
for _ in 'abc' let s = 'abc'
let c += 1 for _ in s
call assert_equal(s[i], _)
let i += 1
endfor endfor
call assert_equal(3, c)
endfunc endfunc
" Test for deeply nested :source command {{{1 " Test for deeply nested :source command {{{1