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