-- Test Visual block mode commands -- And test "U" in Visual mode, also on German sharp S. local helpers = require('test.functional.helpers')(after_each) local nvim, eq = helpers.meths, helpers.eq local insert, feed = helpers.insert, helpers.feed local clear, expect = helpers.clear, helpers.expect local feed_command = helpers.feed_command describe('Visual block mode', function() before_each(function() clear() feed_command('set ts&vi sw&vi sts&vi noet') -- Vim compatible end) it('should shift, insert, replace and change a block', function() insert([[ abcdefghijklm abcdefghijklm abcdefghijklm abcdefghijklm abcdefghijklm]]) feed('gg') -- Test shift-right of a block feed('jlllljj>wlljlll>') -- Test shift-left of a block feed('G$hhhhkk') -- Test block-insert feed('GklkkkIxyz') -- Test block-replace feed('Gllllkkklllrq') -- Test block-change feed('G$khhhhhkkcmno') expect([[ axyzbcdefghijklm axyzqqqq mno ghijklm axyzqqqqef mno ghijklm axyzqqqqefgmnoklm abcdqqqqijklm]]) end) -- luacheck: ignore 611 (Line contains only whitespaces) it('should insert a block using cursor keys for movement', function() insert([[ aaaaaa bbbbbb cccccc dddddd xaaa bbbb cccc dddd]]) feed_command('/^aa') feed('ljjjlllI ') feed_command('/xaaa$') feed('jjjI>p') expect([[ aaa aaa bbb bbb ccc ccc ddd ddd

xaaa

bbbb

cccc

dddd]]) end) it('should create a block', function() insert([[ A23 4567 B23 4567 C23 4567]]) -- Test for Visual block was created with the last $. feed_command('/^A23$/') feed('lj$Aab') -- Test for Visual block was created with the middle $ (1). feed_command('/^B23$/') feed('lj$hAab') -- Test for Visual block was created with the middle $ (2). feed_command('/^C23$/') feed('lj$hhAab') expect([[ A23ab 4567ab B23 ab 4567ab C23ab 456ab7]]) end) -- luacheck: ignore 621 (Indentation) it('should insert and append a block when virtualedit=all', function() insert([[ line1 line2 line3 ]]) -- Test for Visual block insert when virtualedit=all and utf-8 encoding. feed_command('set ve=all') feed_command('/\t\tline') feed('07ljjIx') expect([[ x line1 x line2 x line3 ]]) -- Test for Visual block append when virtualedit=all. feed('012ljjAx') expect([[ x x line1 x x line2 x x line3 ]]) end) it('should make a selected part uppercase', function() -- GUe must uppercase a whole word, also when ß changes to SS. feed('Gothe youtußeuu endYpk0wgUe') -- GUfx must uppercase until x, inclusive. feed('O- youßtußexu -0fogUfx') -- VU must uppercase a whole line. feed('YpkVU') -- Same, when it's the last line in the buffer. feed('YPGi111VUddP') -- Uppercase two lines. feed('Oblah di') feed('doh dutVkUj') -- Uppercase part of two lines. feed('ddppi333k0i222fyllvjfuUk') expect([[ the YOUTUSSEUU end - yOUSSTUSSEXu - THE YOUTUSSEUU END 111THE YOUTUSSEUU END BLAH DI DOH DUT 222the yoUTUSSEUU END 333THE YOUTUßeuu end]]) end) it('should replace using Enter or NL', function() -- Visual replace using Enter or NL. feed('G3o1234567892k05l2jr') feed('G3o987652k02l2jr') feed('G3o1234567892k05l2jr') feed('G3o987652k02l2jr') local expected = [[ 12345 789 12345 789 12345 789 9865 9865 9865 12345 789 12345 789 12345 789 9865 9865 9865]] expected = expected:gsub('', '\r') expected = expected:gsub('', '\000') expect(expected) end) it('should treat cursor position correctly when virtualedit=block', function() insert([[ 12345 789 98765]]) -- Test cursor position. When virtualedit=block and Visual block mode and $gj. feed_command('set ve=block') feed('G2l') feed('2k$gj') feed_command([[let cpos=getpos("'>")]]) local cpos = nvim.get_var('cpos') local expected = { col = 4, off = 0 } local actual = { col = cpos[3], off = cpos[4] } eq(expected, actual) end) it('should replace spaces in front of the block with tabs', function() insert([[ #define BO_ALL 0x0001 #define BO_BS 0x0002 #define BO_CRSR 0x0004]]) -- Block_insert when replacing spaces in front of the block with tabs. feed_command('set ts=8 sts=4 sw=4') feed('ggf02jI') expect([[ #define BO_ALL 0x0001 #define BO_BS 0x0002 #define BO_CRSR 0x0004]]) end) end)