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