diff src/testdir/test_fold.vim @ 12750:0b6c09957b43 v8.0.1253

patch 8.0.1253: still too many old style tests commit https://github.com/vim/vim/commit/430dc5d360166ca5bb6a73f2c87ae53e09282ecb Author: Bram Moolenaar <Bram@vim.org> Date: Thu Nov 2 21:04:47 2017 +0100 patch 8.0.1253: still too many old style tests Problem: Still too many old style tests. Solution: Convert a few more tests to new style. (Yegappan Lakshmanan, closes #2272)
author Christian Brabandt <cb@256bit.org>
date Thu, 02 Nov 2017 21:15:05 +0100
parents f6534b99b76f
children cb9b2774f21f
line wrap: on
line diff
--- 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