comparison 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
comparison
equal deleted inserted replaced
12749:8b706a156136 12750:0b6c09957b43
458 call assert_equal(1, foldlevel(2)) 458 call assert_equal(1, foldlevel(2))
459 call assert_equal(1, foldclosed(2)) 459 call assert_equal(1, foldclosed(2))
460 call assert_equal(3, foldclosedend(2)) 460 call assert_equal(3, foldclosedend(2))
461 bwipe! 461 bwipe!
462 endfunc 462 endfunc
463
464 " Various fold related tests
465
466 " Basic test if a fold can be created, opened, moving to the end and closed
467 func Test_fold_manual()
468 enew!
469 set fdm=manual
470
471 let content = ['1 aa', '2 bb', '3 cc']
472 call append(0, content)
473 call cursor(1, 1)
474 normal zf2j
475 call assert_equal('1 aa', getline(foldclosed('.')))
476 normal zo
477 call assert_equal(-1, foldclosed('.'))
478 normal ]z
479 call assert_equal('3 cc', getline('.'))
480 normal zc
481 call assert_equal('1 aa', getline(foldclosed('.')))
482
483 set fdm&
484 enew!
485 endfunc
486
487 " test folding with markers.
488 func Test_fold_marker()
489 enew!
490 set fdm=marker fdl=1 fdc=3
491
492 let content = ['4 dd {{{', '5 ee {{{ }}}', '6 ff }}}']
493 call append(0, content)
494 call cursor(2, 1)
495 call assert_equal(2, foldlevel('.'))
496 normal [z
497 call assert_equal(1, foldlevel('.'))
498 exe "normal jo{{ \<Esc>r{jj"
499 call assert_equal(1, foldlevel('.'))
500 normal kYpj
501 call assert_equal(0, foldlevel('.'))
502
503 set fdm& fdl& fdc&
504 enew!
505 endfunc
506
507 " test folding with indent
508 func Test_fold_indent()
509 enew!
510 set fdm=indent sw=2
511
512 let content = ['1 aa', '2 bb', '3 cc']
513 call append(0, content)
514 call cursor(2, 1)
515 exe "normal i \<Esc>jI "
516 call assert_equal(2, foldlevel('.'))
517 normal k
518 call assert_equal(1, foldlevel('.'))
519
520 set fdm& sw&
521 enew!
522 endfunc
523
524 " test syntax folding
525 func Test_fold_syntax()
526 if !has('syntax')
527 return
528 endif
529
530 enew!
531 set fdm=syntax fdl=0
532
533 syn region Hup start="dd" end="ii" fold contains=Fd1,Fd2,Fd3
534 syn region Fd1 start="ee" end="ff" fold contained
535 syn region Fd2 start="gg" end="hh" fold contained
536 syn region Fd3 start="commentstart" end="commentend" fold contained
537 let content = ['3 cc', '4 dd {{{', '5 ee {{{ }}}', '{{{{', '6 ff }}}',
538 \ '6 ff }}}', '7 gg', '8 hh', '9 ii']
539 call append(0, content)
540 normal Gzk
541 call assert_equal('9 ii', getline('.'))
542 normal k
543 call assert_equal('3 cc', getline('.'))
544 exe "normal jAcommentstart \<Esc>Acommentend"
545 set fdl=1
546 normal 3j
547 call assert_equal('7 gg', getline('.'))
548 set fdl=0
549 exe "normal zO\<C-L>j"
550 call assert_equal('8 hh', getline('.'))
551 syn clear Fd1 Fd2 Fd3 Hup
552
553 set fdm& fdl&
554 enew!
555 endfunc
556
557 func Flvl()
558 let l = getline(v:lnum)
559 if l =~ "bb$"
560 return 2
561 elseif l =~ "gg$"
562 return "s1"
563 elseif l =~ "ii$"
564 return ">2"
565 elseif l =~ "kk$"
566 return "0"
567 endif
568 return "="
569 endfun
570
571 " test expression folding
572 func Test_fold_expr()
573 enew!
574 set fdm=expr fde=Flvl()
575
576 let content = ['1 aa',
577 \ '2 bb',
578 \ '3 cc',
579 \ '4 dd {{{commentstart commentend',
580 \ '5 ee {{{ }}}',
581 \ '{{{',
582 \ '6 ff }}}',
583 \ '6 ff }}}',
584 \ ' 7 gg',
585 \ ' 8 hh',
586 \ '9 ii',
587 \ 'a jj',
588 \ 'b kk']
589 call append(0, content)
590 call cursor(1, 1)
591 exe "normal /bb$\<CR>"
592 call assert_equal(2, foldlevel('.'))
593 exe "normal /hh$\<CR>"
594 call assert_equal(1, foldlevel('.'))
595 exe "normal /ii$\<CR>"
596 call assert_equal(2, foldlevel('.'))
597 exe "normal /kk$\<CR>"
598 call assert_equal(0, foldlevel('.'))
599
600 set fdm& fde&
601 enew!
602 endfunc
603
604 " Bug with fdm=indent and moving folds
605 " Moving a fold a few times, messes up the folds below the moved fold.
606 " Fixed by 7.4.700
607 func Test_fold_move()
608 enew!
609 set fdm=indent sw=2 fdl=0
610
611 let content = ['', '', 'Line1', ' Line2', ' Line3',
612 \ 'Line4', ' Line5', ' Line6',
613 \ 'Line7', ' Line8', ' Line9']
614 call append(0, content)
615 normal zM
616 call cursor(4, 1)
617 move 2
618 move 1
619 call assert_equal(7, foldclosed(7))
620 call assert_equal(8, foldclosedend(7))
621 call assert_equal(0, foldlevel(9))
622 call assert_equal(10, foldclosed(10))
623 call assert_equal(11, foldclosedend(10))
624 call assert_equal('+-- 2 lines: Line2', foldtextresult(2))
625 call assert_equal('+-- 2 lines: Line8', foldtextresult(10))
626
627 set fdm& sw& fdl&
628 enew!
629 endfunc