summaryrefslogtreecommitdiffstats
path: root/src/testdir/test_fold.vim
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-20 03:56:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-20 03:56:58 +0000
commit0f75b2ad2e23107f8112b6dcd4785eeef6cc34aa (patch)
tree25185226a8d172d94b0ff72f5a611659252c76d6 /src/testdir/test_fold.vim
parentReleasing progress-linux version 2:9.1.0377-1~progress7.99u1. (diff)
downloadvim-0f75b2ad2e23107f8112b6dcd4785eeef6cc34aa.tar.xz
vim-0f75b2ad2e23107f8112b6dcd4785eeef6cc34aa.zip
Merging upstream version 2:9.1.0496.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--src/testdir/test_fold.vim127
1 files changed, 125 insertions, 2 deletions
diff --git a/src/testdir/test_fold.vim b/src/testdir/test_fold.vim
index 3c78e62..dedc4a2 100644
--- a/src/testdir/test_fold.vim
+++ b/src/testdir/test_fold.vim
@@ -8,7 +8,73 @@ func PrepIndent(arg)
return [a:arg] + repeat(["\t".a:arg], 5)
endfu
-func Test_address_fold()
+func Test_address_fold_new_default_commentstring()
+ " Test with the new commentstring defaults, that includes padding after v9.1.464
+ new
+ call setline(1, ['int FuncName() {/* {{{ */', 1, 2, 3, 4, 5, '}/* }}} */',
+ \ 'after fold 1', 'after fold 2', 'after fold 3'])
+ setl fen fdm=marker
+ " The next commands should all copy the same part of the buffer,
+ " regardless of the addressing type, since the part to be copied
+ " is folded away
+ :1y
+ call assert_equal(['int FuncName() {/* {{{ */', '1', '2', '3', '4', '5', '}/* }}} */'], getreg(0,1,1))
+ :.y
+ call assert_equal(['int FuncName() {/* {{{ */', '1', '2', '3', '4', '5', '}/* }}} */'], getreg(0,1,1))
+ :.+y
+ call assert_equal(['int FuncName() {/* {{{ */', '1', '2', '3', '4', '5', '}/* }}} */'], getreg(0,1,1))
+ :.,.y
+ call assert_equal(['int FuncName() {/* {{{ */', '1', '2', '3', '4', '5', '}/* }}} */'], getreg(0,1,1))
+ :sil .1,.y
+ call assert_equal(['int FuncName() {/* {{{ */', '1', '2', '3', '4', '5', '}/* }}} */'], getreg(0,1,1))
+ " use silent to make E493 go away
+ :sil .+,.y
+ call assert_equal(['int FuncName() {/* {{{ */', '1', '2', '3', '4', '5', '}/* }}} */'], getreg(0,1,1))
+ :,y
+ call assert_equal(['int FuncName() {/* {{{ */', '1', '2', '3', '4', '5', '}/* }}} */'], getreg(0,1,1))
+ :,+y
+ call assert_equal(['int FuncName() {/* {{{ */', '1', '2', '3', '4', '5', '}/* }}} */','after fold 1'], getreg(0,1,1))
+ " using .+3 as second address should c opy the whole folded line + the next 3
+ " lines
+ :.,+3y
+ call assert_equal(['int FuncName() {/* {{{ */', '1', '2', '3', '4', '5', '}/* }}} */',
+ \ 'after fold 1', 'after fold 2' , 'after fold 3'], getreg(0,1,1))
+ :sil .,-2y
+ call assert_equal(['int FuncName() {/* {{{ */', '1', '2', '3', '4', '5', '}/* }}} */'], getreg(0,1,1))
+
+ " now test again with folding disabled
+ set nofoldenable
+ :1y
+ call assert_equal(['int FuncName() {/* {{{ */'], getreg(0,1,1))
+ :.y
+ call assert_equal(['int FuncName() {/* {{{ */'], getreg(0,1,1))
+ :.+y
+ call assert_equal(['1'], getreg(0,1,1) )
+ :.,.y
+ call assert_equal(['int FuncName() {/* {{{ */'], getreg(0,1,1))
+ " use silent to make E493 go away
+ :sil .1,.y
+ call assert_equal(['int FuncName() {/* {{{ */', '1'], getreg(0,1,1))
+ " use silent to make E493 go away
+ :sil .+,.y
+ call assert_equal(['int FuncName() {/* {{{ */', '1'], getreg(0,1,1))
+ :,y
+ call assert_equal(['int FuncName() {/* {{{ */'], getreg(0,1,1))
+ :,+y
+ call assert_equal(['int FuncName() {/* {{{ */', '1'], getreg(0,1,1))
+ " using .+3 as second address should c opy the whole folded line + the next 3
+ " lines
+ :.,+3y
+ call assert_equal(['int FuncName() {/* {{{ */', '1', '2', '3'], getreg(0,1,1))
+ :7
+ :sil .,-2y
+ call assert_equal(['4', '5', '}/* }}} */'], getreg(0,1,1))
+
+ quit!
+endfunc
+
+func Test_address_fold_old_default_commentstring()
+ " Test with the old commentstring defaults, before v9.1.464
new
call setline(1, ['int FuncName() {/*{{{*/', 1, 2, 3, 4, 5, '}/*}}}*/',
\ 'after fold 1', 'after fold 2', 'after fold 3'])
@@ -719,7 +785,7 @@ func Test_fold_create_marker_in_C()
call append(0, content)
call cursor(c + 1, 1)
norm! zfG
- call assert_equal(content[c] . (c < 4 ? '{{{' : '/*{{{*/'), getline(c + 1))
+ call assert_equal(content[c] . (c < 4 ? '{{{' : '/* {{{ */'), getline(c + 1))
endfor
set fdm& fdl&
@@ -1601,6 +1667,63 @@ func Test_foldtext_scriptlocal_func()
delfunc s:FoldText
endfunc
+" Test for setting 'foldtext' from the modeline and executing the expression
+" in a sandbox
+func Test_foldtext_in_modeline()
+ func ModelineFoldText()
+ call feedkeys('aFoo', 'xt')
+ return "folded text"
+ endfunc
+ let lines =<< trim END
+ func T()
+ let i = 1
+ endfunc
+ " vim: foldenable foldtext=ModelineFoldText()
+ END
+ call writefile(lines, 'Xmodelinefoldtext', 'D')
+
+ set modeline modelineexpr
+ split Xmodelinefoldtext
+
+ call cursor(1, 1)
+ normal! zf3j
+ call assert_equal('folded text', foldtextresult(1))
+ call assert_equal(lines, getbufline('', 1, '$'))
+
+ bw!
+ set modeline& modelineexpr&
+ delfunc ModelineFoldText
+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
" foldmethod=indent
func Test_fold_split()