mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +00:00 
			
		
		
		
	vim-patch:8.2.2713: folding code not sufficiently tested
Problem:    Folding code not sufficiently tested.
Solution:   Add a few more test cases. (Yegappan Lakshmanan, closes vim/vim#8064)
68ffe8cade
			
			
This commit is contained in:
		| @@ -565,6 +565,60 @@ func Test_fold_manual() | |||||||
|   normal zc |   normal zc | ||||||
|   call assert_equal('1 aa', getline(foldclosed('.'))) |   call assert_equal('1 aa', getline(foldclosed('.'))) | ||||||
|  |  | ||||||
|  |   " Create a fold inside a closed fold after setting 'foldlevel' | ||||||
|  |   %d _ | ||||||
|  |   call setline(1, range(1, 5)) | ||||||
|  |   1,5fold | ||||||
|  |   normal zR | ||||||
|  |   2,4fold | ||||||
|  |   set foldlevel=1 | ||||||
|  |   3fold | ||||||
|  |   call assert_equal([1, 3, 3, 3, 1], map(range(1, 5), {->foldlevel(v:val)})) | ||||||
|  |   set foldlevel& | ||||||
|  |  | ||||||
|  |   " Create overlapping folds (at the start and at the end) | ||||||
|  |   normal zE | ||||||
|  |   2,3fold | ||||||
|  |   normal zR | ||||||
|  |   3,4fold | ||||||
|  |   call assert_equal([0, 2, 2, 1, 0], map(range(1, 5), {->foldlevel(v:val)})) | ||||||
|  |   normal zE | ||||||
|  |   3,4fold | ||||||
|  |   normal zR | ||||||
|  |   2,3fold | ||||||
|  |   call assert_equal([0, 1, 2, 2, 0], map(range(1, 5), {->foldlevel(v:val)})) | ||||||
|  |  | ||||||
|  |   " Create a nested fold across two non-adjoining folds | ||||||
|  |   %d _ | ||||||
|  |   call setline(1, range(1, 7)) | ||||||
|  |   1,2fold | ||||||
|  |   normal zR | ||||||
|  |   4,5fold | ||||||
|  |   normal zR | ||||||
|  |   6,7fold | ||||||
|  |   normal zR | ||||||
|  |   1,5fold | ||||||
|  |   call assert_equal([2, 2, 1, 2, 2, 1, 1], | ||||||
|  |         \ map(range(1, 7), {->foldlevel(v:val)})) | ||||||
|  |  | ||||||
|  |   " A newly created nested fold should be closed | ||||||
|  |   %d _ | ||||||
|  |   call setline(1, range(1, 6)) | ||||||
|  |   1,6fold | ||||||
|  |   normal zR | ||||||
|  |   3,4fold | ||||||
|  |   normal zR | ||||||
|  |   2,5fold | ||||||
|  |   call assert_equal([1, 2, 3, 3, 2, 1], map(range(1, 6), {->foldlevel(v:val)})) | ||||||
|  |   call assert_equal(2, foldclosed(4)) | ||||||
|  |   call assert_equal(5, foldclosedend(4)) | ||||||
|  |  | ||||||
|  |   " Test zO, zC and zA on a line with no folds. | ||||||
|  |   normal zE | ||||||
|  |   call assert_fails('normal zO', 'E490:') | ||||||
|  |   call assert_fails('normal zC', 'E490:') | ||||||
|  |   call assert_fails('normal zA', 'E490:') | ||||||
|  |  | ||||||
|   set fdm& |   set fdm& | ||||||
|   bw! |   bw! | ||||||
| endfunc | endfunc | ||||||
| @@ -884,6 +938,30 @@ func Test_fold_delete_first_line() | |||||||
|   set foldmethod& |   set foldmethod& | ||||||
| endfunc | endfunc | ||||||
|  |  | ||||||
|  | " Add a test for deleting the outer fold of a nested fold and promoting the | ||||||
|  | " inner folds to one level up with already a fold at that level following the | ||||||
|  | " nested fold. | ||||||
|  | func Test_fold_delete_recursive_fold() | ||||||
|  |   new | ||||||
|  |   call setline(1, range(1, 7)) | ||||||
|  |   2,3fold | ||||||
|  |   normal zR | ||||||
|  |   4,5fold | ||||||
|  |   normal zR | ||||||
|  |   1,5fold | ||||||
|  |   normal zR | ||||||
|  |   6,7fold | ||||||
|  |   normal zR | ||||||
|  |   normal 1Gzd | ||||||
|  |   normal 1Gzj | ||||||
|  |   call assert_equal(2, line('.')) | ||||||
|  |   normal zj | ||||||
|  |   call assert_equal(4, line('.')) | ||||||
|  |   normal zj | ||||||
|  |   call assert_equal(6, line('.')) | ||||||
|  |   bw! | ||||||
|  | endfunc | ||||||
|  |  | ||||||
| " Test for errors in 'foldexpr' | " Test for errors in 'foldexpr' | ||||||
| func Test_fold_expr_error() | func Test_fold_expr_error() | ||||||
|   new |   new | ||||||
| @@ -1075,6 +1153,10 @@ func Test_foldclose_opt() | |||||||
|   call term_sendkeys(buf, "1G") |   call term_sendkeys(buf, "1G") | ||||||
|   call WaitForAssert({-> assert_equal('four', term_getline(buf, 3))}) |   call WaitForAssert({-> assert_equal('four', term_getline(buf, 3))}) | ||||||
|   call term_sendkeys(buf, ":call XsaveFoldLevels()\n") |   call term_sendkeys(buf, ":call XsaveFoldLevels()\n") | ||||||
|  |   call term_sendkeys(buf, "2G") | ||||||
|  |   call WaitForAssert({-> assert_equal('two', term_getline(buf, 2))}) | ||||||
|  |   call term_sendkeys(buf, "k") | ||||||
|  |   call WaitForAssert({-> assert_equal('four', term_getline(buf, 3))}) | ||||||
|  |  | ||||||
|   " clean up |   " clean up | ||||||
|   call StopVimInTerminal(buf) |   call StopVimInTerminal(buf) | ||||||
| @@ -1153,6 +1235,44 @@ func Test_fold_move_foldlevel() | |||||||
|   bw! |   bw! | ||||||
| endfunc | endfunc | ||||||
|  |  | ||||||
|  | " Test for using zj and zk to move downwards and upwards to the start and end | ||||||
|  | " of the next fold. | ||||||
|  | " Test for using [z and ]z in a closed fold to jump to the beginning and end | ||||||
|  | " of the fold. | ||||||
|  | func Test_fold_jump() | ||||||
|  |   new | ||||||
|  |   call setline(1, ["\t1", "\t2", "\t\t3", "\t\t4", "\t\t\t5", "\t\t\t6", "\t\t7", "\t\t8", "\t9", "\t10"]) | ||||||
|  |   setlocal foldmethod=indent | ||||||
|  |   normal zR | ||||||
|  |   normal zj | ||||||
|  |   call assert_equal(3, line('.')) | ||||||
|  |   normal zj | ||||||
|  |   call assert_equal(5, line('.')) | ||||||
|  |   call assert_beeps('normal zj') | ||||||
|  |   call assert_equal(5, line('.')) | ||||||
|  |   call assert_beeps('normal 9Gzj') | ||||||
|  |   call assert_equal(9, line('.')) | ||||||
|  |   normal Gzk | ||||||
|  |   call assert_equal(8, line('.')) | ||||||
|  |   normal zk | ||||||
|  |   call assert_equal(6, line('.')) | ||||||
|  |   call assert_beeps('normal zk') | ||||||
|  |   call assert_equal(6, line('.')) | ||||||
|  |   call assert_beeps('normal 2Gzk') | ||||||
|  |   call assert_equal(2, line('.')) | ||||||
|  |  | ||||||
|  |   " Using [z or ]z in a closed fold should not move the cursor | ||||||
|  |   %d _ | ||||||
|  |   call setline(1, ["1", "\t2", "\t3", "\t4", "\t5", "\t6", "7"]) | ||||||
|  |   normal zR4Gzc | ||||||
|  |   call assert_equal(4, line('.')) | ||||||
|  |   call assert_beeps('normal [z') | ||||||
|  |   call assert_equal(4, line('.')) | ||||||
|  |   call assert_beeps('normal ]z') | ||||||
|  |   call assert_equal(4, line('.')) | ||||||
|  |   bw! | ||||||
|  | endfunc | ||||||
|  |  | ||||||
| " Make sure a fold containing a nested fold is split correctly when using | " Make sure a fold containing a nested fold is split correctly when using | ||||||
| " foldmethod=indent | " foldmethod=indent | ||||||
| func Test_fold_split() | func Test_fold_split() | ||||||
|   | |||||||
| @@ -309,5 +309,27 @@ describe('folding', function() | |||||||
|       {1:~                                            }| |       {1:~                                            }| | ||||||
|                                                    | |                                                    | | ||||||
|     ]]) |     ]]) | ||||||
|  |     feed('2G') | ||||||
|  |     screen:expect([[ | ||||||
|  |       one                                          | | ||||||
|  |       ^two                                          | | ||||||
|  |       three                                        | | ||||||
|  |       four                                         | | ||||||
|  |       {1:~                                            }| | ||||||
|  |       {1:~                                            }| | ||||||
|  |       {1:~                                            }| | ||||||
|  |                                                    | | ||||||
|  |     ]]) | ||||||
|  |     feed('k') | ||||||
|  |     screen:expect([[ | ||||||
|  |       ^one                                          | | ||||||
|  |       {2:+--  2 lines: two····························}| | ||||||
|  |       four                                         | | ||||||
|  |       {1:~                                            }| | ||||||
|  |       {1:~                                            }| | ||||||
|  |       {1:~                                            }| | ||||||
|  |       {1:~                                            }| | ||||||
|  |                                                    | | ||||||
|  |     ]]) | ||||||
|   end) |   end) | ||||||
| end) | end) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 zeertzjq
					zeertzjq