diff options
author | Matthew Malcomson <hardenedapple@gmail.com> | 2017-03-31 00:21:26 +0100 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2017-03-31 01:21:26 +0200 |
commit | 3a9dd13f9e6471215a738cf22bf180e60a2e0bcd (patch) | |
tree | 6eb21896fa2240ebaa00845884f84ab6631e235d /test/functional/normal/fold_spec.lua | |
parent | 831eb2a9bf9fdffc1b6942e4c43bc2458f4af794 (diff) | |
download | rneovim-3a9dd13f9e6471215a738cf22bf180e60a2e0bcd.tar.gz rneovim-3a9dd13f9e6471215a738cf22bf180e60a2e0bcd.tar.bz2 rneovim-3a9dd13f9e6471215a738cf22bf180e60a2e0bcd.zip |
fold.c: more edge-cases when updating (#6207)
When foldUpdateIEMSRecurse() re-uses an existing fold, it misses the
case where the existing fold spans from before startlnum to after
firstlnum, the new fold does not span this range, and there is no
"forced start" of a fold. We add a case for this in.
Ensure that if there was no forced break in folds, we merge folds that
now touch each other.
Include testing for a tricky foldmethod=expr case that has never been a
bug. This case works at the moment because of some effects that are not
obvious when reading the code.
A test for this could be useful to ensure a regression doesn't happen.
vim-patch:8.0.0408
Diffstat (limited to 'test/functional/normal/fold_spec.lua')
-rw-r--r-- | test/functional/normal/fold_spec.lua | 112 |
1 files changed, 111 insertions, 1 deletions
diff --git a/test/functional/normal/fold_spec.lua b/test/functional/normal/fold_spec.lua index 5584db20ba..fc055c4e7a 100644 --- a/test/functional/normal/fold_spec.lua +++ b/test/functional/normal/fold_spec.lua @@ -6,12 +6,15 @@ local feed = helpers.feed local expect = helpers.expect local execute = helpers.execute local funcs = helpers.funcs -local foldlevel, foldclosedend = funcs.foldlevel, funcs.foldclosedend +local foldlevel = funcs.foldlevel +local foldclosedend = funcs.foldclosedend local eq = helpers.eq describe('Folds', function() + local tempfname = 'Xtest-fold.txt' clear() before_each(function() execute('enew!') end) + after_each(function() os.remove(tempfname) end) it('manual folding adjusts with filter', function() insert([[ 1 @@ -230,4 +233,111 @@ a]], '2,3m0') eq({1, 2, 0, 0, 0}, get_folds()) end) end) + it('updates correctly on :read', function() + -- luacheck: ignore 621 + helpers.write_file(tempfname, [[ + a + + + a]]) + insert([[ + a + a + a + a + ]]) + execute('set foldmethod=indent', '2', '%foldopen') + execute('read ' .. tempfname) + -- Just to check we have the correct file text. + expect([[ + a + a + a + + + a + a + a + ]]) + for i = 1,2 do + eq(1, funcs.foldlevel(i)) + end + for i = 3,5 do + eq(0, funcs.foldlevel(i)) + end + for i = 6,8 do + eq(1, funcs.foldlevel(i)) + end + end) + it('combines folds when removing separating space', function() + -- luacheck: ignore 621 + insert([[ + a + a + a + a + a + a + a + a + ]]) + execute('set foldmethod=indent', '3,5d') + eq(5, funcs.foldclosedend(1)) + end) + it("doesn't combine folds that have a specified end", function() + insert([[ + {{{ + }}} + + + + {{{ + + }}} + ]]) + execute('set foldmethod=marker', '3,5d', '%foldclose') + eq(2, funcs.foldclosedend(1)) + end) + it('splits folds according to >N and <N with foldexpr', function() + helpers.source([[ + function TestFoldExpr(lnum) + let thisline = getline(a:lnum) + if thisline == 'a' + return 1 + elseif thisline == 'b' + return 0 + elseif thisline == 'c' + return '<1' + elseif thisline == 'd' + return '>1' + endif + return 0 + endfunction + ]]) + helpers.write_file(tempfname, [[ + b + b + a + a + d + a + a + c]]) + insert([[ + a + a + a + a + a + a + ]]) + execute('set foldmethod=expr', 'set foldexpr=TestFoldExpr(v:lnum)', '2', 'foldopen') + execute('read ' .. tempfname, '%foldclose') + eq(2, funcs.foldclosedend(1)) + eq(0, funcs.foldlevel(3)) + eq(0, funcs.foldlevel(4)) + eq(6, funcs.foldclosedend(5)) + eq(10, funcs.foldclosedend(7)) + eq(14, funcs.foldclosedend(11)) + end) end) |