comparison src/testdir/test_syntax.vim @ 20623:99b6e6bf48bf v8.2.0865

patch 8.2.0865: syntax foldlevel is taken from the start of the line Commit: https://github.com/vim/vim/commit/e35a52aee718c881bdfa69a47a1068df6ab6c60a Author: Bram Moolenaar <Bram@vim.org> Date: Sun May 31 19:48:53 2020 +0200 patch 8.2.0865: syntax foldlevel is taken from the start of the line Problem: Syntax foldlevel is taken from the start of the line. Solution: Add ":syn foldlevel" to be able to use the minimal foldlevel in the line. (Brad King, closes #6087)
author Bram Moolenaar <Bram@vim.org>
date Sun, 31 May 2020 20:00:04 +0200
parents e82996ad131f
children 116c7bd5e980
comparison
equal deleted inserted replaced
20622:d487701a608e 20623:99b6e6bf48bf
158 bd 158 bd
159 endfunc 159 endfunc
160 160
161 func Test_syntax_completion() 161 func Test_syntax_completion()
162 call feedkeys(":syn \<C-A>\<C-B>\"\<CR>", 'tx') 162 call feedkeys(":syn \<C-A>\<C-B>\"\<CR>", 'tx')
163 call assert_equal('"syn case clear cluster conceal enable include iskeyword keyword list manual match off on region reset spell sync', @:) 163 call assert_equal('"syn case clear cluster conceal enable foldlevel include iskeyword keyword list manual match off on region reset spell sync', @:)
164 164
165 call feedkeys(":syn case \<C-A>\<C-B>\"\<CR>", 'tx') 165 call feedkeys(":syn case \<C-A>\<C-B>\"\<CR>", 'tx')
166 call assert_equal('"syn case ignore match', @:) 166 call assert_equal('"syn case ignore match', @:)
167 167
168 call feedkeys(":syn spell \<C-A>\<C-B>\"\<CR>", 'tx') 168 call feedkeys(":syn spell \<C-A>\<C-B>\"\<CR>", 'tx')
689 call delete('Xbbb.c') 689 call delete('Xbbb.c')
690 call delete('Xccc.c') 690 call delete('Xccc.c')
691 call delete('Xddd.c') 691 call delete('Xddd.c')
692 endfunc 692 endfunc
693 693
694 func Test_syntax_foldlevel()
695 new
696 call setline(1, [
697 \ 'void f(int a)',
698 \ '{',
699 \ ' if (a == 1) {',
700 \ ' a = 0;',
701 \ ' } else if (a == 2) {',
702 \ ' a = 1;',
703 \ ' } else {',
704 \ ' a = 2;',
705 \ ' }',
706 \ ' if (a > 0) {',
707 \ ' if (a == 1) {',
708 \ ' a = 0;',
709 \ ' } /* missing newline */ } /* end of outer if */ else {',
710 \ ' a = 1;',
711 \ ' }',
712 \ ' if (a == 1)',
713 \ ' {',
714 \ ' a = 0;',
715 \ ' }',
716 \ ' else if (a == 2)',
717 \ ' {',
718 \ ' a = 1;',
719 \ ' }',
720 \ ' else',
721 \ ' {',
722 \ ' a = 2;',
723 \ ' }',
724 \ '}',
725 \ ])
726 setfiletype c
727 syntax on
728 set foldmethod=syntax
729
730 call assert_fails('syn foldlevel start start', 'E390')
731 call assert_fails('syn foldlevel not_an_option', 'E390')
732
733 set foldlevel=1
734
735 syn foldlevel start
736 redir @c
737 syn foldlevel
738 redir END
739 call assert_equal("\nsyntax foldlevel start", @c)
740 syn sync fromstart
741 let a = map(range(3,9), 'foldclosed(v:val)')
742 call assert_equal([3,3,3,3,3,3,3], a) " attached cascade folds together
743 let a = map(range(10,15), 'foldclosed(v:val)')
744 call assert_equal([10,10,10,10,10,10], a) " over-attached 'else' hidden
745 let a = map(range(16,27), 'foldclosed(v:val)')
746 let unattached_results = [-1,17,17,17,-1,21,21,21,-1,25,25,25]
747 call assert_equal(unattached_results, a) " unattached cascade folds separately
748
749 syn foldlevel minimum
750 redir @c
751 syn foldlevel
752 redir END
753 call assert_equal("\nsyntax foldlevel minimum", @c)
754 syn sync fromstart
755 let a = map(range(3,9), 'foldclosed(v:val)')
756 call assert_equal([3,3,5,5,7,7,7], a) " attached cascade folds separately
757 let a = map(range(10,15), 'foldclosed(v:val)')
758 call assert_equal([10,10,10,13,13,13], a) " over-attached 'else' visible
759 let a = map(range(16,27), 'foldclosed(v:val)')
760 call assert_equal(unattached_results, a) " unattached cascade folds separately
761
762 set foldlevel=2
763
764 syn foldlevel start
765 syn sync fromstart
766 let a = map(range(11,14), 'foldclosed(v:val)')
767 call assert_equal([11,11,11,-1], a) " over-attached 'else' hidden
768
769 syn foldlevel minimum
770 syn sync fromstart
771 let a = map(range(11,14), 'foldclosed(v:val)')
772 call assert_equal([11,11,-1,-1], a) " over-attached 'else' visible
773
774 quit!
775 endfunc
776
694 " vim: shiftwidth=2 sts=2 expandtab 777 " vim: shiftwidth=2 sts=2 expandtab