comparison src/testdir/test_fold.vim @ 11392:dc2800c3572b v8.0.0581

patch 8.0.0581: moving folded text is sometimes not correct commit https://github.com/vim/vim/commit/94be619e30e82d28cadeea5e0766c6f5c321ff8b Author: Bram Moolenaar <Bram@vim.org> Date: Sat Apr 22 22:40:11 2017 +0200 patch 8.0.0581: moving folded text is sometimes not correct Problem: Moving folded text is sometimes not correct. Solution: Bail out when "move_end" is zero. (Matthew Malcomson)
author Christian Brabandt <cb@256bit.org>
date Sat, 22 Apr 2017 22:45:04 +0200
parents e53609585b76
children f6534b99b76f
comparison
equal deleted inserted replaced
11391:553eb2299827 11392:dc2800c3572b
1 " Test for folding 1 " Test for folding
2 2
3 func! PrepIndent(arg) 3 func PrepIndent(arg)
4 return [a:arg] + repeat(["\t".a:arg], 5) 4 return [a:arg] + repeat(["\t".a:arg], 5)
5 endfu 5 endfu
6 6
7 func! Test_address_fold() 7 func Test_address_fold()
8 new 8 new
9 call setline(1, ['int FuncName() {/*{{{*/', 1, 2, 3, 4, 5, '}/*}}}*/', 9 call setline(1, ['int FuncName() {/*{{{*/', 1, 2, 3, 4, 5, '}/*}}}*/',
10 \ 'after fold 1', 'after fold 2', 'after fold 3']) 10 \ 'after fold 1', 'after fold 2', 'after fold 3'])
11 setl fen fdm=marker 11 setl fen fdm=marker
12 " The next commands should all copy the same part of the buffer, 12 " The next commands should all copy the same part of the buffer,
66 call assert_equal(['4', '5', '}/*}}}*/'], getreg(0,1,1)) 66 call assert_equal(['4', '5', '}/*}}}*/'], getreg(0,1,1))
67 67
68 quit! 68 quit!
69 endfunc 69 endfunc
70 70
71 func! Test_indent_fold() 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()
82 new 72 new
83 call setline(1, ['', 'a', ' b', ' c']) 73 call setline(1, ['', 'a', ' b', ' c'])
84 setl fen fdm=indent 74 setl fen fdm=indent
85 2 75 2
86 norm! >> 76 norm! >>
87 let a=map(range(1,4), 'foldclosed(v:val)') 77 let a=map(range(1,4), 'foldclosed(v:val)')
88 call assert_equal([-1,-1,-1,-1], a) 78 call assert_equal([-1,-1,-1,-1], a)
89 bw! 79 bw!
90 endfunc 80 endfunc
91 81
92 func! Test_indent_fold2() 82 func Test_indent_fold2()
93 new 83 new
94 call setline(1, ['', '{{{', '}}}', '{{{', '}}}']) 84 call setline(1, ['', '{{{', '}}}', '{{{', '}}}'])
95 setl fen fdm=marker 85 setl fen fdm=marker
96 2 86 2
97 norm! >> 87 norm! >>
120 bwipe! 110 bwipe!
121 set foldmethod& 111 set foldmethod&
122 endfor 112 endfor
123 endfunc 113 endfunc
124 114
125 func! Test_indent_fold_with_read() 115 func Test_indent_fold_with_read()
126 new 116 new
127 set foldmethod=indent 117 set foldmethod=indent
128 call setline(1, repeat(["\<Tab>a"], 4)) 118 call setline(1, repeat(["\<Tab>a"], 4))
129 for n in range(1, 4) 119 for n in range(1, 4)
130 call assert_equal(1, foldlevel(n)) 120 call assert_equal(1, foldlevel(n))
222 call delete('Xfile') 212 call delete('Xfile')
223 bwipe! 213 bwipe!
224 set foldmethod& foldexpr& 214 set foldmethod& foldexpr&
225 endfunc 215 endfunc
226 216
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()
228 new 222 new
229 let input = PrepIndent("a") + PrepIndent("b") + PrepIndent("c") 223 let input = PrepIndent("a") + PrepIndent("b") + PrepIndent("c")
230 call setline(1, PrepIndent("a") + PrepIndent("b") + PrepIndent("c")) 224 call setline(1, PrepIndent("a") + PrepIndent("b") + PrepIndent("c"))
231 let folds=[-1, 2, 2, 2, 2, 2, -1, 8, 8, 8, 8, 8, -1, 14, 14, 14, 14, 14] 225 let folds=[-1, 2, 2, 2, 2, 2, -1, 8, 8, 8, 8, 8, -1, 14, 14, 14, 14, 14]
232 " all folds closed 226 " all folds closed
291 set fdm=manual 285 set fdm=manual
292 %foldopen 286 %foldopen
293 6m$ 287 6m$
294 " The first fold has been truncated to the 5'th line. 288 " The first fold has been truncated to the 5'th line.
295 " Second fold has been moved up because the moved line is now below it. 289 " 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 \ "\ta",
297 \ "\t\ta",
298 \ "\t\ta",
299 \ "\t\ta",
300 \ "a",
301 \ "a"])
302 set fdm=manual
303 %foldopen!
304 4,5m6
305 call Check_foldlevels([0, 1, 2, 0, 0, 0, 0])
306
307 %delete
308 set fdm=indent
309 call setline(1, [
310 \ "\ta",
311 \ "\t\ta",
312 \ "\t\ta",
313 \ "\t\ta",
314 \ "\ta",
315 \ "\t\ta",
316 \ "\t\ta",
317 \ "\t\ta",
318 \ "\ta",
319 \ "\t\ta",
320 \ "\t\ta",
321 \ "\t\ta",
322 \ "\t\ta",
323 \ "\ta",
324 \ "a"])
325 set fdm=manual
326 %foldopen!
327 13m7
328 call Check_foldlevels([1, 2, 2, 2, 1, 2, 2, 1, 1, 1, 2, 2, 2, 1, 0])
329
297 bw! 330 bw!
298 endfunc 331 endfunc
299 332
300 func! Test_move_folds_around_indent() 333 func Test_move_folds_around_indent()
301 new 334 new
302 let input = PrepIndent("a") + PrepIndent("b") + PrepIndent("c") 335 let input = PrepIndent("a") + PrepIndent("b") + PrepIndent("c")
303 call setline(1, PrepIndent("a") + PrepIndent("b") + PrepIndent("c")) 336 call setline(1, PrepIndent("a") + PrepIndent("b") + PrepIndent("c"))
304 let folds=[-1, 2, 2, 2, 2, 2, -1, 8, 8, 8, 8, 8, -1, 14, 14, 14, 14, 14] 337 let folds=[-1, 2, 2, 2, 2, 2, -1, 8, 8, 8, 8, 8, -1, 14, 14, 14, 14, 14]
305 " all folds closed 338 " all folds closed
355 set fdm=indent foldlevel=0 388 set fdm=indent foldlevel=0
356 %foldopen 389 %foldopen
357 6m$ 390 6m$
358 " The first fold has been truncated to the 5'th line. 391 " The first fold has been truncated to the 5'th line.
359 " Second fold has been moved up because the moved line is now below it. 392 " 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])
361 bw! 394 bw!
362 endfunc 395 endfunc
363 396
364 func Test_folddoopen_folddoclosed() 397 func Test_folddoopen_folddoclosed()
365 new 398 new