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