Mercurial > vim
comparison src/testdir/test_fold.vim @ 11156:80241603dd50 v8.0.0465
patch 8.0.0465: off-by-one error in using :move with folding
commit https://github.com/vim/vim/commit/40ebc0afda8d8e478d2090133ed6a3cd3d8da3ec
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Mar 16 15:59:14 2017 +0100
patch 8.0.0465: off-by-one error in using :move with folding
Problem: Off-by-one error in using :move with folding.
Solution: Correct off-by-one mistakes and add more tests. (Matthew
Malcomson)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 16 Mar 2017 16:00:05 +0100 |
parents | 6b26e044b6f5 |
children | e53609585b76 |
comparison
equal
deleted
inserted
replaced
11155:f32a834a52de | 11156:80241603dd50 |
---|---|
247 call setline(1, PrepIndent("a") + PrepIndent("b") + PrepIndent("c")) | 247 call setline(1, PrepIndent("a") + PrepIndent("b") + PrepIndent("c")) |
248 set fdm=indent | 248 set fdm=indent |
249 redraw! | 249 redraw! |
250 set fdm=manual | 250 set fdm=manual |
251 call cursor(2, 1) | 251 call cursor(2, 1) |
252 norm! zR | 252 %foldopen |
253 7,12m0 | 253 7,12m0 |
254 let folds=repeat([-1], 18) | 254 let folds=repeat([-1], 18) |
255 call assert_equal(PrepIndent("b") + PrepIndent("a") + PrepIndent("c"), getline(1, '$')) | 255 call assert_equal(PrepIndent("b") + PrepIndent("a") + PrepIndent("c"), getline(1, '$')) |
256 call assert_equal(folds, map(range(1, line('$')), 'foldclosed(v:val)')) | 256 call assert_equal(folds, map(range(1, line('$')), 'foldclosed(v:val)')) |
257 norm! zM | 257 norm! zM |
282 %foldclose | 282 %foldclose |
283 call assert_equal(5, foldclosedend(2)) | 283 call assert_equal(5, foldclosedend(2)) |
284 call assert_equal(0, foldlevel(6)) | 284 call assert_equal(0, foldlevel(6)) |
285 call assert_equal(9, foldclosedend(7)) | 285 call assert_equal(9, foldclosedend(7)) |
286 call assert_equal([-1, 2, 2, 2, 2, -1, 7, 7, 7, -1], map(range(1, line('$')), 'foldclosed(v:val)')) | 286 call assert_equal([-1, 2, 2, 2, 2, -1, 7, 7, 7, -1], map(range(1, line('$')), 'foldclosed(v:val)')) |
287 %d | |
288 " Ensure moving around the edges still works. | |
289 call setline(1, PrepIndent("a") + repeat(["a"], 3) + ["\ta"]) | |
290 set fdm=indent foldlevel=0 | |
291 set fdm=manual | |
292 %foldopen | |
293 6m$ | |
294 " 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. | |
296 call assert_equal([0, 1, 1, 1, 1, 0, 0, 0, 1, 0], map(range(1, line('$')), 'foldlevel(v:val)')) | |
287 bw! | 297 bw! |
288 endfunc | 298 endfunc |
289 | 299 |
290 func! Test_move_folds_around_indent() | 300 func! Test_move_folds_around_indent() |
291 new | 301 new |
305 " moving should not close the folds | 315 " moving should not close the folds |
306 %d | 316 %d |
307 call setline(1, PrepIndent("a") + PrepIndent("b") + PrepIndent("c")) | 317 call setline(1, PrepIndent("a") + PrepIndent("b") + PrepIndent("c")) |
308 set fdm=indent | 318 set fdm=indent |
309 call cursor(2, 1) | 319 call cursor(2, 1) |
310 norm! zR | 320 %foldopen |
311 7,12m0 | 321 7,12m0 |
312 let folds=repeat([-1], 18) | 322 let folds=repeat([-1], 18) |
313 call assert_equal(PrepIndent("b") + PrepIndent("a") + PrepIndent("c"), getline(1, '$')) | 323 call assert_equal(PrepIndent("b") + PrepIndent("a") + PrepIndent("c"), getline(1, '$')) |
314 call assert_equal(folds, map(range(1, line('$')), 'foldclosed(v:val)')) | 324 call assert_equal(folds, map(range(1, line('$')), 'foldclosed(v:val)')) |
315 norm! zM | 325 norm! zM |
337 %foldclose | 347 %foldclose |
338 call assert_equal(9, foldclosedend(2)) | 348 call assert_equal(9, foldclosedend(2)) |
339 call assert_equal(1, foldlevel(6)) | 349 call assert_equal(1, foldlevel(6)) |
340 call assert_equal(9, foldclosedend(7)) | 350 call assert_equal(9, foldclosedend(7)) |
341 call assert_equal([-1, 2, 2, 2, 2, 2, 2, 2, 2, -1], map(range(1, line('$')), 'foldclosed(v:val)')) | 351 call assert_equal([-1, 2, 2, 2, 2, 2, 2, 2, 2, -1], map(range(1, line('$')), 'foldclosed(v:val)')) |
352 " Ensure moving around the edges still works. | |
353 %d | |
354 call setline(1, PrepIndent("a") + repeat(["a"], 3) + ["\ta"]) | |
355 set fdm=indent foldlevel=0 | |
356 %foldopen | |
357 6m$ | |
358 " 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. | |
360 call assert_equal([0, 1, 1, 1, 1, 0, 0, 0, 1, 1], map(range(1, line('$')), 'foldlevel(v:val)')) | |
342 bw! | 361 bw! |
343 endfunc | 362 endfunc |