test_blockedit.vim (3917B)
1 " Test for block inserting 2 " 3 4 func Test_blockinsert_indent() 5 new 6 filetype plugin indent on 7 setlocal sw=2 et ft=vim 8 call setline(1, ['let a=[', ' ''eins'',', ' ''zwei'',', ' ''drei'']']) 9 call cursor(2, 3) 10 exe "norm! \<c-v>2jI\\ \<esc>" 11 call assert_equal(['let a=[', ' \ ''eins'',', ' \ ''zwei'',', ' \ ''drei'']'], 12 \ getline(1,'$')) 13 " reset to sane state 14 filetype off 15 bwipe! 16 endfunc 17 18 func Test_blockinsert_autoindent() 19 new 20 let lines =<< trim END 21 vim9script 22 var d = { 23 a: () => 0, 24 b: () => 0, 25 c: () => 0, 26 } 27 END 28 call setline(1, lines) 29 filetype plugin indent on 30 setlocal sw=2 et ft=vim 31 setlocal indentkeys+=: 32 exe "norm! 3Gf)\<c-v>2jA: asdf\<esc>" 33 let expected =<< trim END 34 vim9script 35 var d = { 36 a: (): asdf => 0, 37 b: (): asdf => 0, 38 c: (): asdf => 0, 39 } 40 END 41 call assert_equal(expected, getline(1, 6)) 42 43 " insert on the next column should do exactly the same 44 :%dele 45 call setline(1, lines) 46 exe "norm! 3Gf)l\<c-v>2jI: asdf\<esc>" 47 call assert_equal(expected, getline(1, 6)) 48 49 :%dele 50 call setline(1, lines) 51 setlocal sw=8 noet 52 exe "norm! 3Gf)\<c-v>2jA: asdf\<esc>" 53 let expected =<< trim END 54 vim9script 55 var d = { 56 a: (): asdf => 0, 57 b: (): asdf => 0, 58 c: (): asdf => 0, 59 } 60 END 61 call assert_equal(expected, getline(1, 6)) 62 63 " insert on the next column should do exactly the same 64 :%dele 65 call setline(1, lines) 66 exe "norm! 3Gf)l\<c-v>2jI: asdf\<esc>" 67 call assert_equal(expected, getline(1, 6)) 68 69 filetype off 70 bwipe! 71 endfunc 72 73 func Test_blockinsert_delete() 74 new 75 let _bs = &bs 76 set bs=2 77 call setline(1, ['case Arg is ', ' when Name_Async,', ' when Name_Num_Gangs,', 'end if;']) 78 exe "norm! ggjVj\<c-v>$o$A\<bs>\<esc>" 79 "call feedkeys("Vj\<c-v>$o$A\<bs>\<esc>", 'ti') 80 call assert_equal(["case Arg is ", " when Name_Async", " when Name_Num_Gangs,", "end if;"], 81 \ getline(1,'$')) 82 " reset to sane state 83 let &bs = _bs 84 bwipe! 85 endfunc 86 87 func Test_blockappend_eol_cursor() 88 new 89 " Test 1 Move 1 char left 90 call setline(1, ['aaa', 'bbb', 'ccc']) 91 exe "norm! gg$\<c-v>2jA\<left>x\<esc>" 92 call assert_equal(['aaxa', 'bbxb', 'ccxc'], getline(1, '$')) 93 " Test 2 Move 2 chars left 94 sil %d 95 call setline(1, ['aaa', 'bbb', 'ccc']) 96 exe "norm! gg$\<c-v>2jA\<left>\<left>x\<esc>" 97 call assert_equal(['axaa', 'bxbb', 'cxcc'], getline(1, '$')) 98 " Test 3 Move 3 chars left (outside of the visual selection) 99 sil %d 100 call setline(1, ['aaa', 'bbb', 'ccc']) 101 exe "norm! ggl$\<c-v>2jA\<left>\<left>\<left>x\<esc>" 102 call assert_equal(['xaaa', 'bbb', 'ccc'], getline(1, '$')) 103 bw! 104 endfunc 105 106 func Test_blockappend_eol_cursor2() 107 new 108 " Test 1 Move 1 char left 109 call setline(1, ['aaaaa', 'bbb', 'ccccc']) 110 exe "norm! gg\<c-v>$2jA\<left>x\<esc>" 111 call assert_equal(['aaaaxa', 'bbbx', 'ccccxc'], getline(1, '$')) 112 " Test 2 Move 2 chars left 113 sil %d 114 call setline(1, ['aaaaa', 'bbb', 'ccccc']) 115 exe "norm! gg\<c-v>$2jA\<left>\<left>x\<esc>" 116 call assert_equal(['aaaxaa', 'bbbx', 'cccxcc'], getline(1, '$')) 117 " Test 3 Move 3 chars left (to the beginning of the visual selection) 118 sil %d 119 call setline(1, ['aaaaa', 'bbb', 'ccccc']) 120 exe "norm! gg\<c-v>$2jA\<left>\<left>\<left>x\<esc>" 121 call assert_equal(['aaxaaa', 'bbxb', 'ccxccc'], getline(1, '$')) 122 " Test 4 Move 3 chars left (outside of the visual selection) 123 sil %d 124 call setline(1, ['aaaaa', 'bbb', 'ccccc']) 125 exe "norm! ggl\<c-v>$2jA\<left>\<left>\<left>x\<esc>" 126 call assert_equal(['aaxaaa', 'bbxb', 'ccxccc'], getline(1, '$')) 127 " Test 5 Move 4 chars left (outside of the visual selection) 128 sil %d 129 call setline(1, ['aaaaa', 'bbb', 'ccccc']) 130 exe "norm! ggl\<c-v>$2jA\<left>\<left>\<left>\<left>x\<esc>" 131 call assert_equal(['axaaaa', 'bxbb', 'cxcccc'], getline(1, '$')) 132 bw! 133 endfunc 134 135 " vim: shiftwidth=2 sts=2 expandtab