11" Test for folding
22
3- func ! PrepIndent (arg)
3+ func PrepIndent (arg)
44 return [a: arg ] + repeat ([" \t " .a: arg ], 5 )
55endfu
66
7- func ! Test_address_fold ()
7+ func Test_address_fold ()
88 new
99 call setline (1 , [' int FuncName() {/*{{{*/' , 1 , 2 , 3 , 4 , 5 , ' }/*}}}*/' ,
1010 \ ' after fold 1' , ' after fold 2' , ' after fold 3' ])
@@ -68,17 +68,7 @@ func! Test_address_fold()
6868 quit !
6969endfunc
7070
71- func ! Test_indent_fold ()
72- new
73- call setline (1 , [' ' , ' a' , ' b' , ' c' ])
74- setl fen fdm = indent
75- 2
76- norm! >>
77- let a = map (range (1 ,4 ), ' foldclosed(v:val)' )
78- call assert_equal ([-1 ,-1 ,-1 ,-1 ], a )
79- endfunc
80-
81- func ! Test_indent_fold ()
71+ func Test_indent_fold ()
8272 new
8373 call setline (1 , [' ' , ' a' , ' b' , ' c' ])
8474 setl fen fdm = indent
@@ -89,7 +79,7 @@ func! Test_indent_fold()
8979 bw !
9080endfunc
9181
92- func ! Test_indent_fold2 ()
82+ func Test_indent_fold2 ()
9383 new
9484 call setline (1 , [' ' , ' {{{' , ' }}}' , ' {{{' , ' }}}' ])
9585 setl fen fdm = marker
@@ -122,7 +112,7 @@ func Test_manual_fold_with_filter()
122112 endfor
123113endfunc
124114
125- func ! Test_indent_fold_with_read ()
115+ func Test_indent_fold_with_read ()
126116 new
127117 set foldmethod = indent
128118 call setline (1 , repeat ([" \<Tab> a" ], 4 ))
@@ -224,7 +214,11 @@ func Test_update_folds_expr_read()
224214 set foldmethod & foldexpr &
225215endfunc
226216
227- func ! Test_move_folds_around_manual ()
217+ func Check_foldlevels (expected)
218+ call assert_equal (a: expected , map (range (1 , line (' $' )), ' foldlevel(v:val)' ))
219+ endfunc
220+
221+ func Test_move_folds_around_manual ()
228222 new
229223 let input = PrepIndent (" a" ) + PrepIndent (" b" ) + PrepIndent (" c" )
230224 call setline (1 , PrepIndent (" a" ) + PrepIndent (" b" ) + PrepIndent (" c" ))
@@ -293,11 +287,50 @@ func! Test_move_folds_around_manual()
293287 6 m$
294288 " The first fold has been truncated to the 5'th line.
295289 " Second fold has been moved up because the moved line is now below it.
296- call assert_equal ([0 , 1 , 1 , 1 , 1 , 0 , 0 , 0 , 1 , 0 ], map (range (1 , line (' $' )), ' foldlevel(v:val)' ))
290+ call Check_foldlevels ([0 , 1 , 1 , 1 , 1 , 0 , 0 , 0 , 1 , 0 ])
291+
292+ % delete
293+ set fdm = indent foldlevel = 0
294+ call setline (1 , [
295+ \ " a" ,
296+ \ " \t a" ,
297+ \ " \t\t a" ,
298+ \ " \t\t a" ,
299+ \ " \t\t a" ,
300+ \ " a" ,
301+ \ " a" ])
302+ set fdm = manual
303+ % foldopen !
304+ 4 ,5 m6
305+ call Check_foldlevels ([0 , 1 , 2 , 0 , 0 , 0 , 0 ])
306+
307+ % delete
308+ set fdm = indent
309+ call setline (1 , [
310+ \ " \t a" ,
311+ \ " \t\t a" ,
312+ \ " \t\t a" ,
313+ \ " \t\t a" ,
314+ \ " \t a" ,
315+ \ " \t\t a" ,
316+ \ " \t\t a" ,
317+ \ " \t\t a" ,
318+ \ " \t a" ,
319+ \ " \t\t a" ,
320+ \ " \t\t a" ,
321+ \ " \t\t a" ,
322+ \ " \t\t a" ,
323+ \ " \t a" ,
324+ \ " a" ])
325+ set fdm = manual
326+ % foldopen !
327+ 13 m7
328+ call Check_foldlevels ([1 , 2 , 2 , 2 , 1 , 2 , 2 , 1 , 1 , 1 , 2 , 2 , 2 , 1 , 0 ])
329+
297330 bw !
298331endfunc
299332
300- func ! Test_move_folds_around_indent ()
333+ func Test_move_folds_around_indent ()
301334 new
302335 let input = PrepIndent (" a" ) + PrepIndent (" b" ) + PrepIndent (" c" )
303336 call setline (1 , PrepIndent (" a" ) + PrepIndent (" b" ) + PrepIndent (" c" ))
@@ -357,7 +390,7 @@ func! Test_move_folds_around_indent()
357390 6 m$
358391 " The first fold has been truncated to the 5'th line.
359392 " Second fold has been moved up because the moved line is now below it.
360- call assert_equal ([0 , 1 , 1 , 1 , 1 , 0 , 0 , 0 , 1 , 1 ], map ( range ( 1 , line ( ' $ ' )), ' foldlevel(v:val) ' ) )
393+ call Check_foldlevels ([0 , 1 , 1 , 1 , 1 , 0 , 0 , 0 , 1 , 1 ])
361394 bw !
362395endfunc
363396
0 commit comments