From 3a9dd13f9e6471215a738cf22bf180e60a2e0bcd Mon Sep 17 00:00:00 2001 From: Matthew Malcomson Date: Fri, 31 Mar 2017 00:21:26 +0100 Subject: 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 --- test/functional/normal/fold_spec.lua | 112 ++++++++++++++++++++++++++++++++++- 1 file changed, 111 insertions(+), 1 deletion(-) (limited to 'test/functional/normal') 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 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) -- cgit From 65fb622000af8e3dbb65480e1581758ecf4ba3e2 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 9 Apr 2017 00:12:26 +0300 Subject: functests: Replace execute with either command or feed_command Hope this will make people using feed_command less likely: this hides bugs. Already found at least two: 1. msgpackparse() will show internal error: hash_add() in case of duplicate keys, though it will still work correctly. Currently silenced. 2. ttimeoutlen was spelled incorrectly, resulting in option not being set when expected. Test was still functioning somehow though. Currently fixed. --- test/functional/normal/count_spec.lua | 4 ++-- test/functional/normal/fold_spec.lua | 34 +++++++++++++++++----------------- test/functional/normal/put_spec.lua | 24 ++++++++++++------------ test/functional/normal/undo_spec.lua | 4 ++-- 4 files changed, 33 insertions(+), 33 deletions(-) (limited to 'test/functional/normal') diff --git a/test/functional/normal/count_spec.lua b/test/functional/normal/count_spec.lua index 700e1f3e81..94f741250a 100644 --- a/test/functional/normal/count_spec.lua +++ b/test/functional/normal/count_spec.lua @@ -4,13 +4,13 @@ local eq = helpers.eq local eval = helpers.eval local feed = helpers.feed local clear = helpers.clear -local execute = helpers.execute +local command = helpers.command describe('v:count/v:count1', function() before_each(function() clear() - execute('map _x :let g:count = "v:count=". v:count .", v:count1=". v:count1') + command('map _x :let g:count = "v:count=". v:count .", v:count1=". v:count1') end) describe('in cmdwin', function() diff --git a/test/functional/normal/fold_spec.lua b/test/functional/normal/fold_spec.lua index fc055c4e7a..85e4631b61 100644 --- a/test/functional/normal/fold_spec.lua +++ b/test/functional/normal/fold_spec.lua @@ -4,7 +4,7 @@ local clear = helpers.clear local insert = helpers.insert local feed = helpers.feed local expect = helpers.expect -local execute = helpers.execute +local feed_command = helpers.feed_command local funcs = helpers.funcs local foldlevel = funcs.foldlevel local foldclosedend = funcs.foldclosedend @@ -13,7 +13,7 @@ local eq = helpers.eq describe('Folds', function() local tempfname = 'Xtest-fold.txt' clear() - before_each(function() execute('enew!') end) + before_each(function() feed_command('enew!') end) after_each(function() os.remove(tempfname) end) it('manual folding adjusts with filter', function() insert([[ @@ -37,8 +37,8 @@ describe('Folds', function() 18 19 20]]) - execute('4,$fold', '%foldopen', '10,$fold', '%foldopen') - execute('1,8! cat') + feed_command('4,$fold', '%foldopen', '10,$fold', '%foldopen') + feed_command('1,8! cat') feed('5ggzdzMGdd') expect([[ 1 @@ -54,13 +54,13 @@ describe('Folds', function() describe('adjusting folds after :move', function() local function manually_fold_indent() -- setting foldmethod twice is a trick to get vim to set the folds for me - execute('set foldmethod=indent', 'set foldmethod=manual') + feed_command('set foldmethod=indent', 'set foldmethod=manual') -- Ensure that all folds will get closed (makes it easier to test the -- length of folds). - execute('set foldminlines=0') + feed_command('set foldminlines=0') -- Start with all folds open (so :move ranges aren't affected by closed -- folds). - execute('%foldopen!') + feed_command('%foldopen!') end local function get_folds() @@ -75,16 +75,16 @@ describe('Folds', function() -- This test is easy because we just need to ensure that the resulting -- fold is the same as calculated when creating folds from scratch. insert(insert_string) - execute(move_command) + feed_command(move_command) local after_move_folds = get_folds() -- Doesn't change anything, but does call foldUpdateAll() - execute('set foldminlines=0') + feed_command('set foldminlines=0') eq(after_move_folds, get_folds()) -- Set up the buffer with insert_string for the manual fold testing. - execute('enew!') + feed_command('enew!') insert(insert_string) manually_fold_indent() - execute(move_command) + feed_command(move_command) end it('neither closes nor corrupts folds', function() @@ -246,8 +246,8 @@ a]], '2,3m0') a a ]]) - execute('set foldmethod=indent', '2', '%foldopen') - execute('read ' .. tempfname) + feed_command('set foldmethod=indent', '2', '%foldopen') + feed_command('read ' .. tempfname) -- Just to check we have the correct file text. expect([[ a @@ -281,7 +281,7 @@ a]], '2,3m0') a a ]]) - execute('set foldmethod=indent', '3,5d') + feed_command('set foldmethod=indent', '3,5d') eq(5, funcs.foldclosedend(1)) end) it("doesn't combine folds that have a specified end", function() @@ -295,7 +295,7 @@ a]], '2,3m0') }}} ]]) - execute('set foldmethod=marker', '3,5d', '%foldclose') + feed_command('set foldmethod=marker', '3,5d', '%foldclose') eq(2, funcs.foldclosedend(1)) end) it('splits folds according to >N and u') funcs.setreg('a', 'test_stringa', 'V') funcs.setreg('b', 'test_stringb\ntest_stringb\ntest_stringb', 'b') funcs.setreg('"', 'test_string"', 'v') - execute('set virtualedit=') + feed_command('set virtualedit=') end -- We check the last inserted register ". in each of these tests because it is @@ -164,7 +164,7 @@ describe('put command', function() local function create_put_action(command_base, substitution) local temp_val = command_base:gsub('put', substitution) return function() - execute(temp_val) + feed_command(temp_val) return true end end @@ -642,7 +642,7 @@ describe('put command', function() -- Set curswant to '8' to be at the end of the tab character -- This is where the cursor is put back after the 'u' command. funcs.setpos('.', {0, 2, 1, 0, 8}) - execute('set autoindent') + feed_command('set autoindent') end ) end) @@ -653,7 +653,7 @@ describe('put command', function() test_stringx" Line of words 2]] run_normal_mode_tests(test_string, 'p', function() funcs.setline('$', ' Line of words 2') - execute('set virtualedit=all') + feed_command('set virtualedit=all') funcs.setpos('.', {0, 2, 1, 2, 3}) end) end) @@ -664,7 +664,7 @@ describe('put command', function() Line of words 2]] run_normal_mode_tests(test_string, 'p', function() funcs.setline('$', ' Line of words 2') - execute('set virtualedit=all') + feed_command('set virtualedit=all') funcs.setpos('.', {0, 1, 16, 1, 17}) end, true) end) @@ -829,7 +829,7 @@ describe('put command', function() 'vp', function() funcs.setline('$', ' Line of words 2') - execute('set virtualedit=all') + feed_command('set virtualedit=all') funcs.setpos('.', {0, 2, 1, 2, 3}) end, nil, @@ -844,7 +844,7 @@ describe('put command', function() base_expect_string, 'vp', function() - execute('set virtualedit=all') + feed_command('set virtualedit=all') funcs.setpos('.', {0, 1, 16, 2, 18}) end, true, @@ -906,7 +906,7 @@ describe('put command', function() end) it('should ring the bell when deleting if not appropriate', function() - execute('goto 2') + feed_command('goto 2') feed('i') expect([[ ine of words 1 @@ -921,7 +921,7 @@ describe('put command', function() end) it("should be unaffected by 'autoindent' with V\".2p", function() - execute('set autoindent') + feed_command('set autoindent') feed('i test_string.u') feed('V".2p') expect([[ diff --git a/test/functional/normal/undo_spec.lua b/test/functional/normal/undo_spec.lua index 55429f2e1e..a023ca3d90 100644 --- a/test/functional/normal/undo_spec.lua +++ b/test/functional/normal/undo_spec.lua @@ -1,7 +1,7 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear -local execute = helpers.execute +local command = helpers.command local expect = helpers.expect local feed = helpers.feed local insert = helpers.insert @@ -23,7 +23,7 @@ describe('u CTRL-R g- g+', function() end local function undo_and_redo(hist_pos, undo, redo, expect_str) - execute('enew!') + command('enew!') create_history(hist_pos) local cur_contents = helpers.curbuf_contents() feed(undo) -- cgit From a3a06d02489a7a43cdd7909c92c79ef7971c8663 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Sat, 8 Apr 2017 17:02:54 +0200 Subject: test: add tests for gu/gU behavior in Turkish locale --- test/functional/normal/lang_spec.lua | 59 ++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 test/functional/normal/lang_spec.lua (limited to 'test/functional/normal') diff --git a/test/functional/normal/lang_spec.lua b/test/functional/normal/lang_spec.lua new file mode 100644 index 0000000000..464b85d684 --- /dev/null +++ b/test/functional/normal/lang_spec.lua @@ -0,0 +1,59 @@ +local helpers = require('test.functional.helpers')(after_each) +local clear, insert, eq = helpers.clear, helpers.insert, helpers.eq +local execute, expect = helpers.execute, helpers.expect +local feed, eval = helpers.feed, helpers.eval +local exc_exec = helpers.exc_exec + +describe('gu and gU', function() + before_each(clear) + + it('works in any locale with default casemap', function() + eq('internal,keepascii', eval('&casemap')) + insert("iI") + feed("VgU") + expect("II") + feed("Vgu") + expect("ii") + end) + + describe('works in Turkish locale', function() + if helpers.pending_win32(pending) then return end + + clear() + if eval('has("mac")') ~= 0 then + pending("not yet on macOS", function() end) + return + end + + local err = exc_exec('lang ctype tr_TR.UTF-8') + if err ~= 0 then + pending("Locale tr_TR.UTF-8 not supported", function() end) + return + end + + before_each(function() + execute('lang ctype tr_TR.UTF-8') + end) + + it('with default casemap', function() + eq('internal,keepascii', eval('&casemap')) + -- expect ASCII behavior + insert("iI") + feed("VgU") + expect("II") + feed("Vgu") + expect("ii") + end) + + it('with casemap=""', function() + execute('set casemap=') + -- expect Turkish locale behavior + insert("iI") + feed("VgU") + expect("İI") + feed("Vgu") + expect("iı") + end) + + end) +end) -- cgit From 119f0ca85463b7d9fb7dffe47d0fcee2c9604c53 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 10 Apr 2017 21:54:19 +0200 Subject: test: helpers.execute() => helpers.feed_command() --- test/functional/normal/lang_spec.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test/functional/normal') diff --git a/test/functional/normal/lang_spec.lua b/test/functional/normal/lang_spec.lua index 464b85d684..1da1d4679d 100644 --- a/test/functional/normal/lang_spec.lua +++ b/test/functional/normal/lang_spec.lua @@ -1,6 +1,6 @@ local helpers = require('test.functional.helpers')(after_each) local clear, insert, eq = helpers.clear, helpers.insert, helpers.eq -local execute, expect = helpers.execute, helpers.expect +local command, expect = helpers.command, helpers.expect local feed, eval = helpers.feed, helpers.eval local exc_exec = helpers.exc_exec @@ -32,7 +32,7 @@ describe('gu and gU', function() end before_each(function() - execute('lang ctype tr_TR.UTF-8') + command('lang ctype tr_TR.UTF-8') end) it('with default casemap', function() @@ -46,7 +46,7 @@ describe('gu and gU', function() end) it('with casemap=""', function() - execute('set casemap=') + command('set casemap=') -- expect Turkish locale behavior insert("iI") feed("VgU") -- cgit From 69775f603f0b21cb28adec99daaaa9356581ddd0 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Mon, 10 Apr 2017 19:48:45 +0200 Subject: ci: install Turkish locale and make locale tests more reliable --- test/functional/normal/lang_spec.lua | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'test/functional/normal') diff --git a/test/functional/normal/lang_spec.lua b/test/functional/normal/lang_spec.lua index 1da1d4679d..24d1262f5f 100644 --- a/test/functional/normal/lang_spec.lua +++ b/test/functional/normal/lang_spec.lua @@ -17,13 +17,7 @@ describe('gu and gU', function() end) describe('works in Turkish locale', function() - if helpers.pending_win32(pending) then return end - clear() - if eval('has("mac")') ~= 0 then - pending("not yet on macOS", function() end) - return - end local err = exc_exec('lang ctype tr_TR.UTF-8') if err ~= 0 then @@ -47,13 +41,23 @@ describe('gu and gU', function() it('with casemap=""', function() command('set casemap=') - -- expect Turkish locale behavior - insert("iI") - feed("VgU") - expect("İI") - feed("Vgu") - expect("iı") + -- expect either Turkish locale behavior or ASCII behavior + local iupper = eval("toupper('i')") + if iupper == "İ" then + insert("iI") + feed("VgU") + expect("İI") + feed("Vgu") + expect("iı") + elseif iupper == "I" then + insert("iI") + feed("VgU") + expect("II") + feed("Vgu") + expect("ii") + else + error("expected toupper('i') to be either 'I' or 'İ'") + end end) - end) end) -- cgit From 263849b2dd4dc98bbe0870f5654c77809caeb965 Mon Sep 17 00:00:00 2001 From: Matthew Malcomson Date: Sun, 16 Apr 2017 20:15:50 +0100 Subject: fold: foldMoveRange(): fix :move bug #6534 Closes #6540 In #6221 there was a mistake in calculating which folds need to be re-ordered. When there are no folds after those that have been adjusted, then `move_end` remains 0. This results in reverse_fold_order() swapping folds that have been adjusted with uninitialised folds in the remainder of the grow array. Add a check in foldMoveRange() to account for this case. --- test/functional/normal/fold_spec.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'test/functional/normal') diff --git a/test/functional/normal/fold_spec.lua b/test/functional/normal/fold_spec.lua index 85e4631b61..00e83bedc8 100644 --- a/test/functional/normal/fold_spec.lua +++ b/test/functional/normal/fold_spec.lua @@ -232,6 +232,25 @@ a a]], '2,3m0') eq({1, 2, 0, 0, 0}, get_folds()) end) + it('handles shifting all remaining folds', function() + test_move_indent([[ + a + a + a + a + a + a + a + a + a + a + a + a + a + a +a]], '13m7') + eq({1, 2, 2, 2, 1, 2, 2, 1, 1, 1, 2, 2, 2, 1, 0}, get_folds()) + end) end) it('updates correctly on :read', function() -- luacheck: ignore 621 -- cgit