diff options
Diffstat (limited to 'test/functional/normal')
-rw-r--r-- | test/functional/normal/count_spec.lua | 4 | ||||
-rw-r--r-- | test/functional/normal/fold_spec.lua | 321 | ||||
-rw-r--r-- | test/functional/normal/lang_spec.lua | 63 | ||||
-rw-r--r-- | test/functional/normal/put_spec.lua | 24 | ||||
-rw-r--r-- | test/functional/normal/undo_spec.lua | 4 |
5 files changed, 397 insertions, 19 deletions
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 <silent> _x :<C-u>let g:count = "v:count=". v:count .", v:count1=". v:count1<CR>') + command('map <silent> _x :<C-u>let g:count = "v:count=". v:count .", v:count1=". v:count1<CR>') end) describe('in cmdwin', function() diff --git a/test/functional/normal/fold_spec.lua b/test/functional/normal/fold_spec.lua index a2a2a35a8b..00e83bedc8 100644 --- a/test/functional/normal/fold_spec.lua +++ b/test/functional/normal/fold_spec.lua @@ -4,10 +4,17 @@ 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 +local eq = helpers.eq describe('Folds', function() + local tempfname = 'Xtest-fold.txt' clear() + before_each(function() feed_command('enew!') end) + after_each(function() os.remove(tempfname) end) it('manual folding adjusts with filter', function() insert([[ 1 @@ -30,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 @@ -44,4 +51,312 @@ describe('Folds', function() 8 9]]) end) + 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 + feed_command('set foldmethod=indent', 'set foldmethod=manual') + -- Ensure that all folds will get closed (makes it easier to test the + -- length of folds). + feed_command('set foldminlines=0') + -- Start with all folds open (so :move ranges aren't affected by closed + -- folds). + feed_command('%foldopen!') + end + + local function get_folds() + local rettab = {} + for i = 1, funcs.line('$') do + table.insert(rettab, foldlevel(i)) + end + return rettab + end + + local function test_move_indent(insert_string, move_command) + -- 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) + feed_command(move_command) + local after_move_folds = get_folds() + -- Doesn't change anything, but does call foldUpdateAll() + feed_command('set foldminlines=0') + eq(after_move_folds, get_folds()) + -- Set up the buffer with insert_string for the manual fold testing. + feed_command('enew!') + insert(insert_string) + manually_fold_indent() + feed_command(move_command) + end + + it('neither closes nor corrupts folds', function() + test_move_indent([[ +a + a + a + a + a + a +a + a + a + a + a + a +a + a + a + a + a + a]], '7,12m0') + expect([[ +a + a + a + a + a + a +a + a + a + a + a + a +a + a + a + a + a + a]]) + -- lines are not closed, folds are correct + for i = 1,funcs.line('$') do + eq(-1, funcs.foldclosed(i)) + if i == 1 or i == 7 or i == 13 then + eq(0, foldlevel(i)) + elseif i == 4 then + eq(2, foldlevel(i)) + else + eq(1, foldlevel(i)) + end + end + -- folds are not corrupted + feed('zM') + eq(6, foldclosedend(2)) + eq(12, foldclosedend(8)) + eq(18, foldclosedend(14)) + end) + it("doesn't split a fold when the move is within it", function() + test_move_indent([[ +a + a + a + a + a + a + a + a + a +a]], '5m6') + eq({0, 1, 1, 2, 2, 2, 2, 1, 1, 0}, get_folds()) + end) + it('truncates folds that end in the moved range', function() + test_move_indent([[ +a + a + a + a + a +a +a]], '4,5m6') + eq({0, 1, 2, 0, 0, 0, 0}, get_folds()) + end) + it('moves folds that start between moved range and destination', function() + test_move_indent([[ +a + a + a + a + a +a +a + a + a + a +a +a + a]], '3,4m$') + eq({0, 1, 1, 0, 0, 1, 2, 1, 0, 0, 1, 0, 0}, get_folds()) + end) + it('does not affect folds outside changed lines', function() + test_move_indent([[ + a + a + a +a +a +a + a + a + a]], '4m5') + eq({1, 1, 1, 0, 0, 0, 1, 1, 1}, get_folds()) + end) + it('moves and truncates folds that start in moved range', function() + test_move_indent([[ +a + a + a + a + a +a +a +a +a +a]], '1,3m7') + eq({0, 0, 0, 0, 0, 1, 2, 0, 0, 0}, get_folds()) + end) + it('breaks a fold when moving text into it', function() + test_move_indent([[ +a + a + a + a + a +a +a]], '$m4') + eq({0, 1, 2, 2, 0, 0, 0}, get_folds()) + end) + it('adjusts correctly when moving a range backwards', function() + test_move_indent([[ +a + a + a + 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 + helpers.write_file(tempfname, [[ + a + + + a]]) + insert([[ + a + a + a + a + ]]) + feed_command('set foldmethod=indent', '2', '%foldopen') + feed_command('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 + ]]) + feed_command('set foldmethod=indent', '3,5d') + eq(5, funcs.foldclosedend(1)) + end) + it("doesn't combine folds that have a specified end", function() + insert([[ + {{{ + }}} + + + + {{{ + + }}} + ]]) + feed_command('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 + ]]) + feed_command('set foldmethod=expr', 'set foldexpr=TestFoldExpr(v:lnum)', '2', 'foldopen') + feed_command('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) diff --git a/test/functional/normal/lang_spec.lua b/test/functional/normal/lang_spec.lua new file mode 100644 index 0000000000..24d1262f5f --- /dev/null +++ b/test/functional/normal/lang_spec.lua @@ -0,0 +1,63 @@ +local helpers = require('test.functional.helpers')(after_each) +local clear, insert, eq = helpers.clear, helpers.insert, helpers.eq +local command, expect = helpers.command, 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() + clear() + + 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() + command('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() + command('set casemap=') + -- 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) diff --git a/test/functional/normal/put_spec.lua b/test/functional/normal/put_spec.lua index b3162364a6..148a35ec6b 100644 --- a/test/functional/normal/put_spec.lua +++ b/test/functional/normal/put_spec.lua @@ -8,23 +8,23 @@ local expect = helpers.expect local eq = helpers.eq local map = helpers.map local filter = helpers.filter -local execute = helpers.execute +local feed_command = helpers.feed_command local curbuf_contents = helpers.curbuf_contents local funcs = helpers.funcs local dedent = helpers.dedent local getreg = funcs.getreg local function reset() - execute('enew!') + feed_command('enew!') insert([[ Line of words 1 Line of words 2]]) - execute('goto 1') + feed_command('goto 1') feed('itest_string.<esc>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<bs><esc>') 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.<esc>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) |