robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
f907614088
master
1-- Test Visual block mode commands 2-- And test "U" in Visual mode, also on German sharp S. 3 4local t =require ( 'test.testutil' ) 5local n =require ( 'test.functional.testnvim' )() 6 7local describe , it , before_each =t . describe , t . it , t . before_each 8local api , eq =n . api , t . eq 9local insert , feed =n . insert , n . feed 10local clear , expect =n . clear , n . expect 11local feed_command =n . feed_command 12 13describe ( 'Visual block mode' , function () 14before_each ( function () 15clear () 16 17feed_command ( 'set ts&vi sw&vi sts&vi noet' ) -- Vim compatible 18end ) 19 20it ( 'should shift, insert, replace and change a block' , function () 21insert ( [[ 22abcdefghijklm 23abcdefghijklm 24abcdefghijklm 25abcdefghijklm 26abcdefghijklm]] ) 27 28feed ( 'gg' ) 29-- Test shift-right of a block 30feed ( 'jllll<C-v>jj>wll<C-v>jlll><CR>' ) 31-- Test shift-left of a block 32feed ( 'G$hhhh<C-v>kk<lt>' ) 33-- Test block-insert 34feed ( 'Gkl<C-v>kkkIxyz<ESC>' ) 35-- Test block-replace 36feed ( 'Gllll<C-v>kkklllrq' ) 37-- Test block-change 38feed ( 'G$khhh<C-v>hhkkcmno<ESC>' ) 39 40expect ( [[ 41axyzbcdefghijklm 42axyzqqqq mno ghijklm 43axyzqqqqef mno ghijklm 44axyzqqqqefgmnoklm 45abcdqqqqijklm]] ) 46end ) 47 48-- luacheck: ignore 611 (Line contains only whitespaces) 49it ( 'should insert a block using cursor keys for movement' , function () 50insert ( [[ 51aaaaaa 52bbbbbb 53cccccc 54dddddd 5556 xaaa 57bbbb 58cccc 59dddd]] ) 60 61feed_command ( '/^aa' ) 62feed ( 'l<C-v>jjjlllI<Right><Right> <ESC>' ) 63feed_command ( '/xaaa$' ) 64feed ( '<C-v>jjjI<lt>><Left>p<ESC>' ) 65 66expect ( [[ 67aaa aaa 68bbb bbb 69ccc ccc 70ddd ddd 7172 <p>xaaa 73<p>bbbb 74<p>cccc 75<p>dddd]] ) 76end ) 77 78it ( 'should create a block' , function () 79insert ( [[ 80A23 814567 8283 B23 844567 8586 C23 874567]] ) 88 89-- Test for Visual block was created with the last <C-v>$. 90feed_command ( '/^A23$/' ) 91feed ( 'l<C-v>j$Aab<ESC>' ) 92-- Test for Visual block was created with the middle <C-v>$ (1). 93feed_command ( '/^B23$/' ) 94feed ( 'l<C-v>j$hAab<ESC>' ) 95-- Test for Visual block was created with the middle <C-v>$ (2). 96feed_command ( '/^C23$/' ) 97feed ( 'l<C-v>j$hhAab<ESC>' ) 98 99expect ( [[ 100A23ab 1014567ab 102103 B23 ab 1044567ab 105106 C23ab 107456ab7]] ) 108end ) 109 110-- luacheck: ignore 621 (Indentation) 111it ( 'should insert and append a block when virtualedit=all' , function () 112insert ( [[ 113line1 114line2 115line3 116. 117]] ) 118 119-- Test for Visual block insert when virtualedit=all and utf-8 encoding. 120feed_command ( 'set ve=all' ) 121feed_command ( '/\t\tline' ) 122feed ( '07l<C-v>jjIx<ESC>' ) 123 124expect ( [[ 125x line1 126x line2 127x line3 128. 129]] ) 130 131-- Test for Visual block append when virtualedit=all. 132feed ( '012l<C-v>jjAx<ESC>' ) 133 134expect ( [[ 135x x line1 136x x line2 137x x line3 138. 139]] ) 140end ) 141 142it ( 'should make a selected part uppercase' , function () 143-- GUe must uppercase a whole word, also when ß changes to ẞ. 144feed ( 'Gothe youtußeuu end<ESC>Ypk0wgUe<CR>' ) 145-- GUfx must uppercase until x, inclusive. 146feed ( 'O- youßtußexu -<ESC>0fogUfx<CR>' ) 147-- VU must uppercase a whole line. 148feed ( 'YpkVU<CR>' ) 149-- Same, when it's the last line in the buffer. 150feed ( 'YPGi111<ESC>VUddP<CR>' ) 151-- Uppercase two lines. 152feed ( 'Oblah di<CR>' ) 153feed ( 'doh dut<ESC>VkUj<CR>' ) 154-- Uppercase part of two lines. 155feed ( 'ddppi333<ESC>k0i222<esc>fyllvjfuUk<CR>' ) 156 157expect ( [[ 158159 the YOUTUẞEUU end 160- yOUẞTUẞEXu - 161THE YOUTUẞEUU END 162111THE YOUTUẞEUU END 163BLAH DI 164DOH DUT 165222the yoUTUẞEUU END 166333THE YOUTUßeuu end]] ) 167end ) 168 169it ( 'should replace using Enter or NL' , function () 170-- Visual replace using Enter or NL. 171feed ( 'G3o123456789<ESC>2k05l<C-v>2jr<CR>' ) 172feed ( 'G3o98765<ESC>2k02l<C-v>2jr<C-v><CR>' ) 173feed ( 'G3o123456789<ESC>2k05l<C-v>2jr<CR>' ) 174feed ( 'G3o98765<ESC>2k02l<C-v>2jr<C-v><Nul>' ) 175 176local expected =[[ 177178 12345 179789 18012345 181789 18212345 183789 18498<CR>65 18598<CR>65 18698<CR>65 18712345 188789 18912345 190789 19112345 192789 19398<Nul>65 19498<Nul>65 19598<Nul>65]] 196expected =expected : gsub ( '<CR>' , '\r' ) 197expected =expected : gsub ( '<Nul>' , '\000' ) 198 199expect ( expected ) 200end ) 201 202it ( 'should treat cursor position correctly when virtualedit=block' , function () 203insert ( [[ 20412345 205789 20698765]] ) 207 208-- Test cursor position. When virtualedit=block and Visual block mode and $gj. 209feed_command ( 'set ve=block' ) 210feed ( 'G2l' ) 211feed ( '2k<C-v>$gj<ESC>' ) 212feed_command ( [[let cpos=getpos("'>")]] ) 213local cpos =api . nvim_get_var ( 'cpos' ) 214local expected ={ 215col =4 , 216off =0 , 217} 218local actual ={ 219col =cpos [ 3 ], 220off =cpos [ 4 ], 221} 222 223eq ( expected , actual ) 224end ) 225 226it ( 'should replace spaces in front of the block with tabs' , function () 227insert ( [[ 228#define BO_ALL 0x0001 229#define BO_BS 0x0002 230#define BO_CRSR 0x0004]] ) 231 232-- Block_insert when replacing spaces in front of the block with tabs. 233feed_command ( 'set ts=8 sts=4 sw=4' ) 234feed ( 'ggf0<C-v>2jI<TAB><ESC>' ) 235 236expect ( [[ 237#define BO_ALL 0x0001 238#define BO_BS 0x0002 239#define BO_CRSR 0x0004]] ) 240end ) 241end )