diff options
author | Bram Moolenaar <Bram@vim.org> | 2017-11-02 21:04:47 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2017-11-02 21:04:47 +0100 |
commit | 430dc5d360166ca5bb6a73f2c87ae53e09282ecb (patch) | |
tree | 476135bdc6d06c93ae3ab9baa27e50d35c2a7796 /src/testdir/test_fold.vim | |
parent | 8889a5c305e69aa49fd08036e624e365097a5b7b (diff) | |
download | vim-git-430dc5d360166ca5bb6a73f2c87ae53e09282ecb.tar.gz |
patch 8.0.1253: still too many old style testsv8.0.1253
Problem: Still too many old style tests.
Solution: Convert a few more tests to new style. (Yegappan Lakshmanan,
closes #2272)
Diffstat (limited to 'src/testdir/test_fold.vim')
-rw-r--r-- | src/testdir/test_fold.vim | 167 |
1 files changed, 167 insertions, 0 deletions
diff --git a/src/testdir/test_fold.vim b/src/testdir/test_fold.vim index b6ba99c56..5ebf38f7a 100644 --- a/src/testdir/test_fold.vim +++ b/src/testdir/test_fold.vim @@ -460,3 +460,170 @@ func Test_foldtext_recursive() call assert_equal(3, foldclosedend(2)) bwipe! endfunc + +" Various fold related tests + +" Basic test if a fold can be created, opened, moving to the end and closed +func Test_fold_manual() + enew! + set fdm=manual + + let content = ['1 aa', '2 bb', '3 cc'] + call append(0, content) + call cursor(1, 1) + normal zf2j + call assert_equal('1 aa', getline(foldclosed('.'))) + normal zo + call assert_equal(-1, foldclosed('.')) + normal ]z + call assert_equal('3 cc', getline('.')) + normal zc + call assert_equal('1 aa', getline(foldclosed('.'))) + + set fdm& + enew! +endfunc + +" test folding with markers. +func Test_fold_marker() + enew! + set fdm=marker fdl=1 fdc=3 + + let content = ['4 dd {{{', '5 ee {{{ }}}', '6 ff }}}'] + call append(0, content) + call cursor(2, 1) + call assert_equal(2, foldlevel('.')) + normal [z + call assert_equal(1, foldlevel('.')) + exe "normal jo{{ \<Esc>r{jj" + call assert_equal(1, foldlevel('.')) + normal kYpj + call assert_equal(0, foldlevel('.')) + + set fdm& fdl& fdc& + enew! +endfunc + +" test folding with indent +func Test_fold_indent() + enew! + set fdm=indent sw=2 + + let content = ['1 aa', '2 bb', '3 cc'] + call append(0, content) + call cursor(2, 1) + exe "normal i \<Esc>jI " + call assert_equal(2, foldlevel('.')) + normal k + call assert_equal(1, foldlevel('.')) + + set fdm& sw& + enew! +endfunc + +" test syntax folding +func Test_fold_syntax() + if !has('syntax') + return + endif + + enew! + set fdm=syntax fdl=0 + + syn region Hup start="dd" end="ii" fold contains=Fd1,Fd2,Fd3 + syn region Fd1 start="ee" end="ff" fold contained + syn region Fd2 start="gg" end="hh" fold contained + syn region Fd3 start="commentstart" end="commentend" fold contained + let content = ['3 cc', '4 dd {{{', '5 ee {{{ }}}', '{{{{', '6 ff }}}', + \ '6 ff }}}', '7 gg', '8 hh', '9 ii'] + call append(0, content) + normal Gzk + call assert_equal('9 ii', getline('.')) + normal k + call assert_equal('3 cc', getline('.')) + exe "normal jAcommentstart \<Esc>Acommentend" + set fdl=1 + normal 3j + call assert_equal('7 gg', getline('.')) + set fdl=0 + exe "normal zO\<C-L>j" + call assert_equal('8 hh', getline('.')) + syn clear Fd1 Fd2 Fd3 Hup + + set fdm& fdl& + enew! +endfunc + +func Flvl() + let l = getline(v:lnum) + if l =~ "bb$" + return 2 + elseif l =~ "gg$" + return "s1" + elseif l =~ "ii$" + return ">2" + elseif l =~ "kk$" + return "0" + endif + return "=" +endfun + +" test expression folding +func Test_fold_expr() + enew! + set fdm=expr fde=Flvl() + + let content = ['1 aa', + \ '2 bb', + \ '3 cc', + \ '4 dd {{{commentstart commentend', + \ '5 ee {{{ }}}', + \ '{{{', + \ '6 ff }}}', + \ '6 ff }}}', + \ ' 7 gg', + \ ' 8 hh', + \ '9 ii', + \ 'a jj', + \ 'b kk'] + call append(0, content) + call cursor(1, 1) + exe "normal /bb$\<CR>" + call assert_equal(2, foldlevel('.')) + exe "normal /hh$\<CR>" + call assert_equal(1, foldlevel('.')) + exe "normal /ii$\<CR>" + call assert_equal(2, foldlevel('.')) + exe "normal /kk$\<CR>" + call assert_equal(0, foldlevel('.')) + + set fdm& fde& + enew! +endfunc + +" Bug with fdm=indent and moving folds +" Moving a fold a few times, messes up the folds below the moved fold. +" Fixed by 7.4.700 +func Test_fold_move() + enew! + set fdm=indent sw=2 fdl=0 + + let content = ['', '', 'Line1', ' Line2', ' Line3', + \ 'Line4', ' Line5', ' Line6', + \ 'Line7', ' Line8', ' Line9'] + call append(0, content) + normal zM + call cursor(4, 1) + move 2 + move 1 + call assert_equal(7, foldclosed(7)) + call assert_equal(8, foldclosedend(7)) + call assert_equal(0, foldlevel(9)) + call assert_equal(10, foldclosed(10)) + call assert_equal(11, foldclosedend(10)) + call assert_equal('+-- 2 lines: Line2', foldtextresult(2)) + call assert_equal('+-- 2 lines: Line8', foldtextresult(10)) + + set fdm& sw& fdl& + enew! +endfunc |