Bram Moolenaar | 9aa1569 | 2017-08-19 15:05:32 +0200 | [diff] [blame] | 1 | " Tests for 'virtualedit'. |
| 2 | |
| 3 | func Test_yank_move_change() |
Bram Moolenaar | d41babe | 2017-08-30 17:01:35 +0200 | [diff] [blame] | 4 | new |
Bram Moolenaar | 9aa1569 | 2017-08-19 15:05:32 +0200 | [diff] [blame] | 5 | call setline(1, [ |
| 6 | \ "func foo() error {", |
| 7 | \ "\tif n, err := bar();", |
| 8 | \ "\terr != nil {", |
| 9 | \ "\t\treturn err", |
| 10 | \ "\t}", |
| 11 | \ "\tn = n * n", |
| 12 | \ ]) |
| 13 | set virtualedit=all |
| 14 | set ts=4 |
| 15 | function! MoveSelectionDown(count) abort |
| 16 | normal! m` |
| 17 | silent! exe "'<,'>move'>+".a:count |
| 18 | norm! `` |
| 19 | endfunction |
| 20 | |
| 21 | xmap ]e :<C-U>call MoveSelectionDown(v:count1)<CR> |
| 22 | 2 |
| 23 | normal 2gg |
| 24 | normal J |
| 25 | normal jVj |
| 26 | normal ]e |
| 27 | normal ce |
| 28 | bwipe! |
| 29 | set virtualedit= |
| 30 | set ts=8 |
| 31 | endfunc |
Bram Moolenaar | d41babe | 2017-08-30 17:01:35 +0200 | [diff] [blame] | 32 | |
| 33 | func Test_paste_end_of_line() |
| 34 | new |
| 35 | set virtualedit=all |
| 36 | call setline(1, ['456', '123']) |
| 37 | normal! gg0"ay$ |
| 38 | exe "normal! 2G$lllA\<C-O>:normal! \"agP\r" |
| 39 | call assert_equal('123456', getline(2)) |
| 40 | |
| 41 | bwipe! |
| 42 | set virtualedit= |
| 43 | endfunc |
Bram Moolenaar | db0eede | 2018-04-25 22:38:17 +0200 | [diff] [blame] | 44 | |
Bram Moolenaar | 630afe8 | 2018-06-28 19:26:28 +0200 | [diff] [blame] | 45 | func Test_replace_end_of_line() |
| 46 | new |
| 47 | set virtualedit=all |
| 48 | call setline(1, range(20)) |
| 49 | exe "normal! gg2jv10lr-" |
| 50 | call assert_equal(["1", "-----------", "3"], getline(2,4)) |
Bram Moolenaar | 30276f2 | 2019-01-24 17:59:39 +0100 | [diff] [blame] | 51 | call setline(1, range(20)) |
| 52 | exe "normal! gg2jv10lr\<c-k>hh" |
| 53 | call assert_equal(["1", "───────────", "3"], getline(2,4)) |
Bram Moolenaar | 630afe8 | 2018-06-28 19:26:28 +0200 | [diff] [blame] | 54 | |
| 55 | bwipe! |
| 56 | set virtualedit= |
| 57 | endfunc |
| 58 | |
Bram Moolenaar | db0eede | 2018-04-25 22:38:17 +0200 | [diff] [blame] | 59 | func Test_edit_CTRL_G() |
| 60 | new |
| 61 | set virtualedit=insert |
| 62 | call setline(1, ['123', '1', '12']) |
| 63 | exe "normal! ggA\<c-g>jx\<c-g>jx" |
| 64 | call assert_equal(['123', '1 x', '12 x'], getline(1,'$')) |
| 65 | |
| 66 | set virtualedit=all |
| 67 | %d_ |
| 68 | call setline(1, ['1', '12']) |
| 69 | exe "normal! ggllix\<c-g>jx" |
| 70 | call assert_equal(['1 x', '12x'], getline(1,'$')) |
| 71 | |
| 72 | |
| 73 | bwipe! |
| 74 | set virtualedit= |
| 75 | endfunc |
Bram Moolenaar | 77ccc00 | 2019-10-31 03:21:25 +0100 | [diff] [blame] | 76 | |
| 77 | func Test_edit_change() |
| 78 | new |
| 79 | set virtualedit=all |
| 80 | call setline(1, "\t⒌") |
| 81 | normal Cx |
| 82 | call assert_equal('x', getline(1)) |
| 83 | bwipe! |
Bram Moolenaar | 6f1f0ca | 2019-12-01 18:16:18 +0100 | [diff] [blame] | 84 | set virtualedit= |
| 85 | endfunc |
| 86 | |
Bram Moolenaar | 54c8d22 | 2019-12-02 20:41:39 +0100 | [diff] [blame] | 87 | " Tests for pasting at the beginning, end and middle of a tab character |
| 88 | " in virtual edit mode. |
Bram Moolenaar | 6f1f0ca | 2019-12-01 18:16:18 +0100 | [diff] [blame] | 89 | func Test_paste_in_tab() |
| 90 | new |
Bram Moolenaar | 54c8d22 | 2019-12-02 20:41:39 +0100 | [diff] [blame] | 91 | call append(0, '') |
Bram Moolenaar | 6f1f0ca | 2019-12-01 18:16:18 +0100 | [diff] [blame] | 92 | set virtualedit=all |
Bram Moolenaar | 54c8d22 | 2019-12-02 20:41:39 +0100 | [diff] [blame] | 93 | |
| 94 | " Tests for pasting a register with characterwise mode type |
| 95 | call setreg('"', 'xyz', 'c') |
| 96 | |
| 97 | " paste (p) unnamed register at the beginning of a tab |
Bram Moolenaar | 6f1f0ca | 2019-12-01 18:16:18 +0100 | [diff] [blame] | 98 | call setline(1, "a\tb") |
Bram Moolenaar | 54c8d22 | 2019-12-02 20:41:39 +0100 | [diff] [blame] | 99 | call cursor(1, 2, 0) |
| 100 | normal p |
| 101 | call assert_equal('a xyz b', getline(1)) |
| 102 | |
| 103 | " paste (P) unnamed register at the beginning of a tab |
| 104 | call setline(1, "a\tb") |
| 105 | call cursor(1, 2, 0) |
Bram Moolenaar | 6f1f0ca | 2019-12-01 18:16:18 +0100 | [diff] [blame] | 106 | normal P |
| 107 | call assert_equal("axyz\tb", getline(1)) |
| 108 | |
Bram Moolenaar | 54c8d22 | 2019-12-02 20:41:39 +0100 | [diff] [blame] | 109 | " paste (p) unnamed register at the end of a tab |
Bram Moolenaar | 6f1f0ca | 2019-12-01 18:16:18 +0100 | [diff] [blame] | 110 | call setline(1, "a\tb") |
| 111 | call cursor(1, 2, 6) |
| 112 | normal p |
| 113 | call assert_equal("a\txyzb", getline(1)) |
Bram Moolenaar | 54c8d22 | 2019-12-02 20:41:39 +0100 | [diff] [blame] | 114 | |
| 115 | " paste (P) unnamed register at the end of a tab |
Bram Moolenaar | 6f1f0ca | 2019-12-01 18:16:18 +0100 | [diff] [blame] | 116 | call setline(1, "a\tb") |
| 117 | call cursor(1, 2, 6) |
| 118 | normal P |
Bram Moolenaar | 54c8d22 | 2019-12-02 20:41:39 +0100 | [diff] [blame] | 119 | call assert_equal('a xyz b', getline(1)) |
Bram Moolenaar | 6f1f0ca | 2019-12-01 18:16:18 +0100 | [diff] [blame] | 120 | |
Bram Moolenaar | 54c8d22 | 2019-12-02 20:41:39 +0100 | [diff] [blame] | 121 | " Tests for pasting a register with blockwise mode type |
| 122 | call setreg('"', 'xyz', 'b') |
| 123 | |
| 124 | " paste (p) unnamed register at the beginning of a tab |
| 125 | call setline(1, "a\tb") |
| 126 | call cursor(1, 2, 0) |
| 127 | normal p |
| 128 | call assert_equal('a xyz b', getline(1)) |
| 129 | |
| 130 | " paste (P) unnamed register at the beginning of a tab |
| 131 | call setline(1, "a\tb") |
| 132 | call cursor(1, 2, 0) |
| 133 | normal P |
| 134 | call assert_equal("axyz\tb", getline(1)) |
| 135 | |
| 136 | " paste (p) unnamed register at the end of a tab |
| 137 | call setline(1, "a\tb") |
| 138 | call cursor(1, 2, 6) |
| 139 | normal p |
| 140 | call assert_equal("a\txyzb", getline(1)) |
| 141 | |
| 142 | " paste (P) unnamed register at the end of a tab |
| 143 | call setline(1, "a\tb") |
| 144 | call cursor(1, 2, 6) |
| 145 | normal P |
| 146 | call assert_equal('a xyz b', getline(1)) |
| 147 | |
| 148 | " Tests for pasting with gp and gP in virtual edit mode |
| 149 | |
| 150 | " paste (gp) unnamed register at the beginning of a tab |
| 151 | call setline(1, "a\tb") |
| 152 | call cursor(1, 2, 0) |
| 153 | normal gp |
| 154 | call assert_equal('a xyz b', getline(1)) |
| 155 | call assert_equal([0, 1, 12, 0, 12], getcurpos()) |
| 156 | |
| 157 | " paste (gP) unnamed register at the beginning of a tab |
| 158 | call setline(1, "a\tb") |
| 159 | call cursor(1, 2, 0) |
| 160 | normal gP |
| 161 | call assert_equal("axyz\tb", getline(1)) |
| 162 | call assert_equal([0, 1, 5, 0, 5], getcurpos()) |
| 163 | |
| 164 | " paste (gp) unnamed register at the end of a tab |
Bram Moolenaar | 6f1f0ca | 2019-12-01 18:16:18 +0100 | [diff] [blame] | 165 | call setline(1, "a\tb") |
| 166 | call cursor(1, 2, 6) |
| 167 | normal gp |
| 168 | call assert_equal("a\txyzb", getline(1)) |
| 169 | call assert_equal([0, 1, 6, 0, 12], getcurpos()) |
Bram Moolenaar | 54c8d22 | 2019-12-02 20:41:39 +0100 | [diff] [blame] | 170 | |
| 171 | " paste (gP) unnamed register at the end of a tab |
Bram Moolenaar | 6f1f0ca | 2019-12-01 18:16:18 +0100 | [diff] [blame] | 172 | call setline(1, "a\tb") |
| 173 | call cursor(1, 2, 6) |
| 174 | normal gP |
Bram Moolenaar | 54c8d22 | 2019-12-02 20:41:39 +0100 | [diff] [blame] | 175 | call assert_equal('a xyz b', getline(1)) |
| 176 | call assert_equal([0, 1, 12, 0, 12], getcurpos()) |
| 177 | |
| 178 | " Tests for pasting a named register |
| 179 | let @r = 'xyz' |
| 180 | |
| 181 | " paste (gp) named register in the middle of a tab |
| 182 | call setline(1, "a\tb") |
| 183 | call cursor(1, 2, 2) |
| 184 | normal "rgp |
| 185 | call assert_equal('a xyz b', getline(1)) |
| 186 | call assert_equal([0, 1, 8, 0, 8], getcurpos()) |
| 187 | |
| 188 | " paste (gP) named register in the middle of a tab |
| 189 | call setline(1, "a\tb") |
| 190 | call cursor(1, 2, 2) |
| 191 | normal "rgP |
| 192 | call assert_equal('a xyz b', getline(1)) |
| 193 | call assert_equal([0, 1, 7, 0, 7], getcurpos()) |
Bram Moolenaar | 6f1f0ca | 2019-12-01 18:16:18 +0100 | [diff] [blame] | 194 | |
| 195 | bwipe! |
| 196 | set virtualedit= |
Bram Moolenaar | 77ccc00 | 2019-10-31 03:21:25 +0100 | [diff] [blame] | 197 | endfunc |
Bram Moolenaar | 54c8d22 | 2019-12-02 20:41:39 +0100 | [diff] [blame] | 198 | |
| 199 | " Test for yanking a few spaces within a tab to a register |
| 200 | func Test_yank_in_tab() |
| 201 | new |
| 202 | let @r = '' |
| 203 | call setline(1, "a\tb") |
| 204 | set virtualedit=all |
| 205 | call cursor(1, 2, 2) |
| 206 | normal "ry5l |
| 207 | call assert_equal(' ', @r) |
| 208 | |
| 209 | bwipe! |
| 210 | set virtualedit= |
| 211 | endfunc |
| 212 | |
| 213 | " vim: shiftwidth=2 sts=2 expandtab |