Bram Moolenaar | 1f3e7d3 | 2019-12-06 20:43:36 +0100 | [diff] [blame] | 1 | " Tests for various Visual modes. |
Bram Moolenaar | c3c766e | 2017-03-08 22:55:19 +0100 | [diff] [blame] | 2 | |
Bram Moolenaar | d1ad99b | 2020-10-04 16:16:54 +0200 | [diff] [blame] | 3 | source shared.vim |
Bram Moolenaar | 7d7bcc6 | 2021-06-28 21:54:27 +0200 | [diff] [blame] | 4 | source check.vim |
Bram Moolenaar | 9cee4a1 | 2021-07-03 15:08:37 +0200 | [diff] [blame] | 5 | source screendump.vim |
Yegappan Lakshmanan | 4d55c54 | 2024-02-29 17:30:43 +0100 | [diff] [blame] | 6 | import './vim9.vim' as v9 |
Bram Moolenaar | d1ad99b | 2020-10-04 16:16:54 +0200 | [diff] [blame] | 7 | |
Bram Moolenaar | 019b9c6 | 2016-03-05 17:26:00 +0100 | [diff] [blame] | 8 | func Test_block_shift_multibyte() |
Bram Moolenaar | f8eb9c5 | 2017-01-02 17:31:24 +0100 | [diff] [blame] | 9 | " Uses double-wide character. |
Bram Moolenaar | 019b9c6 | 2016-03-05 17:26:00 +0100 | [diff] [blame] | 10 | split |
| 11 | call setline(1, ['xヹxxx', 'ヹxxx']) |
| 12 | exe "normal 1G0l\<C-V>jl>" |
| 13 | call assert_equal('x ヹxxx', getline(1)) |
| 14 | call assert_equal(' ヹxxx', getline(2)) |
| 15 | q! |
| 16 | endfunc |
Bram Moolenaar | f8eb9c5 | 2017-01-02 17:31:24 +0100 | [diff] [blame] | 17 | |
Bram Moolenaar | bae5a17 | 2017-08-06 15:42:06 +0200 | [diff] [blame] | 18 | func Test_block_shift_overflow() |
| 19 | " This used to cause a multiplication overflow followed by a crash. |
| 20 | new |
| 21 | normal ii |
| 22 | exe "normal \<C-V>876543210>" |
| 23 | q! |
| 24 | endfunc |
| 25 | |
Bram Moolenaar | f8eb9c5 | 2017-01-02 17:31:24 +0100 | [diff] [blame] | 26 | func Test_dotregister_paste() |
| 27 | new |
| 28 | exe "norm! ihello world\<esc>" |
| 29 | norm! 0ve".p |
| 30 | call assert_equal('hello world world', getline(1)) |
| 31 | q! |
| 32 | endfunc |
Bram Moolenaar | 23fa81d | 2017-02-01 21:50:21 +0100 | [diff] [blame] | 33 | |
| 34 | func Test_Visual_ctrl_o() |
| 35 | new |
| 36 | call setline(1, ['one', 'two', 'three']) |
| 37 | call cursor(1,2) |
| 38 | set noshowmode |
| 39 | set tw=0 |
| 40 | call feedkeys("\<c-v>jjlIa\<c-\>\<c-o>:set tw=88\<cr>\<esc>", 'tx') |
| 41 | call assert_equal(['oane', 'tawo', 'tahree'], getline(1, 3)) |
| 42 | call assert_equal(88, &tw) |
| 43 | set tw& |
| 44 | bw! |
| 45 | endfu |
Bram Moolenaar | 84b2a38 | 2017-02-17 11:40:00 +0100 | [diff] [blame] | 46 | |
| 47 | func Test_Visual_vapo() |
| 48 | new |
| 49 | normal oxx |
| 50 | normal vapo |
| 51 | bwipe! |
| 52 | endfunc |
Bram Moolenaar | 46522af | 2017-02-18 23:12:01 +0100 | [diff] [blame] | 53 | |
| 54 | func Test_Visual_inner_quote() |
| 55 | new |
| 56 | normal oxX |
| 57 | normal vki' |
| 58 | bwipe! |
| 59 | endfunc |
Bram Moolenaar | 75373f3 | 2017-08-07 22:02:30 +0200 | [diff] [blame] | 60 | |
| 61 | " Test for Visual mode not being reset causing E315 error. |
| 62 | func TriggerTheProblem() |
| 63 | " At this point there is no visual selection because :call reset it. |
| 64 | " Let's restore the selection: |
| 65 | normal gv |
| 66 | '<,'>del _ |
| 67 | try |
| 68 | exe "normal \<Esc>" |
| 69 | catch /^Vim\%((\a\+)\)\=:E315/ |
| 70 | echom 'Snap! E315 error!' |
Bram Moolenaar | 63e82db | 2018-03-06 12:10:48 +0100 | [diff] [blame] | 71 | let g:msg = 'Snap! E315 error!' |
Bram Moolenaar | 75373f3 | 2017-08-07 22:02:30 +0200 | [diff] [blame] | 72 | endtry |
| 73 | endfunc |
| 74 | |
| 75 | func Test_visual_mode_reset() |
Bram Moolenaar | 75373f3 | 2017-08-07 22:02:30 +0200 | [diff] [blame] | 76 | enew |
Bram Moolenaar | 63e82db | 2018-03-06 12:10:48 +0100 | [diff] [blame] | 77 | let g:msg = "Everything's fine." |
Bram Moolenaar | 75373f3 | 2017-08-07 22:02:30 +0200 | [diff] [blame] | 78 | enew |
| 79 | setl buftype=nofile |
| 80 | call append(line('$'), 'Delete this line.') |
| 81 | |
| 82 | " NOTE: this has to be done by a call to a function because executing :del |
| 83 | " the ex-way will require the colon operator which resets the visual mode |
| 84 | " thus preventing the problem: |
| 85 | exe "normal! GV:call TriggerTheProblem()\<CR>" |
| 86 | call assert_equal("Everything's fine.", g:msg) |
Bram Moolenaar | 75373f3 | 2017-08-07 22:02:30 +0200 | [diff] [blame] | 87 | endfunc |
Bram Moolenaar | 67418d9 | 2017-10-15 22:07:39 +0200 | [diff] [blame] | 88 | |
Bram Moolenaar | 15993ce | 2017-10-26 20:21:44 +0200 | [diff] [blame] | 89 | " Test for visual block shift and tab characters. |
| 90 | func Test_block_shift_tab() |
Bram Moolenaar | 3e72dca | 2021-05-29 16:30:12 +0200 | [diff] [blame] | 91 | new |
Bram Moolenaar | 15993ce | 2017-10-26 20:21:44 +0200 | [diff] [blame] | 92 | call append(0, repeat(['one two three'], 5)) |
| 93 | call cursor(1,1) |
| 94 | exe "normal i\<C-G>u" |
| 95 | exe "normal fe\<C-V>4jR\<Esc>ugvr1" |
| 96 | call assert_equal('on1 two three', getline(1)) |
| 97 | call assert_equal('on1 two three', getline(2)) |
| 98 | call assert_equal('on1 two three', getline(5)) |
| 99 | |
Bram Moolenaar | 3e72dca | 2021-05-29 16:30:12 +0200 | [diff] [blame] | 100 | %d _ |
Bram Moolenaar | 15993ce | 2017-10-26 20:21:44 +0200 | [diff] [blame] | 101 | call append(0, repeat(['abcdefghijklmnopqrstuvwxyz'], 5)) |
| 102 | call cursor(1,1) |
| 103 | exe "normal \<C-V>4jI \<Esc>j<<11|D" |
| 104 | exe "normal j7|a\<Tab>\<Tab>" |
| 105 | exe "normal j7|a\<Tab>\<Tab> " |
| 106 | exe "normal j7|a\<Tab> \<Tab>\<Esc>4k13|\<C-V>4j<" |
| 107 | call assert_equal(' abcdefghijklmnopqrstuvwxyz', getline(1)) |
| 108 | call assert_equal('abcdefghij', getline(2)) |
| 109 | call assert_equal(" abc\<Tab> defghijklmnopqrstuvwxyz", getline(3)) |
| 110 | call assert_equal(" abc\<Tab> defghijklmnopqrstuvwxyz", getline(4)) |
| 111 | call assert_equal(" abc\<Tab> defghijklmnopqrstuvwxyz", getline(5)) |
| 112 | |
| 113 | %s/\s\+//g |
| 114 | call cursor(1,1) |
| 115 | exe "normal \<C-V>4jI \<Esc>j<<" |
| 116 | exe "normal j7|a\<Tab>\<Tab>" |
| 117 | exe "normal j7|a\<Tab>\<Tab>\<Tab>\<Tab>\<Tab>" |
| 118 | exe "normal j7|a\<Tab> \<Tab>\<Tab>\<Esc>4k13|\<C-V>4j3<" |
| 119 | call assert_equal(' abcdefghijklmnopqrstuvwxyz', getline(1)) |
| 120 | call assert_equal('abcdefghij', getline(2)) |
| 121 | call assert_equal(" abc\<Tab> defghijklmnopqrstuvwxyz", getline(3)) |
| 122 | call assert_equal(" abc\<Tab>\<Tab>defghijklmnopqrstuvwxyz", getline(4)) |
| 123 | call assert_equal(" abc\<Tab> defghijklmnopqrstuvwxyz", getline(5)) |
| 124 | |
Bram Moolenaar | 3e72dca | 2021-05-29 16:30:12 +0200 | [diff] [blame] | 125 | " Test for block shift with space characters at the beginning and with |
| 126 | " 'noexpandtab' and 'expandtab' |
| 127 | %d _ |
| 128 | call setline(1, [" 1", " 2", " 3"]) |
| 129 | setlocal shiftwidth=2 noexpandtab |
| 130 | exe "normal gg\<C-V>3j>" |
| 131 | call assert_equal(["\t1", "\t2", "\t3"], getline(1, '$')) |
| 132 | %d _ |
| 133 | call setline(1, [" 1", " 2", " 3"]) |
| 134 | setlocal shiftwidth=2 expandtab |
| 135 | exe "normal gg\<C-V>3j>" |
| 136 | call assert_equal([" 1", " 2", " 3"], getline(1, '$')) |
| 137 | setlocal shiftwidth& |
| 138 | |
| 139 | bw! |
Bram Moolenaar | 15993ce | 2017-10-26 20:21:44 +0200 | [diff] [blame] | 140 | endfunc |
| 141 | |
| 142 | " Tests Blockwise Visual when there are TABs before the text. |
| 143 | func Test_blockwise_visual() |
Bram Moolenaar | 3e72dca | 2021-05-29 16:30:12 +0200 | [diff] [blame] | 144 | new |
Bram Moolenaar | 15993ce | 2017-10-26 20:21:44 +0200 | [diff] [blame] | 145 | call append(0, ['123456', |
| 146 | \ '234567', |
| 147 | \ '345678', |
| 148 | \ '', |
| 149 | \ 'test text test tex start here', |
| 150 | \ "\t\tsome text", |
| 151 | \ "\t\ttest text", |
| 152 | \ 'test text']) |
| 153 | call cursor(1,1) |
| 154 | exe "normal /start here$\<CR>" |
| 155 | exe 'normal "by$' . "\<C-V>jjlld" |
| 156 | exe "normal /456$\<CR>" |
| 157 | exe "normal \<C-V>jj" . '"bP' |
| 158 | call assert_equal(['123start here56', |
| 159 | \ '234start here67', |
| 160 | \ '345start here78', |
| 161 | \ '', |
| 162 | \ 'test text test tex rt here', |
| 163 | \ "\t\tsomext", |
| 164 | \ "\t\ttesext"], getline(1, 7)) |
| 165 | |
Bram Moolenaar | 3e72dca | 2021-05-29 16:30:12 +0200 | [diff] [blame] | 166 | bw! |
Bram Moolenaar | 15993ce | 2017-10-26 20:21:44 +0200 | [diff] [blame] | 167 | endfunc |
| 168 | |
Bram Moolenaar | 2e94976 | 2018-05-20 14:06:38 +0200 | [diff] [blame] | 169 | " Test swapping corners in blockwise visual mode with o and O |
| 170 | func Test_blockwise_visual_o_O() |
Bram Moolenaar | 3e72dca | 2021-05-29 16:30:12 +0200 | [diff] [blame] | 171 | new |
Bram Moolenaar | 2e94976 | 2018-05-20 14:06:38 +0200 | [diff] [blame] | 172 | |
| 173 | exe "norm! 10i.\<Esc>Y4P3lj\<C-V>4l2jr " |
| 174 | exe "norm! gvO\<Esc>ra" |
| 175 | exe "norm! gvO\<Esc>rb" |
| 176 | exe "norm! gvo\<C-c>rc" |
| 177 | exe "norm! gvO\<C-c>rd" |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 178 | set selection=exclusive |
| 179 | exe "norm! gvOo\<C-c>re" |
| 180 | call assert_equal('...a be.', getline(4)) |
| 181 | exe "norm! gvOO\<C-c>rf" |
| 182 | set selection& |
Bram Moolenaar | 2e94976 | 2018-05-20 14:06:38 +0200 | [diff] [blame] | 183 | |
| 184 | call assert_equal(['..........', |
| 185 | \ '...c d..', |
| 186 | \ '... ..', |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 187 | \ '...a bf.', |
Bram Moolenaar | 2e94976 | 2018-05-20 14:06:38 +0200 | [diff] [blame] | 188 | \ '..........'], getline(1, '$')) |
| 189 | |
Bram Moolenaar | 3e72dca | 2021-05-29 16:30:12 +0200 | [diff] [blame] | 190 | bw! |
Bram Moolenaar | 2e94976 | 2018-05-20 14:06:38 +0200 | [diff] [blame] | 191 | endfun |
| 192 | |
Bram Moolenaar | 15993ce | 2017-10-26 20:21:44 +0200 | [diff] [blame] | 193 | " Test Virtual replace mode. |
| 194 | func Test_virtual_replace() |
Bram Moolenaar | df0d24b | 2018-03-06 14:22:58 +0100 | [diff] [blame] | 195 | if exists('&t_kD') |
| 196 | let save_t_kD = &t_kD |
| 197 | endif |
| 198 | if exists('&t_kb') |
| 199 | let save_t_kb = &t_kb |
| 200 | endif |
Bram Moolenaar | 15993ce | 2017-10-26 20:21:44 +0200 | [diff] [blame] | 201 | exe "set t_kD=\<C-V>x7f t_kb=\<C-V>x08" |
| 202 | enew! |
| 203 | exe "normal a\nabcdefghi\njk\tlmn\n opq rst\n\<C-D>uvwxyz" |
| 204 | call cursor(1,1) |
| 205 | set ai bs=2 |
| 206 | exe "normal gR0\<C-D> 1\nA\nBCDEFGHIJ\n\tKL\nMNO\nPQR" |
| 207 | call assert_equal([' 1', |
| 208 | \ ' A', |
| 209 | \ ' BCDEFGHIJ', |
| 210 | \ ' KL', |
| 211 | \ ' MNO', |
| 212 | \ ' PQR', |
| 213 | \ ], getline(1, 6)) |
| 214 | normal G |
| 215 | mark a |
| 216 | exe "normal o0\<C-D>\nabcdefghi\njk\tlmn\n opq\trst\n\<C-D>uvwxyz\n" |
| 217 | exe "normal 'ajgR0\<C-D> 1\nA\nBCDEFGHIJ\n\tKL\nMNO\nPQR" . repeat("\<BS>", 29) |
| 218 | call assert_equal([' 1', |
| 219 | \ 'abcdefghi', |
| 220 | \ 'jk lmn', |
| 221 | \ ' opq rst', |
| 222 | \ 'uvwxyz'], getline(7, 11)) |
| 223 | normal G |
| 224 | exe "normal iab\tcdefghi\tjkl" |
| 225 | exe "normal 0gRAB......CDEFGHI.J\<Esc>o" |
| 226 | exe "normal iabcdefghijklmnopqrst\<Esc>0gRAB\tIJKLMNO\tQR" |
| 227 | call assert_equal(['AB......CDEFGHI.Jkl', |
| 228 | \ 'AB IJKLMNO QRst'], getline(12, 13)) |
Bram Moolenaar | 845e0ee | 2020-06-20 16:05:32 +0200 | [diff] [blame] | 229 | |
| 230 | " Test inserting Tab with 'noexpandtab' and 'softabstop' set to 4 |
| 231 | %d |
| 232 | call setline(1, 'aaaaaaaaaaaaa') |
| 233 | set softtabstop=4 |
| 234 | exe "normal gggR\<Tab>\<Tab>x" |
| 235 | call assert_equal("\txaaaa", getline(1)) |
| 236 | set softtabstop& |
| 237 | |
Bram Moolenaar | 15993ce | 2017-10-26 20:21:44 +0200 | [diff] [blame] | 238 | enew! |
Bram Moolenaar | e780848 | 2018-03-06 13:17:23 +0100 | [diff] [blame] | 239 | set noai bs&vim |
Bram Moolenaar | df0d24b | 2018-03-06 14:22:58 +0100 | [diff] [blame] | 240 | if exists('save_t_kD') |
| 241 | let &t_kD = save_t_kD |
| 242 | endif |
| 243 | if exists('save_t_kb') |
| 244 | let &t_kb = save_t_kb |
| 245 | endif |
Bram Moolenaar | 63e82db | 2018-03-06 12:10:48 +0100 | [diff] [blame] | 246 | endfunc |
| 247 | |
| 248 | " Test Virtual replace mode. |
| 249 | func Test_virtual_replace2() |
| 250 | enew! |
| 251 | set bs=2 |
| 252 | exe "normal a\nabcdefghi\njk\tlmn\n opq rst\n\<C-D>uvwxyz" |
| 253 | call cursor(1,1) |
| 254 | " Test 1: Test that del deletes the newline |
| 255 | exe "normal gR0\<del> 1\nA\nBCDEFGHIJ\n\tKL\nMNO\nPQR" |
| 256 | call assert_equal(['0 1', |
| 257 | \ 'A', |
| 258 | \ 'BCDEFGHIJ', |
| 259 | \ ' KL', |
| 260 | \ 'MNO', |
| 261 | \ 'PQR', |
| 262 | \ ], getline(1, 6)) |
| 263 | " Test 2: |
| 264 | " a newline is not deleted, if no newline has been added in virtual replace mode |
| 265 | %d_ |
| 266 | call setline(1, ['abcd', 'efgh', 'ijkl']) |
| 267 | call cursor(2,1) |
| 268 | exe "norm! gR1234\<cr>5\<bs>\<bs>\<bs>" |
| 269 | call assert_equal(['abcd', |
| 270 | \ '123h', |
| 271 | \ 'ijkl'], getline(1, '$')) |
| 272 | " Test 3: |
| 273 | " a newline is deleted, if a newline has been inserted before in virtual replace mode |
| 274 | %d_ |
| 275 | call setline(1, ['abcd', 'efgh', 'ijkl']) |
| 276 | call cursor(2,1) |
| 277 | exe "norm! gR1234\<cr>\<cr>56\<bs>\<bs>\<bs>" |
| 278 | call assert_equal(['abcd', |
| 279 | \ '1234', |
| 280 | \ 'ijkl'], getline(1, '$')) |
| 281 | " Test 4: |
| 282 | " delete add a newline, delete it, add it again and check undo |
| 283 | %d_ |
| 284 | call setline(1, ['abcd', 'efgh', 'ijkl']) |
| 285 | call cursor(2,1) |
| 286 | " break undo sequence explicitly |
| 287 | let &ul = &ul |
| 288 | exe "norm! gR1234\<cr>\<bs>\<del>56\<cr>" |
| 289 | let &ul = &ul |
| 290 | call assert_equal(['abcd', |
| 291 | \ '123456', |
| 292 | \ ''], getline(1, '$')) |
| 293 | norm! u |
| 294 | call assert_equal(['abcd', |
| 295 | \ 'efgh', |
| 296 | \ 'ijkl'], getline(1, '$')) |
Bram Moolenaar | ca68ae1 | 2020-03-30 19:32:53 +0200 | [diff] [blame] | 297 | |
| 298 | " Test for truncating spaces in a newly added line using 'autoindent' if |
| 299 | " characters are not added to that line. |
| 300 | %d_ |
| 301 | call setline(1, [' app', ' bee', ' cat']) |
| 302 | setlocal autoindent |
| 303 | exe "normal gg$gRt\n\nr" |
| 304 | call assert_equal([' apt', '', ' rat'], getline(1, '$')) |
| 305 | |
Bram Moolenaar | 63e82db | 2018-03-06 12:10:48 +0100 | [diff] [blame] | 306 | " clean up |
| 307 | %d_ |
| 308 | set bs&vim |
Bram Moolenaar | 15993ce | 2017-10-26 20:21:44 +0200 | [diff] [blame] | 309 | endfunc |
Bram Moolenaar | 6d3a194 | 2019-01-03 23:10:32 +0100 | [diff] [blame] | 310 | |
Bram Moolenaar | 81b1ba4 | 2019-01-13 16:12:40 +0100 | [diff] [blame] | 311 | func Test_Visual_word_textobject() |
| 312 | new |
| 313 | call setline(1, ['First sentence. Second sentence.']) |
| 314 | |
| 315 | " When start and end of visual area are identical, 'aw' or 'iw' select |
| 316 | " the whole word. |
| 317 | norm! 1go2fcvawy |
| 318 | call assert_equal('Second ', @") |
| 319 | norm! 1go2fcviwy |
| 320 | call assert_equal('Second', @") |
| 321 | |
| 322 | " When start and end of visual area are not identical, 'aw' or 'iw' |
| 323 | " extend the word in direction of the end of the visual area. |
| 324 | norm! 1go2fcvlawy |
| 325 | call assert_equal('cond ', @") |
| 326 | norm! gv2awy |
| 327 | call assert_equal('cond sentence.', @") |
| 328 | |
| 329 | norm! 1go2fcvliwy |
| 330 | call assert_equal('cond', @") |
| 331 | norm! gv2iwy |
| 332 | call assert_equal('cond sentence', @") |
| 333 | |
| 334 | " Extend visual area in opposite direction. |
| 335 | norm! 1go2fcvhawy |
| 336 | call assert_equal(' Sec', @") |
| 337 | norm! gv2awy |
| 338 | call assert_equal(' sentence. Sec', @") |
| 339 | |
| 340 | norm! 1go2fcvhiwy |
| 341 | call assert_equal('Sec', @") |
| 342 | norm! gv2iwy |
| 343 | call assert_equal('. Sec', @") |
| 344 | |
| 345 | bwipe! |
| 346 | endfunc |
| 347 | |
Bram Moolenaar | 6d3a194 | 2019-01-03 23:10:32 +0100 | [diff] [blame] | 348 | func Test_Visual_sentence_textobject() |
| 349 | new |
Bram Moolenaar | 81b1ba4 | 2019-01-13 16:12:40 +0100 | [diff] [blame] | 350 | call setline(1, ['First sentence. Second sentence. Third', 'sentence. Fourth sentence']) |
Bram Moolenaar | 6d3a194 | 2019-01-03 23:10:32 +0100 | [diff] [blame] | 351 | |
| 352 | " When start and end of visual area are identical, 'as' or 'is' select |
| 353 | " the whole sentence. |
| 354 | norm! 1gofdvasy |
| 355 | call assert_equal('Second sentence. ', @") |
| 356 | norm! 1gofdvisy |
| 357 | call assert_equal('Second sentence.', @") |
| 358 | |
| 359 | " When start and end of visual area are not identical, 'as' or 'is' |
| 360 | " extend the sentence in direction of the end of the visual area. |
| 361 | norm! 1gofdvlasy |
| 362 | call assert_equal('d sentence. ', @") |
| 363 | norm! gvasy |
| 364 | call assert_equal("d sentence. Third\nsentence. ", @") |
| 365 | |
| 366 | norm! 1gofdvlisy |
| 367 | call assert_equal('d sentence.', @") |
| 368 | norm! gvisy |
| 369 | call assert_equal('d sentence. ', @") |
| 370 | norm! gvisy |
| 371 | call assert_equal("d sentence. Third\nsentence.", @") |
| 372 | |
| 373 | " Extend visual area in opposite direction. |
| 374 | norm! 1gofdvhasy |
| 375 | call assert_equal(' Second', @") |
| 376 | norm! gvasy |
| 377 | call assert_equal("First sentence. Second", @") |
| 378 | |
| 379 | norm! 1gofdvhisy |
| 380 | call assert_equal('Second', @") |
| 381 | norm! gvisy |
| 382 | call assert_equal(' Second', @") |
| 383 | norm! gvisy |
| 384 | call assert_equal('First sentence. Second', @") |
| 385 | |
| 386 | bwipe! |
| 387 | endfunc |
Bram Moolenaar | 81b1ba4 | 2019-01-13 16:12:40 +0100 | [diff] [blame] | 388 | |
| 389 | func Test_Visual_paragraph_textobject() |
| 390 | new |
Bram Moolenaar | 8a9bc95 | 2020-10-02 18:48:07 +0200 | [diff] [blame] | 391 | let lines =<< trim [END] |
| 392 | First line. |
| 393 | |
| 394 | Second line. |
| 395 | Third line. |
| 396 | Fourth line. |
| 397 | Fifth line. |
| 398 | |
| 399 | Sixth line. |
| 400 | [END] |
| 401 | call setline(1, lines) |
Bram Moolenaar | 81b1ba4 | 2019-01-13 16:12:40 +0100 | [diff] [blame] | 402 | |
| 403 | " When start and end of visual area are identical, 'ap' or 'ip' select |
| 404 | " the whole paragraph. |
| 405 | norm! 4ggvapy |
| 406 | call assert_equal("Second line.\nThird line.\nFourth line.\nFifth line.\n\n", @") |
| 407 | norm! 4ggvipy |
| 408 | call assert_equal("Second line.\nThird line.\nFourth line.\nFifth line.\n", @") |
| 409 | |
| 410 | " When start and end of visual area are not identical, 'ap' or 'ip' |
| 411 | " extend the sentence in direction of the end of the visual area. |
| 412 | " FIXME: actually, it is not sufficient to have different start and |
| 413 | " end of visual selection, the start line and end line have to differ, |
| 414 | " which is not consistent with the documentation. |
| 415 | norm! 4ggVjapy |
| 416 | call assert_equal("Third line.\nFourth line.\nFifth line.\n\n", @") |
| 417 | norm! gvapy |
| 418 | call assert_equal("Third line.\nFourth line.\nFifth line.\n\nSixth line.\n", @") |
| 419 | norm! 4ggVjipy |
| 420 | call assert_equal("Third line.\nFourth line.\nFifth line.\n", @") |
| 421 | norm! gvipy |
| 422 | call assert_equal("Third line.\nFourth line.\nFifth line.\n\n", @") |
| 423 | norm! gvipy |
| 424 | call assert_equal("Third line.\nFourth line.\nFifth line.\n\nSixth line.\n", @") |
| 425 | |
| 426 | " Extend visual area in opposite direction. |
| 427 | norm! 5ggVkapy |
| 428 | call assert_equal("\nSecond line.\nThird line.\nFourth line.\n", @") |
| 429 | norm! gvapy |
| 430 | call assert_equal("First line.\n\nSecond line.\nThird line.\nFourth line.\n", @") |
| 431 | norm! 5ggVkipy |
| 432 | call assert_equal("Second line.\nThird line.\nFourth line.\n", @") |
| 433 | norma gvipy |
| 434 | call assert_equal("\nSecond line.\nThird line.\nFourth line.\n", @") |
| 435 | norm! gvipy |
| 436 | call assert_equal("First line.\n\nSecond line.\nThird line.\nFourth line.\n", @") |
| 437 | |
| 438 | bwipe! |
| 439 | endfunc |
Bram Moolenaar | 19a6685 | 2019-03-07 11:25:32 +0100 | [diff] [blame] | 440 | |
| 441 | func Test_curswant_not_changed() |
| 442 | new |
| 443 | call setline(1, ['one', 'two']) |
| 444 | au InsertLeave * call getcurpos() |
| 445 | call feedkeys("gg0\<C-V>jI123 \<Esc>j", 'xt') |
| 446 | call assert_equal([0, 2, 1, 0, 1], getcurpos()) |
| 447 | |
| 448 | bwipe! |
| 449 | au! InsertLeave |
| 450 | endfunc |
Bram Moolenaar | c6b37db | 2019-04-27 18:00:34 +0200 | [diff] [blame] | 451 | |
| 452 | " Tests for "vaBiB", end could be wrong. |
| 453 | func Test_Visual_Block() |
| 454 | new |
| 455 | a |
| 456 | - Bug in "vPPPP" on this text: |
| 457 | { |
| 458 | cmd; |
| 459 | { |
| 460 | cmd;\t/* <-- Start cursor here */ |
| 461 | { |
| 462 | } |
| 463 | } |
| 464 | } |
| 465 | . |
| 466 | normal gg |
| 467 | call search('Start cursor here') |
| 468 | normal vaBiBD |
| 469 | call assert_equal(['- Bug in "vPPPP" on this text:', |
| 470 | \ "\t{", |
| 471 | \ "\t}"], getline(1, '$')) |
| 472 | |
Christian Brabandt | c9a1e25 | 2025-01-11 15:25:00 +0100 | [diff] [blame] | 473 | bw! |
Bram Moolenaar | c6b37db | 2019-04-27 18:00:34 +0200 | [diff] [blame] | 474 | endfunc |
Bram Moolenaar | 6f1f0ca | 2019-12-01 18:16:18 +0100 | [diff] [blame] | 475 | |
| 476 | " Test for 'p'ut in visual block mode |
| 477 | func Test_visual_block_put() |
Bram Moolenaar | 3e72dca | 2021-05-29 16:30:12 +0200 | [diff] [blame] | 478 | new |
Bram Moolenaar | 6f1f0ca | 2019-12-01 18:16:18 +0100 | [diff] [blame] | 479 | call append(0, ['One', 'Two', 'Three']) |
| 480 | normal gg |
| 481 | yank |
| 482 | call feedkeys("jl\<C-V>ljp", 'xt') |
| 483 | call assert_equal(['One', 'T', 'Tee', 'One', ''], getline(1, '$')) |
Bram Moolenaar | 3e72dca | 2021-05-29 16:30:12 +0200 | [diff] [blame] | 484 | bw! |
Bram Moolenaar | 6f1f0ca | 2019-12-01 18:16:18 +0100 | [diff] [blame] | 485 | endfunc |
| 486 | |
Bram Moolenaar | 36343ae | 2022-10-15 19:04:05 +0100 | [diff] [blame] | 487 | func Test_visual_block_put_invalid() |
| 488 | enew! |
| 489 | behave mswin |
| 490 | norm yy |
| 491 | norm v)Ps/^/ |
| 492 | " this was causing the column to become negative |
| 493 | silent norm ggv)P |
| 494 | |
| 495 | bwipe! |
| 496 | behave xterm |
| 497 | endfunc |
| 498 | |
Bram Moolenaar | 309976e | 2019-12-05 18:16:33 +0100 | [diff] [blame] | 499 | " Visual modes (v V CTRL-V) followed by an operator; count; repeating |
| 500 | func Test_visual_mode_op() |
| 501 | new |
| 502 | call append(0, '') |
| 503 | |
| 504 | call setline(1, 'apple banana cherry') |
| 505 | call cursor(1, 1) |
| 506 | normal lvld.l3vd. |
| 507 | call assert_equal('a y', getline(1)) |
| 508 | |
| 509 | call setline(1, ['line 1 line 1', 'line 2 line 2', 'line 3 line 3', |
| 510 | \ 'line 4 line 4', 'line 5 line 5', 'line 6 line 6']) |
| 511 | call cursor(1, 1) |
| 512 | exe "normal Vcnewline\<Esc>j.j2Vd." |
| 513 | call assert_equal(['newline', 'newline'], getline(1, '$')) |
| 514 | |
| 515 | call deletebufline('', 1, '$') |
| 516 | call setline(1, ['xxxxxxxxxxxxx', 'xxxxxxxxxxxxx', 'xxxxxxxxxxxxx', |
| 517 | \ 'xxxxxxxxxxxxx']) |
| 518 | exe "normal \<C-V>jlc \<Esc>l.l2\<C-V>c----\<Esc>l." |
| 519 | call assert_equal([' --------x', |
| 520 | \ ' --------x', |
| 521 | \ 'xxxx--------x', |
| 522 | \ 'xxxx--------x'], getline(1, '$')) |
| 523 | |
| 524 | bwipe! |
| 525 | endfunc |
| 526 | |
| 527 | " Visual mode maps (movement and text object) |
| 528 | " Visual mode maps; count; repeating |
| 529 | " - Simple |
| 530 | " - With an Ex command (custom text object) |
| 531 | func Test_visual_mode_maps() |
| 532 | new |
| 533 | call append(0, '') |
| 534 | |
| 535 | func SelectInCaps() |
| 536 | let [line1, col1] = searchpos('\u', 'bcnW') |
| 537 | let [line2, col2] = searchpos('.\u', 'nW') |
| 538 | call setpos("'<", [0, line1, col1, 0]) |
| 539 | call setpos("'>", [0, line2, col2, 0]) |
| 540 | normal! gv |
| 541 | endfunction |
| 542 | |
| 543 | vnoremap W /\u/s-1<CR> |
| 544 | vnoremap iW :<C-U>call SelectInCaps()<CR> |
| 545 | |
| 546 | call setline(1, 'KiwiRaspberryDateWatermelonPeach') |
| 547 | call cursor(1, 1) |
| 548 | exe "normal vWcNo\<Esc>l.fD2vd." |
| 549 | call assert_equal('NoNoberryach', getline(1)) |
| 550 | |
| 551 | call setline(1, 'JambuRambutanBananaTangerineMango') |
| 552 | call cursor(1, 1) |
| 553 | exe "normal llviWc-\<Esc>l.l2vdl." |
| 554 | call assert_equal('--ago', getline(1)) |
| 555 | |
| 556 | vunmap W |
| 557 | vunmap iW |
| 558 | bwipe! |
| 559 | delfunc SelectInCaps |
| 560 | endfunc |
| 561 | |
| 562 | " Operator-pending mode maps (movement and text object) |
| 563 | " - Simple |
| 564 | " - With Ex command moving the cursor |
| 565 | " - With Ex command and Visual selection (custom text object) |
| 566 | func Test_visual_oper_pending_mode_maps() |
| 567 | new |
| 568 | call append(0, '') |
| 569 | |
| 570 | func MoveToCap() |
| 571 | call search('\u', 'W') |
| 572 | endfunction |
| 573 | |
| 574 | func SelectInCaps() |
| 575 | let [line1, col1] = searchpos('\u', 'bcnW') |
| 576 | let [line2, col2] = searchpos('.\u', 'nW') |
| 577 | call setpos("'<", [0, line1, col1, 0]) |
| 578 | call setpos("'>", [0, line2, col2, 0]) |
| 579 | normal! gv |
| 580 | endfunction |
| 581 | |
| 582 | onoremap W /\u/<CR> |
| 583 | onoremap <Leader>W :<C-U>call MoveToCap()<CR> |
| 584 | onoremap iW :<C-U>call SelectInCaps()<CR> |
| 585 | |
| 586 | call setline(1, 'PineappleQuinceLoganberryOrangeGrapefruitKiwiZ') |
| 587 | call cursor(1, 1) |
| 588 | exe "normal cW-\<Esc>l.l2.l." |
| 589 | call assert_equal('----Z', getline(1)) |
| 590 | |
| 591 | call setline(1, 'JuniperDurianZ') |
| 592 | call cursor(1, 1) |
| 593 | exe "normal g?\WfD." |
| 594 | call assert_equal('WhavcreQhevnaZ', getline(1)) |
| 595 | |
| 596 | call setline(1, 'LemonNectarineZ') |
| 597 | call cursor(1, 1) |
| 598 | exe "normal yiWPlciWNew\<Esc>fr." |
| 599 | call assert_equal('LemonNewNewZ', getline(1)) |
| 600 | |
| 601 | ounmap W |
| 602 | ounmap <Leader>W |
| 603 | ounmap iW |
| 604 | bwipe! |
| 605 | delfunc MoveToCap |
| 606 | delfunc SelectInCaps |
| 607 | endfunc |
| 608 | |
| 609 | " Patch 7.3.879: Properly abort Operator-pending mode for "dv:<Esc>" etc. |
| 610 | func Test_op_pend_mode_abort() |
| 611 | new |
| 612 | call append(0, '') |
| 613 | |
| 614 | call setline(1, ['zzzz', 'zzzz']) |
| 615 | call cursor(1, 1) |
| 616 | |
| 617 | exe "normal dV:\<CR>dv:\<CR>" |
| 618 | call assert_equal(['zzz'], getline(1, 2)) |
| 619 | set nomodifiable |
| 620 | call assert_fails('exe "normal d:\<CR>"', 'E21:') |
| 621 | set modifiable |
| 622 | call feedkeys("dv:\<Esc>dV:\<Esc>", 'xt') |
| 623 | call assert_equal(['zzz'], getline(1, 2)) |
| 624 | set nomodifiable |
| 625 | let v:errmsg = '' |
| 626 | call feedkeys("d:\<Esc>", 'xt') |
| 627 | call assert_true(v:errmsg !~# '^E21:') |
| 628 | set modifiable |
| 629 | |
| 630 | bwipe! |
| 631 | endfunc |
| 632 | |
| 633 | func Test_characterwise_visual_mode() |
| 634 | new |
| 635 | |
| 636 | " characterwise visual mode: replace last line |
| 637 | $put ='a' |
| 638 | let @" = 'x' |
| 639 | normal v$p |
| 640 | call assert_equal('x', getline('$')) |
| 641 | |
| 642 | " characterwise visual mode: delete middle line |
| 643 | call deletebufline('', 1, '$') |
| 644 | call append('$', ['a', 'b', 'c']) |
| 645 | normal G |
| 646 | normal kkv$d |
| 647 | call assert_equal(['', 'b', 'c'], getline(1, '$')) |
| 648 | |
| 649 | " characterwise visual mode: delete middle two lines |
| 650 | call deletebufline('', 1, '$') |
| 651 | call append('$', ['a', 'b', 'c']) |
| 652 | normal Gkkvj$d |
| 653 | call assert_equal(['', 'c'], getline(1, '$')) |
| 654 | |
| 655 | " characterwise visual mode: delete last line |
| 656 | call deletebufline('', 1, '$') |
| 657 | call append('$', ['a', 'b', 'c']) |
| 658 | normal Gv$d |
| 659 | call assert_equal(['', 'a', 'b', ''], getline(1, '$')) |
| 660 | |
| 661 | " characterwise visual mode: delete last two lines |
| 662 | call deletebufline('', 1, '$') |
| 663 | call append('$', ['a', 'b', 'c']) |
| 664 | normal Gkvj$d |
| 665 | call assert_equal(['', 'a', ''], getline(1, '$')) |
| 666 | |
Bram Moolenaar | 8a9bc95 | 2020-10-02 18:48:07 +0200 | [diff] [blame] | 667 | " characterwise visual mode: use a count with the visual mode from the last |
| 668 | " line in the buffer |
| 669 | %d _ |
| 670 | call setline(1, ['one', 'two', 'three', 'four']) |
| 671 | norm! vj$y |
| 672 | norm! G1vy |
| 673 | call assert_equal('four', @") |
| 674 | |
Bram Moolenaar | 3e72dca | 2021-05-29 16:30:12 +0200 | [diff] [blame] | 675 | " characterwise visual mode: replace a single character line and the eol |
| 676 | %d _ |
| 677 | call setline(1, "a") |
| 678 | normal v$rx |
| 679 | call assert_equal(['x'], getline(1, '$')) |
| 680 | |
Bram Moolenaar | 6ecf58b | 2021-12-16 10:05:41 +0000 | [diff] [blame] | 681 | " replace a character with composing characters |
| 682 | call setline(1, "xã̳x") |
| 683 | normal gg0lvrb |
| 684 | call assert_equal("xbx", getline(1)) |
| 685 | |
Bram Moolenaar | 309976e | 2019-12-05 18:16:33 +0100 | [diff] [blame] | 686 | bwipe! |
| 687 | endfunc |
| 688 | |
Bram Moolenaar | 309976e | 2019-12-05 18:16:33 +0100 | [diff] [blame] | 689 | func Test_visual_mode_put() |
| 690 | new |
| 691 | |
| 692 | " v_p: replace last character with line register at middle line |
| 693 | call append('$', ['aaa', 'bbb', 'ccc']) |
| 694 | normal G |
| 695 | -2yank |
| 696 | normal k$vp |
| 697 | call assert_equal(['', 'aaa', 'bb', 'aaa', '', 'ccc'], getline(1, '$')) |
| 698 | |
| 699 | " v_p: replace last character with line register at middle line selecting |
| 700 | " newline |
| 701 | call deletebufline('', 1, '$') |
| 702 | call append('$', ['aaa', 'bbb', 'ccc']) |
| 703 | normal G |
| 704 | -2yank |
| 705 | normal k$v$p |
| 706 | call assert_equal(['', 'aaa', 'bb', 'aaa', 'ccc'], getline(1, '$')) |
| 707 | |
| 708 | " v_p: replace last character with line register at last line |
| 709 | call deletebufline('', 1, '$') |
| 710 | call append('$', ['aaa', 'bbb', 'ccc']) |
| 711 | normal G |
| 712 | -2yank |
| 713 | normal $vp |
| 714 | call assert_equal(['', 'aaa', 'bbb', 'cc', 'aaa', ''], getline(1, '$')) |
| 715 | |
| 716 | " v_p: replace last character with line register at last line selecting |
| 717 | " newline |
| 718 | call deletebufline('', 1, '$') |
| 719 | call append('$', ['aaa', 'bbb', 'ccc']) |
| 720 | normal G |
| 721 | -2yank |
| 722 | normal $v$p |
| 723 | call assert_equal(['', 'aaa', 'bbb', 'cc', 'aaa', ''], getline(1, '$')) |
| 724 | |
| 725 | bwipe! |
| 726 | endfunc |
| 727 | |
Bram Moolenaar | 515545e | 2020-03-22 14:08:59 +0100 | [diff] [blame] | 728 | func Test_gv_with_exclusive_selection() |
Bram Moolenaar | 309976e | 2019-12-05 18:16:33 +0100 | [diff] [blame] | 729 | new |
| 730 | |
Bram Moolenaar | 515545e | 2020-03-22 14:08:59 +0100 | [diff] [blame] | 731 | " gv with exclusive selection after an operation |
Bram Moolenaar | 309976e | 2019-12-05 18:16:33 +0100 | [diff] [blame] | 732 | call append('$', ['zzz ', 'äà ']) |
| 733 | set selection=exclusive |
| 734 | normal Gkv3lyjv3lpgvcxxx |
| 735 | call assert_equal(['', 'zzz ', 'xxx '], getline(1, '$')) |
| 736 | |
Bram Moolenaar | 515545e | 2020-03-22 14:08:59 +0100 | [diff] [blame] | 737 | " gv with exclusive selection without an operation |
Bram Moolenaar | 309976e | 2019-12-05 18:16:33 +0100 | [diff] [blame] | 738 | call deletebufline('', 1, '$') |
| 739 | call append('$', 'zzz ') |
| 740 | set selection=exclusive |
| 741 | exe "normal G0v3l\<Esc>gvcxxx" |
| 742 | call assert_equal(['', 'xxx '], getline(1, '$')) |
| 743 | |
| 744 | set selection&vim |
| 745 | bwipe! |
| 746 | endfunc |
| 747 | |
Bram Moolenaar | 1f3e7d3 | 2019-12-06 20:43:36 +0100 | [diff] [blame] | 748 | " Tests for the visual block mode commands |
| 749 | func Test_visual_block_mode() |
| 750 | new |
| 751 | call append(0, '') |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 752 | call setline(1, repeat(['abcdefghijklm'], 5)) |
Bram Moolenaar | 1f3e7d3 | 2019-12-06 20:43:36 +0100 | [diff] [blame] | 753 | call cursor(1, 1) |
| 754 | |
| 755 | " Test shift-right of a block |
| 756 | exe "normal jllll\<C-V>jj>wll\<C-V>jlll>" |
| 757 | " Test shift-left of a block |
| 758 | exe "normal G$hhhh\<C-V>kk<" |
| 759 | " Test block-insert |
| 760 | exe "normal Gkl\<C-V>kkkIxyz" |
| 761 | " Test block-replace |
| 762 | exe "normal Gllll\<C-V>kkklllrq" |
| 763 | " Test block-change |
| 764 | exe "normal G$khhh\<C-V>hhkkcmno" |
| 765 | call assert_equal(['axyzbcdefghijklm', |
| 766 | \ 'axyzqqqq mno ghijklm', |
| 767 | \ 'axyzqqqqef mno ghijklm', |
| 768 | \ 'axyzqqqqefgmnoklm', |
| 769 | \ 'abcdqqqqijklm'], getline(1, 5)) |
| 770 | |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 771 | " Test 'C' to change till the end of the line |
| 772 | call cursor(3, 4) |
| 773 | exe "normal! \<C-V>j3lCooo" |
| 774 | call assert_equal(['axyooo', 'axyooo'], getline(3, 4)) |
| 775 | |
| 776 | " Test 'D' to delete till the end of the line |
| 777 | call cursor(3, 3) |
| 778 | exe "normal! \<C-V>j2lD" |
| 779 | call assert_equal(['ax', 'ax'], getline(3, 4)) |
| 780 | |
Bram Moolenaar | 3e72dca | 2021-05-29 16:30:12 +0200 | [diff] [blame] | 781 | " Test block insert with a short line that ends before the block |
| 782 | %d _ |
| 783 | call setline(1, [" one", "a", " two"]) |
| 784 | exe "normal gg\<C-V>2jIx" |
| 785 | call assert_equal([" xone", "a", " xtwo"], getline(1, '$')) |
| 786 | |
| 787 | " Test block append at EOL with '$' and without '$' |
| 788 | %d _ |
| 789 | call setline(1, ["one", "a", "two"]) |
| 790 | exe "normal gg$\<C-V>2jAx" |
| 791 | call assert_equal(["onex", "ax", "twox"], getline(1, '$')) |
| 792 | %d _ |
| 793 | call setline(1, ["one", "a", "two"]) |
| 794 | exe "normal gg3l\<C-V>2jAx" |
| 795 | call assert_equal(["onex", "a x", "twox"], getline(1, '$')) |
| 796 | |
| 797 | " Test block replace with an empty line in the middle and use $ to jump to |
| 798 | " the end of the line. |
| 799 | %d _ |
| 800 | call setline(1, ['one', '', 'two']) |
| 801 | exe "normal gg$\<C-V>2jrx" |
| 802 | call assert_equal(["onx", "", "twx"], getline(1, '$')) |
| 803 | |
| 804 | " Test block replace with an empty line in the middle and move cursor to the |
| 805 | " end of the line |
| 806 | %d _ |
| 807 | call setline(1, ['one', '', 'two']) |
| 808 | exe "normal gg2l\<C-V>2jrx" |
| 809 | call assert_equal(["onx", "", "twx"], getline(1, '$')) |
| 810 | |
| 811 | " Replace odd number of characters with a multibyte character |
| 812 | %d _ |
| 813 | call setline(1, ['abcd', 'efgh']) |
| 814 | exe "normal ggl\<C-V>2ljr\u1100" |
| 815 | call assert_equal(["a\u1100 ", "e\u1100 "], getline(1, '$')) |
| 816 | |
| 817 | " During visual block append, if the cursor moved outside of the selected |
| 818 | " range, then the edit should not be applied to the block. |
| 819 | %d _ |
| 820 | call setline(1, ['aaa', 'bbb', 'ccc']) |
| 821 | exe "normal 2G\<C-V>jAx\<Up>" |
| 822 | call assert_equal(['aaa', 'bxbb', 'ccc'], getline(1, '$')) |
| 823 | |
| 824 | " During visual block append, if the cursor is moved before the start of the |
| 825 | " block, then the new text should be appended there. |
| 826 | %d _ |
| 827 | call setline(1, ['aaa', 'bbb', 'ccc']) |
| 828 | exe "normal $\<C-V>2jA\<Left>x" |
Bram Moolenaar | 4067bd3 | 2021-06-29 18:54:35 +0200 | [diff] [blame] | 829 | call assert_equal(['aaxa', 'bbxb', 'ccxc'], getline(1, '$')) |
Yegappan Lakshmanan | 59b2623 | 2021-06-05 20:59:22 +0200 | [diff] [blame] | 830 | " Repeat the previous test but use 'l' to move the cursor instead of '$' |
| 831 | call setline(1, ['aaa', 'bbb', 'ccc']) |
| 832 | exe "normal! gg2l\<C-V>2jA\<Left>x" |
| 833 | call assert_equal(['aaxa', 'bbxb', 'ccxc'], getline(1, '$')) |
Bram Moolenaar | 3e72dca | 2021-05-29 16:30:12 +0200 | [diff] [blame] | 834 | |
| 835 | " Change a characterwise motion to a blockwise motion using CTRL-V |
| 836 | %d _ |
| 837 | call setline(1, ['123', '456', '789']) |
| 838 | exe "normal ld\<C-V>j" |
| 839 | call assert_equal(['13', '46', '789'], getline(1, '$')) |
| 840 | |
Yegappan Lakshmanan | 2ac7184 | 2021-05-31 19:23:01 +0200 | [diff] [blame] | 841 | " Test from ':help v_b_I_example' |
| 842 | %d _ |
| 843 | setlocal tabstop=8 shiftwidth=4 |
| 844 | let lines =<< trim END |
| 845 | abcdefghijklmnopqrstuvwxyz |
| 846 | abc defghijklmnopqrstuvwxyz |
| 847 | abcdef ghi jklmnopqrstuvwxyz |
| 848 | abcdefghijklmnopqrstuvwxyz |
| 849 | END |
| 850 | call setline(1, lines) |
| 851 | exe "normal ggfo\<C-V>3jISTRING" |
| 852 | let expected =<< trim END |
| 853 | abcdefghijklmnSTRINGopqrstuvwxyz |
| 854 | abc STRING defghijklmnopqrstuvwxyz |
| 855 | abcdef ghi STRING jklmnopqrstuvwxyz |
| 856 | abcdefghijklmnSTRINGopqrstuvwxyz |
| 857 | END |
| 858 | call assert_equal(expected, getline(1, '$')) |
| 859 | |
| 860 | " Test from ':help v_b_A_example' |
| 861 | %d _ |
| 862 | let lines =<< trim END |
| 863 | abcdefghijklmnopqrstuvwxyz |
| 864 | abc defghijklmnopqrstuvwxyz |
| 865 | abcdef ghi jklmnopqrstuvwxyz |
| 866 | abcdefghijklmnopqrstuvwxyz |
| 867 | END |
| 868 | call setline(1, lines) |
| 869 | exe "normal ggfo\<C-V>3j$ASTRING" |
| 870 | let expected =<< trim END |
| 871 | abcdefghijklmnopqrstuvwxyzSTRING |
| 872 | abc defghijklmnopqrstuvwxyzSTRING |
| 873 | abcdef ghi jklmnopqrstuvwxyzSTRING |
| 874 | abcdefghijklmnopqrstuvwxyzSTRING |
| 875 | END |
| 876 | call assert_equal(expected, getline(1, '$')) |
| 877 | |
| 878 | " Test from ':help v_b_<_example' |
| 879 | %d _ |
| 880 | let lines =<< trim END |
| 881 | abcdefghijklmnopqrstuvwxyz |
| 882 | abc defghijklmnopqrstuvwxyz |
| 883 | abcdef ghi jklmnopqrstuvwxyz |
| 884 | abcdefghijklmnopqrstuvwxyz |
| 885 | END |
| 886 | call setline(1, lines) |
| 887 | exe "normal ggfo\<C-V>3j3l<.." |
| 888 | let expected =<< trim END |
| 889 | abcdefghijklmnopqrstuvwxyz |
| 890 | abc defghijklmnopqrstuvwxyz |
| 891 | abcdef ghi jklmnopqrstuvwxyz |
| 892 | abcdefghijklmnopqrstuvwxyz |
| 893 | END |
| 894 | call assert_equal(expected, getline(1, '$')) |
| 895 | |
| 896 | " Test from ':help v_b_>_example' |
| 897 | %d _ |
| 898 | let lines =<< trim END |
| 899 | abcdefghijklmnopqrstuvwxyz |
| 900 | abc defghijklmnopqrstuvwxyz |
| 901 | abcdef ghi jklmnopqrstuvwxyz |
| 902 | abcdefghijklmnopqrstuvwxyz |
| 903 | END |
| 904 | call setline(1, lines) |
| 905 | exe "normal ggfo\<C-V>3j>.." |
| 906 | let expected =<< trim END |
| 907 | abcdefghijklmn opqrstuvwxyz |
| 908 | abc defghijklmnopqrstuvwxyz |
| 909 | abcdef ghi jklmnopqrstuvwxyz |
| 910 | abcdefghijklmn opqrstuvwxyz |
| 911 | END |
| 912 | call assert_equal(expected, getline(1, '$')) |
| 913 | |
| 914 | " Test from ':help v_b_r_example' |
| 915 | %d _ |
| 916 | let lines =<< trim END |
| 917 | abcdefghijklmnopqrstuvwxyz |
| 918 | abc defghijklmnopqrstuvwxyz |
| 919 | abcdef ghi jklmnopqrstuvwxyz |
| 920 | abcdefghijklmnopqrstuvwxyz |
| 921 | END |
| 922 | call setline(1, lines) |
| 923 | exe "normal ggfo\<C-V>5l3jrX" |
| 924 | let expected =<< trim END |
| 925 | abcdefghijklmnXXXXXXuvwxyz |
| 926 | abc XXXXXXhijklmnopqrstuvwxyz |
| 927 | abcdef ghi XXXXXX jklmnopqrstuvwxyz |
| 928 | abcdefghijklmnXXXXXXuvwxyz |
| 929 | END |
| 930 | call assert_equal(expected, getline(1, '$')) |
| 931 | |
Bram Moolenaar | 1f3e7d3 | 2019-12-06 20:43:36 +0100 | [diff] [blame] | 932 | bwipe! |
Yegappan Lakshmanan | 2ac7184 | 2021-05-31 19:23:01 +0200 | [diff] [blame] | 933 | set tabstop& shiftwidth& |
Bram Moolenaar | 1f3e7d3 | 2019-12-06 20:43:36 +0100 | [diff] [blame] | 934 | endfunc |
| 935 | |
Bram Moolenaar | 2149274 | 2021-06-04 21:57:57 +0200 | [diff] [blame] | 936 | func Test_visual_force_motion_feedkeys() |
| 937 | onoremap <expr> i- execute('let g:mode = mode(1)')->slice(0, 0) |
| 938 | call feedkeys('dvi-', 'x') |
| 939 | call assert_equal('nov', g:mode) |
| 940 | call feedkeys('di-', 'x') |
| 941 | call assert_equal('no', g:mode) |
| 942 | ounmap i- |
| 943 | endfunc |
| 944 | |
Bram Moolenaar | 1f3e7d3 | 2019-12-06 20:43:36 +0100 | [diff] [blame] | 945 | " Test block-insert using cursor keys for movement |
| 946 | func Test_visual_block_insert_cursor_keys() |
| 947 | new |
| 948 | call append(0, ['aaaaaa', 'bbbbbb', 'cccccc', 'dddddd']) |
| 949 | call cursor(1, 1) |
| 950 | |
| 951 | exe "norm! l\<C-V>jjjlllI\<Right>\<Right> \<Esc>" |
| 952 | call assert_equal(['aaa aaa', 'bbb bbb', 'ccc ccc', 'ddd ddd'], |
| 953 | \ getline(1, 4)) |
| 954 | |
| 955 | call deletebufline('', 1, '$') |
| 956 | call setline(1, ['xaaa', 'bbbb', 'cccc', 'dddd']) |
| 957 | call cursor(1, 1) |
| 958 | exe "norm! \<C-V>jjjI<>\<Left>p\<Esc>" |
| 959 | call assert_equal(['<p>xaaa', '<p>bbbb', '<p>cccc', '<p>dddd'], |
| 960 | \ getline(1, 4)) |
| 961 | bwipe! |
| 962 | endfunc |
| 963 | |
| 964 | func Test_visual_block_create() |
| 965 | new |
| 966 | call append(0, '') |
| 967 | " Test for Visual block was created with the last <C-v>$ |
| 968 | call setline(1, ['A23', '4567']) |
| 969 | call cursor(1, 1) |
| 970 | exe "norm! l\<C-V>j$Aab\<Esc>" |
| 971 | call assert_equal(['A23ab', '4567ab'], getline(1, 2)) |
| 972 | |
| 973 | " Test for Visual block was created with the middle <C-v>$ (1) |
| 974 | call deletebufline('', 1, '$') |
| 975 | call setline(1, ['B23', '4567']) |
| 976 | call cursor(1, 1) |
| 977 | exe "norm! l\<C-V>j$hAab\<Esc>" |
| 978 | call assert_equal(['B23 ab', '4567ab'], getline(1, 2)) |
| 979 | |
| 980 | " Test for Visual block was created with the middle <C-v>$ (2) |
| 981 | call deletebufline('', 1, '$') |
| 982 | call setline(1, ['C23', '4567']) |
| 983 | call cursor(1, 1) |
| 984 | exe "norm! l\<C-V>j$hhAab\<Esc>" |
| 985 | call assert_equal(['C23ab', '456ab7'], getline(1, 2)) |
| 986 | bwipe! |
| 987 | endfunc |
| 988 | |
| 989 | " Test for Visual block insert when virtualedit=all |
| 990 | func Test_virtualedit_visual_block() |
| 991 | set ve=all |
| 992 | new |
| 993 | call append(0, ["\t\tline1", "\t\tline2", "\t\tline3"]) |
| 994 | call cursor(1, 1) |
| 995 | exe "norm! 07l\<C-V>jjIx\<Esc>" |
| 996 | call assert_equal([" x \tline1", |
| 997 | \ " x \tline2", |
| 998 | \ " x \tline3"], getline(1, 3)) |
| 999 | |
| 1000 | " Test for Visual block append when virtualedit=all |
| 1001 | exe "norm! 012l\<C-v>jjAx\<Esc>" |
| 1002 | call assert_equal([' x x line1', |
| 1003 | \ ' x x line2', |
| 1004 | \ ' x x line3'], getline(1, 3)) |
| 1005 | set ve= |
| 1006 | bwipe! |
| 1007 | endfunc |
| 1008 | |
| 1009 | " Test for changing case |
| 1010 | func Test_visual_change_case() |
| 1011 | new |
zeertzjq | e710220 | 2024-02-13 20:32:04 +0100 | [diff] [blame] | 1012 | " gUe must uppercase a whole word, also when ß changes to ẞ |
Bram Moolenaar | 1f3e7d3 | 2019-12-06 20:43:36 +0100 | [diff] [blame] | 1013 | exe "normal Gothe youtußeuu end\<Esc>Ypk0wgUe\r" |
| 1014 | " gUfx must uppercase until x, inclusive. |
| 1015 | exe "normal O- youßtußexu -\<Esc>0fogUfx\r" |
| 1016 | " VU must uppercase a whole line |
| 1017 | exe "normal YpkVU\r" |
| 1018 | " same, when it's the last line in the buffer |
| 1019 | exe "normal YPGi111\<Esc>VUddP\r" |
| 1020 | " Uppercase two lines |
| 1021 | exe "normal Oblah di\rdoh dut\<Esc>VkUj\r" |
| 1022 | " Uppercase part of two lines |
| 1023 | exe "normal ddppi333\<Esc>k0i222\<Esc>fyllvjfuUk" |
glepnir | bd1232a | 2024-02-12 22:14:53 +0100 | [diff] [blame] | 1024 | call assert_equal(['the YOUTUẞEUU end', '- yOUẞTUẞEXu -', |
| 1025 | \ 'THE YOUTUẞEUU END', '111THE YOUTUẞEUU END', 'BLAH DI', 'DOH DUT', |
| 1026 | \ '222the yoUTUẞEUU END', '333THE YOUTUßeuu end'], getline(2, '$')) |
Bram Moolenaar | 1f3e7d3 | 2019-12-06 20:43:36 +0100 | [diff] [blame] | 1027 | bwipe! |
| 1028 | endfunc |
| 1029 | |
| 1030 | " Test for Visual replace using Enter or NL |
| 1031 | func Test_visual_replace_crnl() |
| 1032 | new |
| 1033 | exe "normal G3o123456789\e2k05l\<C-V>2jr\r" |
| 1034 | exe "normal G3o98765\e2k02l\<C-V>2jr\<C-V>\r\n" |
| 1035 | exe "normal G3o123456789\e2k05l\<C-V>2jr\n" |
| 1036 | exe "normal G3o98765\e2k02l\<C-V>2jr\<C-V>\n" |
| 1037 | call assert_equal(['12345', '789', '12345', '789', '12345', '789', "98\r65", |
| 1038 | \ "98\r65", "98\r65", '12345', '789', '12345', '789', '12345', '789', |
| 1039 | \ "98\n65", "98\n65", "98\n65"], getline(2, '$')) |
| 1040 | bwipe! |
| 1041 | endfunc |
| 1042 | |
| 1043 | func Test_ve_block_curpos() |
| 1044 | new |
| 1045 | " Test cursor position. When ve=block and Visual block mode and $gj |
| 1046 | call append(0, ['12345', '789']) |
| 1047 | call cursor(1, 3) |
| 1048 | set virtualedit=block |
| 1049 | exe "norm! \<C-V>$gj\<Esc>" |
| 1050 | call assert_equal([0, 2, 4, 0], getpos("'>")) |
| 1051 | set virtualedit= |
| 1052 | bwipe! |
| 1053 | endfunc |
| 1054 | |
| 1055 | " Test for block_insert when replacing spaces in front of the a with tabs |
| 1056 | func Test_block_insert_replace_tabs() |
| 1057 | new |
| 1058 | set ts=8 sts=4 sw=4 |
| 1059 | call append(0, ["#define BO_ALL\t 0x0001", |
| 1060 | \ "#define BO_BS\t 0x0002", |
| 1061 | \ "#define BO_CRSR\t 0x0004"]) |
| 1062 | call cursor(1, 1) |
| 1063 | exe "norm! f0\<C-V>2jI\<tab>\<esc>" |
| 1064 | call assert_equal([ |
| 1065 | \ "#define BO_ALL\t\t0x0001", |
| 1066 | \ "#define BO_BS\t \t0x0002", |
| 1067 | \ "#define BO_CRSR\t \t0x0004", ''], getline(1, '$')) |
| 1068 | set ts& sts& sw& |
| 1069 | bwipe! |
| 1070 | endfunc |
| 1071 | |
Bram Moolenaar | bc2b71d | 2020-02-17 21:33:30 +0100 | [diff] [blame] | 1072 | " Test for * register in : |
| 1073 | func Test_star_register() |
| 1074 | call assert_fails('*bfirst', 'E16:') |
| 1075 | new |
| 1076 | call setline(1, ['foo', 'bar', 'baz', 'qux']) |
| 1077 | exe "normal jVj\<ESC>" |
| 1078 | *yank r |
| 1079 | call assert_equal("bar\nbaz\n", @r) |
| 1080 | |
| 1081 | delmarks < > |
| 1082 | call assert_fails('*yank', 'E20:') |
Christian Brabandt | c9a1e25 | 2025-01-11 15:25:00 +0100 | [diff] [blame] | 1083 | bw! |
Bram Moolenaar | bc2b71d | 2020-02-17 21:33:30 +0100 | [diff] [blame] | 1084 | endfunc |
| 1085 | |
Bram Moolenaar | f5f1e10 | 2020-03-08 05:13:15 +0100 | [diff] [blame] | 1086 | " Test for changing text in visual mode with 'exclusive' selection |
| 1087 | func Test_exclusive_selection() |
| 1088 | new |
| 1089 | call setline(1, ['one', 'two']) |
| 1090 | set selection=exclusive |
| 1091 | call feedkeys("vwcabc", 'xt') |
| 1092 | call assert_equal('abctwo', getline(1)) |
| 1093 | call setline(1, ["\tone"]) |
| 1094 | set virtualedit=all |
| 1095 | call feedkeys('0v2lcl', 'xt') |
| 1096 | call assert_equal('l one', getline(1)) |
| 1097 | set virtualedit& |
| 1098 | set selection& |
Christian Brabandt | c9a1e25 | 2025-01-11 15:25:00 +0100 | [diff] [blame] | 1099 | bw! |
Bram Moolenaar | f5f1e10 | 2020-03-08 05:13:15 +0100 | [diff] [blame] | 1100 | endfunc |
| 1101 | |
Bram Moolenaar | d1ad99b | 2020-10-04 16:16:54 +0200 | [diff] [blame] | 1102 | " Test for starting linewise visual with a count. |
| 1103 | " This test needs to be run without any previous visual mode. Otherwise the |
| 1104 | " count will use the count from the previous visual mode. |
| 1105 | func Test_linewise_visual_with_count() |
| 1106 | let after =<< trim [CODE] |
| 1107 | call setline(1, ['one', 'two', 'three', 'four']) |
| 1108 | norm! 3Vy |
| 1109 | call assert_equal("one\ntwo\nthree\n", @") |
| 1110 | call writefile(v:errors, 'Xtestout') |
| 1111 | qall! |
| 1112 | [CODE] |
| 1113 | if RunVim([], after, '') |
| 1114 | call assert_equal([], readfile('Xtestout')) |
| 1115 | call delete('Xtestout') |
| 1116 | endif |
| 1117 | endfunc |
| 1118 | |
| 1119 | " Test for starting characterwise visual with a count. |
| 1120 | " This test needs to be run without any previous visual mode. Otherwise the |
| 1121 | " count will use the count from the previous visual mode. |
| 1122 | func Test_characterwise_visual_with_count() |
| 1123 | let after =<< trim [CODE] |
| 1124 | call setline(1, ['one two', 'three']) |
| 1125 | norm! l5vy |
| 1126 | call assert_equal("ne tw", @") |
| 1127 | call writefile(v:errors, 'Xtestout') |
| 1128 | qall! |
| 1129 | [CODE] |
| 1130 | if RunVim([], after, '') |
| 1131 | call assert_equal([], readfile('Xtestout')) |
| 1132 | call delete('Xtestout') |
| 1133 | endif |
Bram Moolenaar | f5f1e10 | 2020-03-08 05:13:15 +0100 | [diff] [blame] | 1134 | endfunc |
| 1135 | |
Bram Moolenaar | 224a5f1 | 2020-04-28 20:29:07 +0200 | [diff] [blame] | 1136 | " Test for visually selecting an inner block (iB) |
| 1137 | func Test_visual_inner_block() |
| 1138 | new |
| 1139 | call setline(1, ['one', '{', 'two', '{', 'three', '}', 'four', '}', 'five']) |
| 1140 | call cursor(5, 1) |
| 1141 | " visually select all the lines in the block and then execute iB |
| 1142 | call feedkeys("ViB\<C-C>", 'xt') |
| 1143 | call assert_equal([0, 5, 1, 0], getpos("'<")) |
| 1144 | call assert_equal([0, 5, 6, 0], getpos("'>")) |
| 1145 | " visually select two inner blocks |
| 1146 | call feedkeys("ViBiB\<C-C>", 'xt') |
| 1147 | call assert_equal([0, 3, 1, 0], getpos("'<")) |
| 1148 | call assert_equal([0, 7, 5, 0], getpos("'>")) |
| 1149 | " try to select non-existing inner block |
| 1150 | call cursor(5, 1) |
| 1151 | call assert_beeps('normal ViBiBiB') |
zeertzjq | c029c13 | 2024-03-28 11:37:26 +0100 | [diff] [blame] | 1152 | " try to select an unclosed inner block |
Bram Moolenaar | 224a5f1 | 2020-04-28 20:29:07 +0200 | [diff] [blame] | 1153 | 8,9d |
| 1154 | call cursor(5, 1) |
| 1155 | call assert_beeps('normal ViBiB') |
Christian Brabandt | c9a1e25 | 2025-01-11 15:25:00 +0100 | [diff] [blame] | 1156 | bw! |
Bram Moolenaar | 224a5f1 | 2020-04-28 20:29:07 +0200 | [diff] [blame] | 1157 | endfunc |
| 1158 | |
Bram Moolenaar | cd94277 | 2020-08-22 21:08:44 +0200 | [diff] [blame] | 1159 | func Test_visual_put_in_block() |
| 1160 | new |
| 1161 | call setline(1, ['xxxx', 'y∞yy', 'zzzz']) |
| 1162 | normal 1G2yl |
| 1163 | exe "normal 1G2l\<C-V>jjlp" |
| 1164 | call assert_equal(['xxxx', 'y∞xx', 'zzxx'], getline(1, 3)) |
| 1165 | bwipe! |
| 1166 | endfunc |
| 1167 | |
Christian Brabandt | 2fa9384 | 2021-05-30 22:17:25 +0200 | [diff] [blame] | 1168 | func Test_visual_put_in_block_using_zp() |
| 1169 | new |
| 1170 | " paste using zP |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 1171 | call setline(1, ['/path;text', '/path;text', '/path;text', '', |
| 1172 | \ '/subdir', |
Christian Brabandt | 2fa9384 | 2021-05-30 22:17:25 +0200 | [diff] [blame] | 1173 | \ '/longsubdir', |
| 1174 | \ '/longlongsubdir']) |
| 1175 | exe "normal! 5G\<c-v>2j$y" |
| 1176 | norm! 1Gf;zP |
| 1177 | call assert_equal(['/path/subdir;text', '/path/longsubdir;text', '/path/longlongsubdir;text'], getline(1, 3)) |
| 1178 | %d |
| 1179 | " paste using zP |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 1180 | call setline(1, ['/path;text', '/path;text', '/path;text', '', |
| 1181 | \ '/subdir', |
Christian Brabandt | 2fa9384 | 2021-05-30 22:17:25 +0200 | [diff] [blame] | 1182 | \ '/longsubdir', |
| 1183 | \ '/longlongsubdir']) |
| 1184 | exe "normal! 5G\<c-v>2j$y" |
| 1185 | norm! 1Gf;hzp |
| 1186 | call assert_equal(['/path/subdir;text', '/path/longsubdir;text', '/path/longlongsubdir;text'], getline(1, 3)) |
| 1187 | bwipe! |
| 1188 | endfunc |
| 1189 | |
Christian Brabandt | 544a38e | 2021-06-10 19:39:11 +0200 | [diff] [blame] | 1190 | func Test_visual_put_in_block_using_zy_and_zp() |
| 1191 | new |
| 1192 | |
| 1193 | " Test 1) Paste using zp - after the cursor without trailing spaces |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 1194 | call setline(1, ['/path;text', '/path;text', '/path;text', '', |
Christian Brabandt | 544a38e | 2021-06-10 19:39:11 +0200 | [diff] [blame] | 1195 | \ 'texttext /subdir columntext', |
| 1196 | \ 'texttext /longsubdir columntext', |
| 1197 | \ 'texttext /longlongsubdir columntext']) |
| 1198 | exe "normal! 5G0f/\<c-v>2jezy" |
| 1199 | norm! 1G0f;hzp |
| 1200 | call assert_equal(['/path/subdir;text', '/path/longsubdir;text', '/path/longlongsubdir;text'], getline(1, 3)) |
| 1201 | |
| 1202 | " Test 2) Paste using zP - in front of the cursor without trailing spaces |
| 1203 | %d |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 1204 | call setline(1, ['/path;text', '/path;text', '/path;text', '', |
Christian Brabandt | 544a38e | 2021-06-10 19:39:11 +0200 | [diff] [blame] | 1205 | \ 'texttext /subdir columntext', |
| 1206 | \ 'texttext /longsubdir columntext', |
| 1207 | \ 'texttext /longlongsubdir columntext']) |
| 1208 | exe "normal! 5G0f/\<c-v>2jezy" |
| 1209 | norm! 1G0f;zP |
| 1210 | call assert_equal(['/path/subdir;text', '/path/longsubdir;text', '/path/longlongsubdir;text'], getline(1, 3)) |
| 1211 | |
| 1212 | " Test 3) Paste using p - with trailing spaces |
| 1213 | %d |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 1214 | call setline(1, ['/path;text', '/path;text', '/path;text', '', |
Christian Brabandt | 544a38e | 2021-06-10 19:39:11 +0200 | [diff] [blame] | 1215 | \ 'texttext /subdir columntext', |
| 1216 | \ 'texttext /longsubdir columntext', |
| 1217 | \ 'texttext /longlongsubdir columntext']) |
| 1218 | exe "normal! 5G0f/\<c-v>2jezy" |
| 1219 | norm! 1G0f;hp |
| 1220 | call assert_equal(['/path/subdir ;text', '/path/longsubdir ;text', '/path/longlongsubdir;text'], getline(1, 3)) |
| 1221 | |
| 1222 | " Test 4) Paste using P - with trailing spaces |
| 1223 | %d |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 1224 | call setline(1, ['/path;text', '/path;text', '/path;text', '', |
Christian Brabandt | 544a38e | 2021-06-10 19:39:11 +0200 | [diff] [blame] | 1225 | \ 'texttext /subdir columntext', |
| 1226 | \ 'texttext /longsubdir columntext', |
| 1227 | \ 'texttext /longlongsubdir columntext']) |
| 1228 | exe "normal! 5G0f/\<c-v>2jezy" |
| 1229 | norm! 1G0f;P |
| 1230 | call assert_equal(['/path/subdir ;text', '/path/longsubdir ;text', '/path/longlongsubdir;text'], getline(1, 3)) |
| 1231 | |
| 1232 | " Test 5) Yank with spaces inside the block |
| 1233 | %d |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 1234 | call setline(1, ['/path;text', '/path;text', '/path;text', '', |
Christian Brabandt | 544a38e | 2021-06-10 19:39:11 +0200 | [diff] [blame] | 1235 | \ 'texttext /sub dir/ columntext', |
| 1236 | \ 'texttext /lon gsubdir/ columntext', |
| 1237 | \ 'texttext /lon glongsubdir/ columntext']) |
| 1238 | exe "normal! 5G0f/\<c-v>2jf/zy" |
| 1239 | norm! 1G0f;zP |
| 1240 | call assert_equal(['/path/sub dir/;text', '/path/lon gsubdir/;text', '/path/lon glongsubdir/;text'], getline(1, 3)) |
| 1241 | bwipe! |
| 1242 | endfunc |
| 1243 | |
Bram Moolenaar | 7d7bcc6 | 2021-06-28 21:54:27 +0200 | [diff] [blame] | 1244 | func Test_visual_put_blockedit_zy_and_zp() |
| 1245 | new |
| 1246 | |
| 1247 | call setline(1, ['aa', 'bbbbb', 'ccc', '', 'XX', 'GGHHJ', 'RTZU']) |
| 1248 | exe "normal! gg0\<c-v>2j$zy" |
| 1249 | norm! 5gg0zP |
| 1250 | call assert_equal(['aa', 'bbbbb', 'ccc', '', 'aaXX', 'bbbbbGGHHJ', 'cccRTZU'], getline(1, 7)) |
| 1251 | " |
| 1252 | " now with blockmode editing |
| 1253 | sil %d |
| 1254 | :set ve=block |
| 1255 | call setline(1, ['aa', 'bbbbb', 'ccc', '', 'XX', 'GGHHJ', 'RTZU']) |
| 1256 | exe "normal! gg0\<c-v>2j$zy" |
| 1257 | norm! 5gg0zP |
| 1258 | call assert_equal(['aa', 'bbbbb', 'ccc', '', 'aaXX', 'bbbbbGGHHJ', 'cccRTZU'], getline(1, 7)) |
| 1259 | set ve&vim |
| 1260 | bw! |
| 1261 | endfunc |
| 1262 | |
Bram Moolenaar | 44db821 | 2022-01-25 21:26:17 +0000 | [diff] [blame] | 1263 | func Test_visual_block_yank_zy() |
| 1264 | new |
| 1265 | " this was reading before the start of the line |
| 1266 | exe "norm o\<C-T>\<Esc>\<C-V>zy" |
| 1267 | bwipe! |
| 1268 | endfunc |
| 1269 | |
Bram Moolenaar | 9cee4a1 | 2021-07-03 15:08:37 +0200 | [diff] [blame] | 1270 | func Test_visual_block_with_virtualedit() |
| 1271 | CheckScreendump |
| 1272 | |
| 1273 | let lines =<< trim END |
| 1274 | call setline(1, ['aaaaaa', 'bbbb', 'cc']) |
| 1275 | set virtualedit=block |
| 1276 | normal G |
| 1277 | END |
Bram Moolenaar | 5b148ef | 2022-10-15 21:35:56 +0100 | [diff] [blame] | 1278 | call writefile(lines, 'XTest_block', 'D') |
Bram Moolenaar | 9cee4a1 | 2021-07-03 15:08:37 +0200 | [diff] [blame] | 1279 | |
| 1280 | let buf = RunVimInTerminal('-S XTest_block', {'rows': 8, 'cols': 50}) |
| 1281 | call term_sendkeys(buf, "\<C-V>gg$") |
| 1282 | call VerifyScreenDump(buf, 'Test_visual_block_with_virtualedit', {}) |
| 1283 | |
Bram Moolenaar | b17ab86 | 2021-07-03 22:15:17 +0200 | [diff] [blame] | 1284 | call term_sendkeys(buf, "\<Esc>gg\<C-V>G$") |
| 1285 | call VerifyScreenDump(buf, 'Test_visual_block_with_virtualedit2', {}) |
| 1286 | |
Bram Moolenaar | 9cee4a1 | 2021-07-03 15:08:37 +0200 | [diff] [blame] | 1287 | " clean up |
| 1288 | call term_sendkeys(buf, "\<Esc>") |
| 1289 | call StopVimInTerminal(buf) |
Bram Moolenaar | 9cee4a1 | 2021-07-03 15:08:37 +0200 | [diff] [blame] | 1290 | endfunc |
| 1291 | |
Bram Moolenaar | 615ddd5 | 2021-11-17 18:00:31 +0000 | [diff] [blame] | 1292 | func Test_visual_block_ctrl_w_f() |
dundargoc | c57b5bc | 2022-11-02 13:30:51 +0000 | [diff] [blame] | 1293 | " Empty block selected in new buffer should not result in an error. |
Bram Moolenaar | 615ddd5 | 2021-11-17 18:00:31 +0000 | [diff] [blame] | 1294 | au! BufNew foo sil norm f |
| 1295 | edit foo |
| 1296 | |
| 1297 | au! BufNew |
| 1298 | endfunc |
| 1299 | |
Bram Moolenaar | 9f8c304 | 2022-01-17 17:30:21 +0000 | [diff] [blame] | 1300 | func Test_visual_block_append_invalid_char() |
| 1301 | " this was going over the end of the line |
Bram Moolenaar | 262898a | 2022-01-17 17:52:22 +0000 | [diff] [blame] | 1302 | set isprint=@,161-255 |
Bram Moolenaar | 9f8c304 | 2022-01-17 17:30:21 +0000 | [diff] [blame] | 1303 | new |
| 1304 | call setline(1, [' let xxx', 'xxxxx', 'xxxxxxxxxxx']) |
| 1305 | exe "normal 0\<C-V>jjA-\<Esc>" |
| 1306 | call assert_equal([' - let xxx', 'xxxxx -', 'xxxxxxxx-xxx'], getline(1, 3)) |
| 1307 | bwipe! |
Bram Moolenaar | 262898a | 2022-01-17 17:52:22 +0000 | [diff] [blame] | 1308 | set isprint& |
Bram Moolenaar | 9f8c304 | 2022-01-17 17:30:21 +0000 | [diff] [blame] | 1309 | endfunc |
| 1310 | |
Bram Moolenaar | 7ce5b2b | 2022-05-16 19:40:59 +0100 | [diff] [blame] | 1311 | func Test_visual_block_with_substitute() |
| 1312 | " this was reading beyond the end of the line |
| 1313 | new |
| 1314 | norm a0) |
| 1315 | sil! norm O |
| 1316 | s/) |
| 1317 | sil! norm |
| 1318 | bwipe! |
| 1319 | endfunc |
| 1320 | |
Bram Moolenaar | b07626d | 2021-10-11 15:40:43 +0100 | [diff] [blame] | 1321 | func Test_visual_reselect_with_count() |
Bram Moolenaar | 8f53166 | 2023-02-01 17:33:18 +0000 | [diff] [blame] | 1322 | enew |
| 1323 | call setline(1, ['aaaaaa', '✗ bbbb', '✗ bbbb']) |
| 1324 | exe "normal! 2Gw\<C-V>jed" |
| 1325 | exe "normal! gg0lP" |
| 1326 | call assert_equal(['abbbbaaaaa', '✗bbbb ', '✗ '], getline(1, '$')) |
| 1327 | |
| 1328 | exe "normal! 1vr." |
| 1329 | call assert_equal(['a....aaaaa', '✗.... ', '✗ '], getline(1, '$')) |
| 1330 | |
| 1331 | bwipe! |
| 1332 | |
Bram Moolenaar | b07626d | 2021-10-11 15:40:43 +0100 | [diff] [blame] | 1333 | " this was causing an illegal memory access |
| 1334 | let lines =<< trim END |
| 1335 | |
| 1336 | |
| 1337 | |
| 1338 | : |
| 1339 | r<sfile> |
| 1340 | exe "%norm e3\<c-v>kr\t" |
| 1341 | : |
| 1342 | |
| 1343 | : |
| 1344 | END |
Bram Moolenaar | 5b148ef | 2022-10-15 21:35:56 +0100 | [diff] [blame] | 1345 | call writefile(lines, 'XvisualReselect', 'D') |
Bram Moolenaar | b07626d | 2021-10-11 15:40:43 +0100 | [diff] [blame] | 1346 | source XvisualReselect |
| 1347 | |
| 1348 | bwipe! |
Bram Moolenaar | b07626d | 2021-10-11 15:40:43 +0100 | [diff] [blame] | 1349 | endfunc |
| 1350 | |
Bram Moolenaar | 79c11e3 | 2023-01-10 17:29:29 +0000 | [diff] [blame] | 1351 | func Test_visual_reselect_exclusive() |
| 1352 | new |
| 1353 | call setline(1, ['abcde', 'abcde']) |
| 1354 | set selection=exclusive |
| 1355 | normal 1G0viwd |
| 1356 | normal 2G01vd |
| 1357 | call assert_equal(['', ''], getline(1, 2)) |
| 1358 | |
| 1359 | set selection& |
| 1360 | bwipe! |
| 1361 | endfunc |
| 1362 | |
Bram Moolenaar | 57df9e8 | 2022-01-20 12:10:48 +0000 | [diff] [blame] | 1363 | func Test_visual_block_insert_round_off() |
| 1364 | new |
| 1365 | " The number of characters are tuned to fill a 4096 byte allocated block, |
| 1366 | " so that valgrind reports going over the end. |
| 1367 | call setline(1, ['xxxxx', repeat('0', 1350), "\t", repeat('x', 60)]) |
| 1368 | exe "normal gg0\<C-V>GI" .. repeat('0', 1320) .. "\<Esc>" |
| 1369 | bwipe! |
| 1370 | endfunc |
| 1371 | |
Bram Moolenaar | 05b2761 | 2022-01-20 13:32:50 +0000 | [diff] [blame] | 1372 | " this was causing an ml_get error |
| 1373 | func Test_visual_exchange_windows() |
| 1374 | enew! |
| 1375 | new |
| 1376 | call setline(1, ['foo', 'bar']) |
| 1377 | exe "normal G\<C-V>gg\<C-W>\<C-X>OO\<Esc>" |
| 1378 | bwipe! |
| 1379 | bwipe! |
| 1380 | endfunc |
| 1381 | |
Bram Moolenaar | dc5490e | 2022-01-25 13:52:53 +0000 | [diff] [blame] | 1382 | " this was leaving the end of the Visual area beyond the end of a line |
| 1383 | func Test_visual_ex_copy_line() |
| 1384 | new |
| 1385 | call setline(1, ["aaa", "bbbbbbbbbxbb"]) |
| 1386 | /x |
| 1387 | exe "normal ggvjfxO" |
| 1388 | t0 |
| 1389 | normal gNU |
| 1390 | bwipe! |
| 1391 | endfunc |
| 1392 | |
Bram Moolenaar | 8d02ce1 | 2022-01-25 18:24:00 +0000 | [diff] [blame] | 1393 | " This was leaving the end of the Visual area beyond the end of a line. |
| 1394 | " Set 'undolevels' to start a new undo block. |
| 1395 | func Test_visual_undo_deletes_last_line() |
| 1396 | new |
| 1397 | call setline(1, ["aaa", "ccc", "dyd"]) |
| 1398 | set undolevels=100 |
| 1399 | exe "normal obbbbbbbbbxbb\<Esc>" |
| 1400 | set undolevels=100 |
| 1401 | /y |
| 1402 | exe "normal ggvjfxO" |
| 1403 | undo |
| 1404 | normal gNU |
Shougo Matsushita | fb55207 | 2022-01-28 16:01:13 +0000 | [diff] [blame] | 1405 | |
Bram Moolenaar | 8d02ce1 | 2022-01-25 18:24:00 +0000 | [diff] [blame] | 1406 | bwipe! |
| 1407 | endfunc |
| 1408 | |
Shougo Matsushita | fb55207 | 2022-01-28 16:01:13 +0000 | [diff] [blame] | 1409 | func Test_visual_paste() |
| 1410 | new |
| 1411 | |
| 1412 | " v_p overwrites unnamed register. |
| 1413 | call setline(1, ['xxxx']) |
| 1414 | call setreg('"', 'foo') |
| 1415 | call setreg('-', 'bar') |
zeertzjq | 6bf821e | 2022-02-07 10:33:20 +0000 | [diff] [blame] | 1416 | normal gg0vp |
| 1417 | call assert_equal('x', @") |
| 1418 | call assert_equal('x', @-) |
| 1419 | call assert_equal('fooxxx', getline(1)) |
| 1420 | normal $vp |
| 1421 | call assert_equal('x', @") |
| 1422 | call assert_equal('x', @-) |
| 1423 | call assert_equal('fooxxx', getline(1)) |
| 1424 | " Test with a different register as unnamed register. |
| 1425 | call setline(2, ['baz']) |
| 1426 | normal 2gg0"rD |
| 1427 | call assert_equal('baz', @") |
| 1428 | normal gg0vp |
| 1429 | call assert_equal('f', @") |
| 1430 | call assert_equal('f', @-) |
| 1431 | call assert_equal('bazooxxx', getline(1)) |
| 1432 | normal $vp |
| 1433 | call assert_equal('x', @") |
| 1434 | call assert_equal('x', @-) |
| 1435 | call assert_equal('bazooxxf', getline(1)) |
Shougo Matsushita | fb55207 | 2022-01-28 16:01:13 +0000 | [diff] [blame] | 1436 | |
Shougo Matsushita | 509142a | 2022-05-06 11:45:09 +0100 | [diff] [blame] | 1437 | bwipe! |
| 1438 | endfunc |
| 1439 | |
| 1440 | func Test_visual_paste_clipboard() |
| 1441 | CheckFeature clipboard_working |
| 1442 | |
| 1443 | if has('gui') |
| 1444 | " auto select feature breaks tests |
| 1445 | set guioptions-=a |
| 1446 | endif |
| 1447 | |
| 1448 | " v_P does not overwrite unnamed register. |
| 1449 | call setline(1, ['xxxx']) |
| 1450 | call setreg('"', 'foo') |
| 1451 | call setreg('-', 'bar') |
| 1452 | normal gg0vP |
| 1453 | call assert_equal('foo', @") |
| 1454 | call assert_equal('bar', @-) |
| 1455 | call assert_equal('fooxxx', getline(1)) |
| 1456 | normal $vP |
| 1457 | call assert_equal('foo', @") |
| 1458 | call assert_equal('bar', @-) |
| 1459 | call assert_equal('fooxxfoo', getline(1)) |
| 1460 | " Test with a different register as unnamed register. |
| 1461 | call setline(2, ['baz']) |
| 1462 | normal 2gg0"rD |
| 1463 | call assert_equal('baz', @") |
| 1464 | normal gg0vP |
| 1465 | call assert_equal('baz', @") |
| 1466 | call assert_equal('bar', @-) |
| 1467 | call assert_equal('bazooxxfoo', getline(1)) |
| 1468 | normal $vP |
| 1469 | call assert_equal('baz', @") |
| 1470 | call assert_equal('bar', @-) |
| 1471 | call assert_equal('bazooxxfobaz', getline(1)) |
| 1472 | |
| 1473 | " Test for unnamed clipboard |
| 1474 | set clipboard=unnamed |
| 1475 | call setline(1, ['xxxx']) |
| 1476 | call setreg('"', 'foo') |
| 1477 | call setreg('-', 'bar') |
| 1478 | call setreg('*', 'baz') |
| 1479 | normal gg0vP |
| 1480 | call assert_equal('foo', @") |
| 1481 | call assert_equal('bar', @-) |
| 1482 | call assert_equal('baz', @*) |
| 1483 | call assert_equal('bazxxx', getline(1)) |
| 1484 | |
| 1485 | " Test for unnamedplus clipboard |
| 1486 | if has('unnamedplus') |
| 1487 | set clipboard=unnamedplus |
Shougo Matsushita | fb55207 | 2022-01-28 16:01:13 +0000 | [diff] [blame] | 1488 | call setline(1, ['xxxx']) |
| 1489 | call setreg('"', 'foo') |
| 1490 | call setreg('-', 'bar') |
Shougo Matsushita | 509142a | 2022-05-06 11:45:09 +0100 | [diff] [blame] | 1491 | call setreg('+', 'baz') |
zeertzjq | 6bf821e | 2022-02-07 10:33:20 +0000 | [diff] [blame] | 1492 | normal gg0vP |
| 1493 | call assert_equal('foo', @") |
Shougo Matsushita | 509142a | 2022-05-06 11:45:09 +0100 | [diff] [blame] | 1494 | call assert_equal('bar', @-) |
| 1495 | call assert_equal('baz', @+) |
| 1496 | call assert_equal('bazxxx', getline(1)) |
Shougo Matsushita | fb55207 | 2022-01-28 16:01:13 +0000 | [diff] [blame] | 1497 | endif |
| 1498 | |
Shougo Matsushita | 509142a | 2022-05-06 11:45:09 +0100 | [diff] [blame] | 1499 | set clipboard& |
| 1500 | if has('gui') |
| 1501 | set guioptions& |
| 1502 | endif |
Shougo Matsushita | fb55207 | 2022-01-28 16:01:13 +0000 | [diff] [blame] | 1503 | bwipe! |
| 1504 | endfunc |
Christian Brabandt | 544a38e | 2021-06-10 19:39:11 +0200 | [diff] [blame] | 1505 | |
Bram Moolenaar | 3d51ce1 | 2022-07-01 15:26:15 +0100 | [diff] [blame] | 1506 | func Test_visual_area_adjusted_when_hiding() |
| 1507 | " The Visual area ended after the end of the line after :hide |
| 1508 | call setline(1, 'xxx') |
Bram Moolenaar | b18b496 | 2022-09-02 21:55:50 +0100 | [diff] [blame] | 1509 | vsplit Xvaafile |
Bram Moolenaar | 3d51ce1 | 2022-07-01 15:26:15 +0100 | [diff] [blame] | 1510 | call setline(1, 'xxxxxxxx') |
| 1511 | norm! $o |
| 1512 | hid |
| 1513 | norm! zW |
| 1514 | bwipe! |
| 1515 | bwipe! |
| 1516 | endfunc |
| 1517 | |
Bram Moolenaar | cfeb8a5 | 2022-08-13 14:09:44 +0100 | [diff] [blame] | 1518 | func Test_switch_buffer_ends_visual_mode() |
| 1519 | enew |
| 1520 | call setline(1, 'foo') |
| 1521 | set hidden |
| 1522 | set virtualedit=all |
| 1523 | let buf1 = bufnr() |
| 1524 | enew |
| 1525 | let buf2 = bufnr() |
| 1526 | call setline(1, ['', '', '', '']) |
| 1527 | call cursor(4, 5) |
| 1528 | call feedkeys("\<C-V>3k4h", 'xt') |
| 1529 | exe 'buffer' buf1 |
| 1530 | call assert_equal('n', mode()) |
| 1531 | |
| 1532 | set nohidden |
| 1533 | set virtualedit= |
| 1534 | bwipe! |
| 1535 | exe 'bwipe!' buf2 |
| 1536 | endfunc |
| 1537 | |
Pavel Mayorov | e1121b1 | 2023-02-20 14:35:20 +0000 | [diff] [blame] | 1538 | " Check fix for the heap-based buffer overflow bug found in the function |
| 1539 | " utfc_ptr2len and reported at |
| 1540 | " https://huntr.dev/bounties/ae933869-a1ec-402a-bbea-d51764c6618e |
| 1541 | func Test_heap_buffer_overflow() |
| 1542 | enew |
| 1543 | set updatecount=0 |
| 1544 | |
| 1545 | norm R0 |
| 1546 | split other |
| 1547 | norm R000 |
| 1548 | exe "norm \<C-V>l" |
| 1549 | ball |
| 1550 | call assert_equal(getpos("."), getpos("v")) |
| 1551 | call assert_equal('n', mode()) |
| 1552 | norm zW |
| 1553 | |
| 1554 | %bwipe! |
| 1555 | set updatecount& |
| 1556 | endfunc |
| 1557 | |
zeertzjq | 8fc6a1d | 2023-08-20 18:12:54 +0200 | [diff] [blame] | 1558 | " Test Visual highlight with cursor at end of screen line and 'showbreak' |
| 1559 | func Test_visual_hl_with_showbreak() |
| 1560 | CheckScreendump |
| 1561 | |
| 1562 | let lines =<< trim END |
| 1563 | setlocal showbreak=+ |
| 1564 | call setline(1, repeat('a', &columns + 10)) |
| 1565 | normal g$v4lo |
| 1566 | END |
| 1567 | call writefile(lines, 'XTest_visual_sbr', 'D') |
| 1568 | |
| 1569 | let buf = RunVimInTerminal('-S XTest_visual_sbr', {'rows': 6, 'cols': 50}) |
| 1570 | call VerifyScreenDump(buf, 'Test_visual_hl_with_showbreak', {}) |
| 1571 | |
| 1572 | " clean up |
| 1573 | call term_sendkeys(buf, "\<Esc>") |
| 1574 | call StopVimInTerminal(buf) |
| 1575 | endfunc |
Pavel Mayorov | e1121b1 | 2023-02-20 14:35:20 +0000 | [diff] [blame] | 1576 | |
Christian Brabandt | 476733f | 2023-09-19 20:41:51 +0200 | [diff] [blame] | 1577 | func Test_Visual_r_CTRL_C() |
| 1578 | new |
| 1579 | " visual r_cmd |
| 1580 | call setline(1, [' ']) |
| 1581 | call feedkeys("\<c-v>$r\<c-c>", 'tx') |
| 1582 | call assert_equal([''], getline(1, 1)) |
| 1583 | |
| 1584 | " visual gr_cmd |
| 1585 | call setline(1, [' ']) |
| 1586 | call feedkeys("\<c-v>$gr\<c-c>", 'tx') |
| 1587 | call assert_equal([''], getline(1, 1)) |
| 1588 | bw! |
zeertzjq | ec14924 | 2023-12-19 20:28:31 +0100 | [diff] [blame] | 1589 | endfunc |
| 1590 | |
| 1591 | func Test_visual_drag_out_of_window() |
| 1592 | rightbelow vnew |
| 1593 | call setline(1, '123456789') |
| 1594 | set mouse=a |
| 1595 | func ClickExpr(off) |
| 1596 | call test_setmouse(1, getwininfo(win_getid())[0].wincol + a:off) |
| 1597 | return "\<LeftMouse>" |
| 1598 | endfunc |
| 1599 | func DragExpr(off) |
| 1600 | call test_setmouse(1, getwininfo(win_getid())[0].wincol + a:off) |
| 1601 | return "\<LeftDrag>" |
| 1602 | endfunc |
| 1603 | |
| 1604 | nnoremap <expr> <F2> ClickExpr(5) |
| 1605 | nnoremap <expr> <F3> DragExpr(-1) |
| 1606 | redraw |
| 1607 | call feedkeys("\<F2>\<F3>\<LeftRelease>", 'tx') |
| 1608 | call assert_equal([1, 6], [col('.'), col('v')]) |
| 1609 | call feedkeys("\<Esc>", 'tx') |
| 1610 | |
| 1611 | nnoremap <expr> <F2> ClickExpr(6) |
| 1612 | nnoremap <expr> <F3> DragExpr(-2) |
| 1613 | redraw |
| 1614 | call feedkeys("\<F2>\<F3>\<LeftRelease>", 'tx') |
| 1615 | call assert_equal([1, 7], [col('.'), col('v')]) |
| 1616 | call feedkeys("\<Esc>", 'tx') |
| 1617 | |
| 1618 | nunmap <F2> |
| 1619 | nunmap <F3> |
| 1620 | delfunc ClickExpr |
| 1621 | delfunc DragExpr |
| 1622 | set mouse& |
| 1623 | bwipe! |
| 1624 | endfunc |
Christian Brabandt | 476733f | 2023-09-19 20:41:51 +0200 | [diff] [blame] | 1625 | |
Christian Brabandt | 7c71db3 | 2024-01-22 20:12:34 +0100 | [diff] [blame] | 1626 | func Test_visual_substitute_visual() |
| 1627 | new |
| 1628 | call setline(1, ['one', 'two', 'three']) |
| 1629 | call feedkeys("Gk\<C-V>j$:s/\\%V\\_.*\\%V/foobar\<CR>", 'tx') |
| 1630 | call assert_equal(['one', 'foobar'], getline(1, '$')) |
| 1631 | bwipe! |
| 1632 | endfunc |
| 1633 | |
zeertzjq | 701ad50 | 2024-05-23 07:47:55 +0200 | [diff] [blame] | 1634 | func Test_virtualedit_exclusive_selection() |
| 1635 | new |
| 1636 | set virtualedit=all selection=exclusive |
| 1637 | |
| 1638 | call setline(1, "a\tb") |
| 1639 | normal! 0v8ly |
| 1640 | call assert_equal("a\t", getreg('"')) |
| 1641 | normal! 0v6ly |
| 1642 | call assert_equal('a ', getreg('"')) |
| 1643 | normal! 06lv2ly |
| 1644 | call assert_equal(' ', getreg('"')) |
| 1645 | |
| 1646 | set virtualedit& selection& |
| 1647 | bwipe! |
| 1648 | endfunc |
| 1649 | |
Shougo Matsushita | 3f905ab | 2024-02-21 00:02:45 +0100 | [diff] [blame] | 1650 | func Test_visual_getregion() |
Yegappan Lakshmanan | 4d55c54 | 2024-02-29 17:30:43 +0100 | [diff] [blame] | 1651 | let lines =<< trim END |
| 1652 | new |
Shougo Matsushita | 3f905ab | 2024-02-21 00:02:45 +0100 | [diff] [blame] | 1653 | |
Yegappan Lakshmanan | 4d55c54 | 2024-02-29 17:30:43 +0100 | [diff] [blame] | 1654 | call setline(1, ['one', 'two', 'three']) |
Shougo Matsushita | 3f905ab | 2024-02-21 00:02:45 +0100 | [diff] [blame] | 1655 | |
Yegappan Lakshmanan | 4d55c54 | 2024-02-29 17:30:43 +0100 | [diff] [blame] | 1656 | #" Visual mode |
| 1657 | call cursor(1, 1) |
| 1658 | call feedkeys("\<ESC>vjl", 'tx') |
zeertzjq | c95e64f | 2024-05-20 14:00:31 +0200 | [diff] [blame] | 1659 | |
Yegappan Lakshmanan | 4d55c54 | 2024-02-29 17:30:43 +0100 | [diff] [blame] | 1660 | call assert_equal(['one', 'tw'], |
| 1661 | \ 'v'->getpos()->getregion(getpos('.'))) |
Shougo Matsushita | b4757e6 | 2024-05-07 20:49:24 +0200 | [diff] [blame] | 1662 | call assert_equal([ |
| 1663 | \ [[bufnr('%'), 1, 1, 0], [bufnr('%'), 1, 3, 0]], |
| 1664 | \ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 2, 0]] |
| 1665 | \ ], |
| 1666 | \ 'v'->getpos()->getregionpos(getpos('.'))) |
zeertzjq | c95e64f | 2024-05-20 14:00:31 +0200 | [diff] [blame] | 1667 | |
Yegappan Lakshmanan | 4d55c54 | 2024-02-29 17:30:43 +0100 | [diff] [blame] | 1668 | call assert_equal(['one', 'tw'], |
| 1669 | \ '.'->getpos()->getregion(getpos('v'))) |
Shougo Matsushita | b4757e6 | 2024-05-07 20:49:24 +0200 | [diff] [blame] | 1670 | call assert_equal([ |
| 1671 | \ [[bufnr('%'), 1, 1, 0], [bufnr('%'), 1, 3, 0]], |
| 1672 | \ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 2, 0]] |
| 1673 | \ ], |
| 1674 | \ '.'->getpos()->getregionpos(getpos('v'))) |
zeertzjq | c95e64f | 2024-05-20 14:00:31 +0200 | [diff] [blame] | 1675 | |
Yegappan Lakshmanan | 4d55c54 | 2024-02-29 17:30:43 +0100 | [diff] [blame] | 1676 | call assert_equal(['o'], |
| 1677 | \ 'v'->getpos()->getregion(getpos('v'))) |
Shougo Matsushita | b4757e6 | 2024-05-07 20:49:24 +0200 | [diff] [blame] | 1678 | call assert_equal([ |
| 1679 | \ [[bufnr('%'), 1, 1, 0], [bufnr('%'), 1, 1, 0]], |
| 1680 | \ ], |
| 1681 | \ 'v'->getpos()->getregionpos(getpos('v'))) |
zeertzjq | c95e64f | 2024-05-20 14:00:31 +0200 | [diff] [blame] | 1682 | |
Yegappan Lakshmanan | 4d55c54 | 2024-02-29 17:30:43 +0100 | [diff] [blame] | 1683 | call assert_equal(['w'], |
| 1684 | \ '.'->getpos()->getregion(getpos('.'), {'type': 'v' })) |
Shougo Matsushita | b4757e6 | 2024-05-07 20:49:24 +0200 | [diff] [blame] | 1685 | call assert_equal([ |
| 1686 | \ [[bufnr('%'), 2, 2, 0], [bufnr('%'), 2, 2, 0]], |
| 1687 | \ ], |
| 1688 | \ '.'->getpos()->getregionpos(getpos('.'), {'type': 'v' })) |
zeertzjq | c95e64f | 2024-05-20 14:00:31 +0200 | [diff] [blame] | 1689 | |
Yegappan Lakshmanan | 4d55c54 | 2024-02-29 17:30:43 +0100 | [diff] [blame] | 1690 | call assert_equal(['one', 'two'], |
| 1691 | \ getpos('.')->getregion(getpos('v'), {'type': 'V' })) |
Shougo Matsushita | b4757e6 | 2024-05-07 20:49:24 +0200 | [diff] [blame] | 1692 | call assert_equal([ |
| 1693 | \ [[bufnr('%'), 1, 1, 0], [bufnr('%'), 1, 3, 0]], |
| 1694 | \ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 3, 0]], |
| 1695 | \ ], |
| 1696 | \ getpos('.')->getregionpos(getpos('v'), {'type': 'V' })) |
zeertzjq | c95e64f | 2024-05-20 14:00:31 +0200 | [diff] [blame] | 1697 | |
Yegappan Lakshmanan | 4d55c54 | 2024-02-29 17:30:43 +0100 | [diff] [blame] | 1698 | call assert_equal(['on', 'tw'], |
| 1699 | \ getpos('.')->getregion(getpos('v'), {'type': "\<C-v>" })) |
Shougo Matsushita | b4757e6 | 2024-05-07 20:49:24 +0200 | [diff] [blame] | 1700 | call assert_equal([ |
| 1701 | \ [[bufnr('%'), 1, 1, 0], [bufnr('%'), 1, 2, 0]], |
| 1702 | \ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 2, 0]], |
| 1703 | \ ], |
| 1704 | \ getpos('.')->getregionpos(getpos('v'), {'type': "\<C-v>" })) |
Shougo Matsushita | 3f905ab | 2024-02-21 00:02:45 +0100 | [diff] [blame] | 1705 | |
Yegappan Lakshmanan | 4d55c54 | 2024-02-29 17:30:43 +0100 | [diff] [blame] | 1706 | #" Line visual mode |
| 1707 | call cursor(1, 1) |
| 1708 | call feedkeys("\<ESC>Vl", 'tx') |
| 1709 | call assert_equal(['one'], |
| 1710 | \ getregion(getpos('v'), getpos('.'), {'type': 'V' })) |
| 1711 | call assert_equal(['one'], |
| 1712 | \ getregion(getpos('.'), getpos('v'), {'type': 'V' })) |
| 1713 | call assert_equal(['one'], |
| 1714 | \ getregion(getpos('v'), getpos('v'), {'type': 'V' })) |
| 1715 | call assert_equal(['one'], |
| 1716 | \ getregion(getpos('.'), getpos('.'), {'type': 'V' })) |
| 1717 | call assert_equal(['on'], |
| 1718 | \ getpos('.')->getregion(getpos('v'), {'type': 'v' })) |
| 1719 | call assert_equal(['on'], |
| 1720 | \ getpos('.')->getregion(getpos('v'), {'type': "\<C-v>" })) |
Shougo Matsushita | 3f905ab | 2024-02-21 00:02:45 +0100 | [diff] [blame] | 1721 | |
Yegappan Lakshmanan | 4d55c54 | 2024-02-29 17:30:43 +0100 | [diff] [blame] | 1722 | #" Block visual mode |
| 1723 | call cursor(1, 1) |
| 1724 | call feedkeys("\<ESC>\<C-v>ll", 'tx') |
| 1725 | call assert_equal(['one'], |
| 1726 | \ getregion(getpos('v'), getpos('.'), {'type': "\<C-v>" })) |
| 1727 | call assert_equal(['one'], |
| 1728 | \ getregion(getpos('.'), getpos('v'), {'type': "\<C-v>" })) |
| 1729 | call assert_equal(['o'], |
| 1730 | \ getregion(getpos('v'), getpos('v'), {'type': "\<C-v>" })) |
| 1731 | call assert_equal(['e'], |
| 1732 | \ getregion(getpos('.'), getpos('.'), {'type': "\<C-v>" })) |
| 1733 | call assert_equal(['one'], |
| 1734 | \ '.'->getpos()->getregion(getpos('v'), {'type': 'V' })) |
| 1735 | call assert_equal(['one'], |
| 1736 | \ '.'->getpos()->getregion(getpos('v'), {'type': 'v' })) |
Shougo Matsushita | 3f905ab | 2024-02-21 00:02:45 +0100 | [diff] [blame] | 1737 | |
Yegappan Lakshmanan | 4d55c54 | 2024-02-29 17:30:43 +0100 | [diff] [blame] | 1738 | #" Using Marks |
| 1739 | call setpos("'a", [0, 2, 3, 0]) |
| 1740 | call cursor(1, 1) |
| 1741 | call assert_equal(['one', 'two'], |
| 1742 | \ "'a"->getpos()->getregion(getpos('.'), {'type': 'v' })) |
| 1743 | call assert_equal(['one', 'two'], |
| 1744 | \ "."->getpos()->getregion(getpos("'a"), {'type': 'v' })) |
| 1745 | call assert_equal(['one', 'two'], |
| 1746 | \ "."->getpos()->getregion(getpos("'a"), {'type': 'V' })) |
| 1747 | call assert_equal(['two'], |
| 1748 | \ "'a"->getpos()->getregion(getpos("'a"), {'type': 'V' })) |
| 1749 | call assert_equal(['one', 'two'], |
| 1750 | \ "."->getpos()->getregion(getpos("'a"), {'type': "\<c-v>" })) |
zeertzjq | 2ffdae7 | 2024-05-02 13:06:24 +0200 | [diff] [blame] | 1751 | call feedkeys("\<ESC>jVj\<ESC>", 'tx') |
| 1752 | call assert_equal(['two', 'three'], getregion(getpos("'<"), getpos("'>"))) |
| 1753 | call assert_equal(['two', 'three'], getregion(getpos("'>"), getpos("'<"))) |
Shougo Matsushita | 19b7188 | 2024-02-28 22:48:12 +0100 | [diff] [blame] | 1754 | |
Yegappan Lakshmanan | 4d55c54 | 2024-02-29 17:30:43 +0100 | [diff] [blame] | 1755 | #" Using List |
| 1756 | call cursor(1, 1) |
| 1757 | call assert_equal(['one', 'two'], |
| 1758 | \ [0, 2, 3, 0]->getregion(getpos('.'), {'type': 'v' })) |
| 1759 | call assert_equal(['one', 'two'], |
| 1760 | \ '.'->getpos()->getregion([0, 2, 3, 0], {'type': 'v' })) |
| 1761 | call assert_equal(['one', 'two'], |
| 1762 | \ '.'->getpos()->getregion([0, 2, 3, 0], {'type': 'V' })) |
| 1763 | call assert_equal(['two'], |
| 1764 | \ [0, 2, 3, 0]->getregion([0, 2, 3, 0], {'type': 'V' })) |
| 1765 | call assert_equal(['one', 'two'], |
| 1766 | \ '.'->getpos()->getregion([0, 2, 3, 0], {'type': "\<c-v>" })) |
Shougo Matsushita | 3f905ab | 2024-02-21 00:02:45 +0100 | [diff] [blame] | 1767 | |
Yegappan Lakshmanan | 4d55c54 | 2024-02-29 17:30:43 +0100 | [diff] [blame] | 1768 | #" Multiline with line visual mode |
| 1769 | call cursor(1, 1) |
| 1770 | call feedkeys("\<ESC>Vjj", 'tx') |
| 1771 | call assert_equal(['one', 'two', 'three'], |
| 1772 | \ getregion(getpos('v'), getpos('.'), {'type': 'V' })) |
zeertzjq | 2b09de9 | 2024-05-24 07:48:51 +0200 | [diff] [blame] | 1773 | call assert_equal([ |
| 1774 | \ [[bufnr('%'), 1, 1, 0], [bufnr('%'), 1, 3, 0]], |
| 1775 | \ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 3, 0]], |
| 1776 | \ [[bufnr('%'), 3, 1, 0], [bufnr('%'), 3, 5, 0]], |
| 1777 | \ ], |
| 1778 | \ getregionpos(getpos('v'), getpos('.'), {'type': 'V' })) |
| 1779 | call assert_equal([ |
| 1780 | \ [[bufnr('%'), 1, 1, 0], [bufnr('%'), 1, 4, 0]], |
| 1781 | \ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 4, 0]], |
| 1782 | \ [[bufnr('%'), 3, 1, 0], [bufnr('%'), 3, 6, 0]], |
| 1783 | \ ], |
| 1784 | \ getregionpos(getpos('v'), getpos('.'), |
| 1785 | \ {'type': 'V', 'eol': v:true })) |
Shougo Matsushita | 3f905ab | 2024-02-21 00:02:45 +0100 | [diff] [blame] | 1786 | |
Yegappan Lakshmanan | 4d55c54 | 2024-02-29 17:30:43 +0100 | [diff] [blame] | 1787 | #" Multiline with block visual mode |
| 1788 | call cursor(1, 1) |
| 1789 | call feedkeys("\<ESC>\<C-v>jj", 'tx') |
| 1790 | call assert_equal(['o', 't', 't'], |
| 1791 | \ getregion(getpos('v'), getpos('.'), {'type': "\<C-v>" })) |
zeertzjq | 2b09de9 | 2024-05-24 07:48:51 +0200 | [diff] [blame] | 1792 | call assert_equal([ |
| 1793 | \ [[bufnr('%'), 1, 1, 0], [bufnr('%'), 1, 1, 0]], |
| 1794 | \ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 1, 0]], |
| 1795 | \ [[bufnr('%'), 3, 1, 0], [bufnr('%'), 3, 1, 0]], |
| 1796 | \ ], |
| 1797 | \ getregionpos(getpos('v'), getpos('.'), {'type': "\<C-v>" })) |
Shougo Matsushita | 3f905ab | 2024-02-21 00:02:45 +0100 | [diff] [blame] | 1798 | |
Yegappan Lakshmanan | 4d55c54 | 2024-02-29 17:30:43 +0100 | [diff] [blame] | 1799 | call cursor(1, 1) |
| 1800 | call feedkeys("\<ESC>\<C-v>jj$", 'tx') |
| 1801 | call assert_equal(['one', 'two', 'three'], |
| 1802 | \ getregion(getpos('v'), getpos('.'), {'type': "\<C-v>" })) |
zeertzjq | 2b09de9 | 2024-05-24 07:48:51 +0200 | [diff] [blame] | 1803 | call assert_equal([ |
| 1804 | \ [[bufnr('%'), 1, 1, 0], [bufnr('%'), 1, 3, 0]], |
| 1805 | \ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 3, 0]], |
| 1806 | \ [[bufnr('%'), 3, 1, 0], [bufnr('%'), 3, 5, 0]], |
| 1807 | \ ], |
| 1808 | \ getregionpos(getpos('v'), getpos('.'), {'type': "\<C-v>" })) |
| 1809 | call assert_equal([ |
| 1810 | \ [[bufnr('%'), 1, 1, 0], [bufnr('%'), 1, 3, 0]], |
| 1811 | \ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 3, 0]], |
| 1812 | \ [[bufnr('%'), 3, 1, 0], [bufnr('%'), 3, 5, 0]], |
| 1813 | \ ], |
| 1814 | \ getregionpos(getpos('v'), getpos('.'), |
| 1815 | \ {'type': "\<C-v>", 'eol': v:true })) |
Shougo Matsushita | 3f905ab | 2024-02-21 00:02:45 +0100 | [diff] [blame] | 1816 | |
Yegappan Lakshmanan | 4d55c54 | 2024-02-29 17:30:43 +0100 | [diff] [blame] | 1817 | #" 'virtualedit' |
| 1818 | set virtualedit=all |
zeertzjq | 2b09de9 | 2024-05-24 07:48:51 +0200 | [diff] [blame] | 1819 | |
Yegappan Lakshmanan | 4d55c54 | 2024-02-29 17:30:43 +0100 | [diff] [blame] | 1820 | call cursor(1, 1) |
| 1821 | call feedkeys("\<ESC>\<C-v>10ljj$", 'tx') |
| 1822 | call assert_equal(['one ', 'two ', 'three '], |
| 1823 | \ getregion(getpos('v'), getpos('.'), {'type': "\<C-v>" })) |
zeertzjq | 2b09de9 | 2024-05-24 07:48:51 +0200 | [diff] [blame] | 1824 | call assert_equal([ |
| 1825 | \ [[bufnr('%'), 1, 1, 0], [bufnr('%'), 1, 3, 0]], |
| 1826 | \ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 3, 0]], |
| 1827 | \ [[bufnr('%'), 3, 1, 0], [bufnr('%'), 3, 5, 0]], |
| 1828 | \ ], |
| 1829 | \ getregionpos(getpos('v'), getpos('.'), {'type': "\<C-v>" })) |
| 1830 | call assert_equal([ |
| 1831 | \ [[bufnr('%'), 1, 1, 0], [bufnr('%'), 1, 4, 3]], |
| 1832 | \ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 4, 3]], |
| 1833 | \ [[bufnr('%'), 3, 1, 0], [bufnr('%'), 3, 6, 1]], |
| 1834 | \ ], |
| 1835 | \ getregionpos(getpos('v'), getpos('.'), |
| 1836 | \ {'type': "\<C-v>", 'eol': v:true })) |
| 1837 | |
| 1838 | call cursor(3, 5) |
| 1839 | call feedkeys("\<ESC>\<C-v>hkk", 'tx') |
| 1840 | call assert_equal([' ', ' ', 'ee'], |
| 1841 | \ getregion(getpos('v'), getpos('.'), {'type': "\<C-v>" })) |
| 1842 | call assert_equal([ |
| 1843 | \ [[bufnr('%'), 1, 0, 0], [bufnr('%'), 1, 0, 0]], |
| 1844 | \ [[bufnr('%'), 2, 0, 0], [bufnr('%'), 2, 0, 0]], |
| 1845 | \ [[bufnr('%'), 3, 4, 0], [bufnr('%'), 3, 5, 0]], |
| 1846 | \ ], |
| 1847 | \ getregionpos(getpos('v'), getpos('.'), {'type': "\<C-v>" })) |
| 1848 | call assert_equal([ |
| 1849 | \ [[bufnr('%'), 1, 4, 0], [bufnr('%'), 1, 4, 2]], |
| 1850 | \ [[bufnr('%'), 2, 4, 0], [bufnr('%'), 2, 4, 2]], |
| 1851 | \ [[bufnr('%'), 3, 4, 0], [bufnr('%'), 3, 5, 0]], |
| 1852 | \ ], |
| 1853 | \ getregionpos(getpos('v'), getpos('.'), |
| 1854 | \ {'type': "\<C-v>", 'eol': v:true })) |
| 1855 | |
| 1856 | call cursor(3, 5) |
| 1857 | call feedkeys("\<ESC>\<C-v>kk", 'tx') |
| 1858 | call assert_equal([' ', ' ', 'e'], |
| 1859 | \ getregion(getpos('v'), getpos('.'), {'type': "\<C-v>" })) |
| 1860 | call assert_equal([ |
| 1861 | \ [[bufnr('%'), 1, 0, 0], [bufnr('%'), 1, 0, 0]], |
| 1862 | \ [[bufnr('%'), 2, 0, 0], [bufnr('%'), 2, 0, 0]], |
| 1863 | \ [[bufnr('%'), 3, 5, 0], [bufnr('%'), 3, 5, 0]], |
| 1864 | \ ], |
| 1865 | \ getregionpos(getpos('v'), getpos('.'), {'type': "\<C-v>" })) |
| 1866 | call assert_equal([ |
| 1867 | \ [[bufnr('%'), 1, 4, 1], [bufnr('%'), 1, 4, 2]], |
| 1868 | \ [[bufnr('%'), 2, 4, 1], [bufnr('%'), 2, 4, 2]], |
| 1869 | \ [[bufnr('%'), 3, 5, 0], [bufnr('%'), 3, 5, 0]], |
| 1870 | \ ], |
| 1871 | \ getregionpos(getpos('v'), getpos('.'), |
| 1872 | \ {'type': "\<C-v>", 'eol': v:true })) |
| 1873 | |
| 1874 | call cursor(1, 3) |
| 1875 | call feedkeys("\<ESC>vjj4l", 'tx') |
| 1876 | call assert_equal(['e', 'two', 'three '], |
| 1877 | \ getregion(getpos('v'), getpos('.'), {'type': 'v' })) |
| 1878 | call assert_equal([ |
| 1879 | \ [[bufnr('%'), 1, 3, 0], [bufnr('%'), 1, 3, 0]], |
| 1880 | \ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 3, 0]], |
| 1881 | \ [[bufnr('%'), 3, 1, 0], [bufnr('%'), 3, 5, 0]], |
| 1882 | \ ], |
| 1883 | \ getregionpos(getpos('v'), getpos('.'), {'type': 'v' })) |
| 1884 | call assert_equal([ |
| 1885 | \ [[bufnr('%'), 1, 3, 0], [bufnr('%'), 1, 4, 0]], |
| 1886 | \ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 4, 0]], |
| 1887 | \ [[bufnr('%'), 3, 1, 0], [bufnr('%'), 3, 6, 2]], |
| 1888 | \ ], |
| 1889 | \ getregionpos(getpos('v'), getpos('.'), |
| 1890 | \ {'type': 'v', 'eol': v:true })) |
| 1891 | |
| 1892 | call cursor(1, 3) |
| 1893 | call feedkeys("\<ESC>lvjj3l", 'tx') |
| 1894 | call assert_equal(['', 'two', 'three '], |
| 1895 | \ getregion(getpos('v'), getpos('.'), {'type': 'v' })) |
| 1896 | call assert_equal([ |
| 1897 | \ [[bufnr('%'), 1, 0, 0], [bufnr('%'), 1, 0, 0]], |
| 1898 | \ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 3, 0]], |
| 1899 | \ [[bufnr('%'), 3, 1, 0], [bufnr('%'), 3, 5, 0]], |
| 1900 | \ ], |
| 1901 | \ getregionpos(getpos('v'), getpos('.'), {'type': 'v' })) |
| 1902 | call assert_equal([ |
| 1903 | \ [[bufnr('%'), 1, 4, 0], [bufnr('%'), 1, 4, 0]], |
| 1904 | \ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 4, 0]], |
| 1905 | \ [[bufnr('%'), 3, 1, 0], [bufnr('%'), 3, 6, 2]], |
| 1906 | \ ], |
| 1907 | \ getregionpos(getpos('v'), getpos('.'), |
| 1908 | \ {'type': 'v', 'eol': v:true })) |
| 1909 | |
| 1910 | call cursor(3, 5) |
| 1911 | call feedkeys("\<ESC>v3l", 'tx') |
| 1912 | call assert_equal(['e '], |
| 1913 | \ getregion(getpos('v'), getpos('.'), {'type': 'v' })) |
| 1914 | call assert_equal([ |
| 1915 | \ [[bufnr('%'), 3, 5, 0], [bufnr('%'), 3, 5, 0]], |
| 1916 | \ ], |
| 1917 | \ getregionpos(getpos('v'), getpos('.'), {'type': 'v' })) |
| 1918 | call assert_equal([ |
| 1919 | \ [[bufnr('%'), 3, 5, 0], [bufnr('%'), 3, 6, 3]], |
| 1920 | \ ], |
| 1921 | \ getregionpos(getpos('v'), getpos('.'), |
| 1922 | \ {'type': 'v', 'eol': v:true })) |
| 1923 | |
| 1924 | call cursor(3, 5) |
| 1925 | call feedkeys("\<ESC>lv3l", 'tx') |
| 1926 | call assert_equal([' '], |
| 1927 | \ getregion(getpos('v'), getpos('.'), {'type': 'v' })) |
| 1928 | call assert_equal([ |
| 1929 | \ [[bufnr('%'), 3, 0, 0], [bufnr('%'), 3, 0, 0]], |
| 1930 | \ ], |
| 1931 | \ getregionpos(getpos('v'), getpos('.'), {'type': 'v' })) |
| 1932 | call assert_equal([ |
| 1933 | \ [[bufnr('%'), 3, 6, 0], [bufnr('%'), 3, 6, 4]], |
| 1934 | \ ], |
| 1935 | \ getregionpos(getpos('v'), getpos('.'), |
| 1936 | \ {'type': 'v', 'eol': v:true })) |
| 1937 | |
| 1938 | call cursor(3, 5) |
| 1939 | call feedkeys("\<ESC>3lv3l", 'tx') |
| 1940 | call assert_equal([' '], |
| 1941 | \ getregion(getpos('v'), getpos('.'), {'type': 'v' })) |
| 1942 | call assert_equal([ |
| 1943 | \ [[bufnr('%'), 3, 0, 0], [bufnr('%'), 3, 0, 0]], |
| 1944 | \ ], |
| 1945 | \ getregionpos(getpos('v'), getpos('.'), {'type': 'v' })) |
| 1946 | call assert_equal([ |
| 1947 | \ [[bufnr('%'), 3, 6, 2], [bufnr('%'), 3, 6, 6]], |
| 1948 | \ ], |
| 1949 | \ getregionpos(getpos('v'), getpos('.'), |
| 1950 | \ {'type': 'v', 'eol': v:true })) |
| 1951 | |
Yegappan Lakshmanan | 4d55c54 | 2024-02-29 17:30:43 +0100 | [diff] [blame] | 1952 | set virtualedit& |
Shougo Matsushita | 3f905ab | 2024-02-21 00:02:45 +0100 | [diff] [blame] | 1953 | |
zeertzjq | 26dd09a | 2024-03-10 15:46:58 +0100 | [diff] [blame] | 1954 | #" using wrong types for positions |
Yegappan Lakshmanan | 4d55c54 | 2024-02-29 17:30:43 +0100 | [diff] [blame] | 1955 | call cursor(1, 1) |
| 1956 | call feedkeys("\<ESC>vjj$", 'tx') |
| 1957 | call assert_fails("call getregion(1, 2)", 'E1211:') |
| 1958 | call assert_fails("call getregion(getpos('.'), {})", 'E1211:') |
Yegappan Lakshmanan | 4d55c54 | 2024-02-29 17:30:43 +0100 | [diff] [blame] | 1959 | call assert_fails(':echo "."->getpos()->getregion("$", [])', 'E1211:') |
Shougo Matsushita | b4757e6 | 2024-05-07 20:49:24 +0200 | [diff] [blame] | 1960 | call assert_fails("call getregionpos(1, 2)", 'E1211:') |
| 1961 | call assert_fails("call getregionpos(getpos('.'), {})", 'E1211:') |
| 1962 | call assert_fails(':echo "."->getpos()->getregionpos("$", [])', 'E1211:') |
Shougo Matsushita | 19b7188 | 2024-02-28 22:48:12 +0100 | [diff] [blame] | 1963 | |
zeertzjq | 26dd09a | 2024-03-10 15:46:58 +0100 | [diff] [blame] | 1964 | #" using invalid value for "type" |
| 1965 | call assert_fails("call getregion(getpos('.'), getpos('.'), {'type': '' })", 'E475:') |
Shougo Matsushita | b4757e6 | 2024-05-07 20:49:24 +0200 | [diff] [blame] | 1966 | call assert_fails("call getregionpos(getpos('.'), getpos('.'), {'type': '' })", 'E475:') |
zeertzjq | afc2295 | 2024-05-24 19:07:12 +0200 | [diff] [blame] | 1967 | call assert_fails("call getregion(getpos('.'), getpos('.'), {'type': 'v0' })", 'E475:') |
| 1968 | call assert_fails("call getregionpos(getpos('.'), getpos('.'), {'type': 'v0' })", 'E475:') |
| 1969 | call assert_fails("call getregion(getpos('.'), getpos('.'), {'type': 'V0' })", 'E475:') |
| 1970 | call assert_fails("call getregionpos(getpos('.'), getpos('.'), {'type': 'V0' })", 'E475:') |
| 1971 | call assert_fails("call getregion(getpos('.'), getpos('.'), {'type': '\<C-v>0' })", 'E475:') |
| 1972 | call assert_fails("call getregionpos(getpos('.'), getpos('.'), {'type': '\<C-v>0' })", 'E475:') |
| 1973 | call assert_fails("call getregion(getpos('.'), getpos('.'), {'type': '\<C-v>1:' })", 'E475:') |
| 1974 | call assert_fails("call getregionpos(getpos('.'), getpos('.'), {'type': '\<C-v>1:' })", 'E475:') |
zeertzjq | 26dd09a | 2024-03-10 15:46:58 +0100 | [diff] [blame] | 1975 | |
Shougo Matsushita | 84bf6e6 | 2024-03-06 21:10:18 +0100 | [diff] [blame] | 1976 | #" using a mark from another buffer to current buffer |
Yegappan Lakshmanan | 4d55c54 | 2024-02-29 17:30:43 +0100 | [diff] [blame] | 1977 | new |
zeertzjq | 26dd09a | 2024-03-10 15:46:58 +0100 | [diff] [blame] | 1978 | LET g:buf = bufnr() |
Yegappan Lakshmanan | 4d55c54 | 2024-02-29 17:30:43 +0100 | [diff] [blame] | 1979 | call setline(1, range(10)) |
| 1980 | normal! GmA |
| 1981 | wincmd p |
zeertzjq | 26dd09a | 2024-03-10 15:46:58 +0100 | [diff] [blame] | 1982 | call assert_equal([g:buf, 10, 1, 0], getpos("'A")) |
Yegappan Lakshmanan | 4d55c54 | 2024-02-29 17:30:43 +0100 | [diff] [blame] | 1983 | call assert_equal([], getregion(getpos('.'), getpos("'A"), {'type': 'v' })) |
| 1984 | call assert_equal([], getregion(getpos("'A"), getpos('.'), {'type': 'v' })) |
Shougo Matsushita | b4757e6 | 2024-05-07 20:49:24 +0200 | [diff] [blame] | 1985 | call assert_equal([], getregionpos(getpos('.'), getpos("'A"), {'type': 'v' })) |
| 1986 | call assert_equal([], getregionpos(getpos("'A"), getpos('.'), {'type': 'v' })) |
Shougo Matsushita | 84bf6e6 | 2024-03-06 21:10:18 +0100 | [diff] [blame] | 1987 | |
zeertzjq | 26dd09a | 2024-03-10 15:46:58 +0100 | [diff] [blame] | 1988 | #" using two marks from another buffer |
| 1989 | wincmd p |
Shougo Matsushita | 84bf6e6 | 2024-03-06 21:10:18 +0100 | [diff] [blame] | 1990 | normal! GmB |
| 1991 | wincmd p |
zeertzjq | 26dd09a | 2024-03-10 15:46:58 +0100 | [diff] [blame] | 1992 | call assert_equal([g:buf, 10, 1, 0], getpos("'B")) |
Shougo Matsushita | b4757e6 | 2024-05-07 20:49:24 +0200 | [diff] [blame] | 1993 | call assert_equal(['9'], |
| 1994 | \ getregion(getpos("'B"), getpos("'A"), {'type': 'v' })) |
| 1995 | call assert_equal([ |
| 1996 | \ [[g:buf, 10, 1, 0], [g:buf, 10, 1, 0]], |
| 1997 | \ ], |
| 1998 | \ getregionpos(getpos("'B"), getpos("'A"), {'type': 'v' })) |
zeertzjq | 26dd09a | 2024-03-10 15:46:58 +0100 | [diff] [blame] | 1999 | |
| 2000 | #" using two positions from another buffer |
| 2001 | for type in ['v', 'V', "\<C-V>"] |
| 2002 | for exclusive in [v:false, v:true] |
| 2003 | call assert_equal(range(10)->mapnew('string(v:val)'), |
zeertzjq | 5406eb8 | 2024-03-11 21:36:42 +0100 | [diff] [blame] | 2004 | \ getregion([g:buf, 1, 1, 0], [g:buf, 10, 2, 0], |
| 2005 | \ {'type': type, 'exclusive': exclusive })) |
zeertzjq | 26dd09a | 2024-03-10 15:46:58 +0100 | [diff] [blame] | 2006 | call assert_equal(range(10)->mapnew('string(v:val)'), |
zeertzjq | 5406eb8 | 2024-03-11 21:36:42 +0100 | [diff] [blame] | 2007 | \ getregion([g:buf, 10, 2, 0], [g:buf, 1, 1, 0], |
| 2008 | \ {'type': type, 'exclusive': exclusive })) |
zeertzjq | c95e64f | 2024-05-20 14:00:31 +0200 | [diff] [blame] | 2009 | call assert_equal(range(1, 10)->mapnew('repeat([[g:buf, v:val, 1, 0]], 2)'), |
| 2010 | \ getregionpos([g:buf, 1, 1, 0], [g:buf, 10, 2, 0], |
| 2011 | \ {'type': type, 'exclusive': exclusive })) |
| 2012 | call assert_equal(range(1, 10)->mapnew('repeat([[g:buf, v:val, 1, 0]], 2)'), |
| 2013 | \ getregionpos([g:buf, 10, 2, 0], [g:buf, 1, 1, 0], |
| 2014 | \ {'type': type, 'exclusive': exclusive })) |
zeertzjq | 26dd09a | 2024-03-10 15:46:58 +0100 | [diff] [blame] | 2015 | endfor |
| 2016 | endfor |
| 2017 | |
| 2018 | #" using invalid positions in buffer |
| 2019 | call assert_fails('call getregion([g:buf, 0, 1, 0], [g:buf, 10, 2, 0])', 'E966:') |
| 2020 | call assert_fails('call getregion([g:buf, 10, 2, 0], [g:buf, 0, 1, 0])', 'E966:') |
| 2021 | call assert_fails('call getregion([g:buf, 1, 1, 0], [g:buf, 11, 2, 0])', 'E966:') |
| 2022 | call assert_fails('call getregion([g:buf, 11, 2, 0], [g:buf, 1, 1, 0])', 'E966:') |
| 2023 | call assert_fails('call getregion([g:buf, 1, 1, 0], [g:buf, 10, 0, 0])', 'E964:') |
| 2024 | call assert_fails('call getregion([g:buf, 10, 0, 0], [g:buf, 1, 1, 0])', 'E964:') |
| 2025 | call assert_fails('call getregion([g:buf, 1, 1, 0], [g:buf, 10, 3, 0])', 'E964:') |
| 2026 | call assert_fails('call getregion([g:buf, 10, 3, 0], [g:buf, 1, 1, 0])', 'E964:') |
Shougo Matsushita | b4757e6 | 2024-05-07 20:49:24 +0200 | [diff] [blame] | 2027 | call assert_fails('call getregion([g:buf, 1, 0, 0], [g:buf, 1, 1, 0])', 'E964:') |
| 2028 | call assert_fails('call getregion([g:buf, 1, 1, 0], [g:buf, 1, 0, 0])', 'E964:') |
Shougo Matsushita | 84bf6e6 | 2024-03-06 21:10:18 +0100 | [diff] [blame] | 2029 | |
| 2030 | #" using invalid buffer |
zeertzjq | 26dd09a | 2024-03-10 15:46:58 +0100 | [diff] [blame] | 2031 | call assert_fails('call getregion([10000, 10, 1, 0], [10000, 10, 1, 0])', 'E681:') |
| 2032 | |
| 2033 | exe $':{g:buf}bwipe!' |
| 2034 | unlet g:buf |
zeertzjq | 2b09de9 | 2024-05-24 07:48:51 +0200 | [diff] [blame] | 2035 | bwipe! |
Yegappan Lakshmanan | 4d55c54 | 2024-02-29 17:30:43 +0100 | [diff] [blame] | 2036 | END |
| 2037 | call v9.CheckLegacyAndVim9Success(lines) |
Shougo Matsushita | 3f905ab | 2024-02-21 00:02:45 +0100 | [diff] [blame] | 2038 | |
Yegappan Lakshmanan | 4d55c54 | 2024-02-29 17:30:43 +0100 | [diff] [blame] | 2039 | let lines =<< trim END |
| 2040 | #" Selection in starts or ends in the middle of a multibyte character |
| 2041 | new |
| 2042 | call setline(1, [ |
| 2043 | \ "abcdefghijk\u00ab", |
| 2044 | \ "\U0001f1e6\u00ab\U0001f1e7\u00ab\U0001f1e8\u00ab\U0001f1e9", |
| 2045 | \ "1234567890" |
| 2046 | \ ]) |
zeertzjq | c95e64f | 2024-05-20 14:00:31 +0200 | [diff] [blame] | 2047 | |
Yegappan Lakshmanan | 4d55c54 | 2024-02-29 17:30:43 +0100 | [diff] [blame] | 2048 | call cursor(1, 3) |
| 2049 | call feedkeys("\<Esc>\<C-v>ljj", 'xt') |
| 2050 | call assert_equal(['cd', "\u00ab ", '34'], |
| 2051 | \ getregion(getpos('v'), getpos('.'), {'type': "\<C-v>" })) |
zeertzjq | c95e64f | 2024-05-20 14:00:31 +0200 | [diff] [blame] | 2052 | call assert_equal([ |
| 2053 | \ [[bufnr('%'), 1, 3, 0], [bufnr('%'), 1, 4, 0]], |
| 2054 | \ [[bufnr('%'), 2, 5, 0], [bufnr('%'), 2, 7, 1]], |
| 2055 | \ [[bufnr('%'), 3, 3, 0], [bufnr('%'), 3, 4, 0]], |
| 2056 | \ ], |
| 2057 | \ getregionpos(getpos('v'), getpos('.'), {'type': "\<C-v>" })) |
| 2058 | |
Yegappan Lakshmanan | 4d55c54 | 2024-02-29 17:30:43 +0100 | [diff] [blame] | 2059 | call cursor(1, 4) |
| 2060 | call feedkeys("\<Esc>\<C-v>ljj", 'xt') |
| 2061 | call assert_equal(['de', "\U0001f1e7", '45'], |
| 2062 | \ getregion(getpos('v'), getpos('.'), {'type': "\<C-v>" })) |
zeertzjq | c95e64f | 2024-05-20 14:00:31 +0200 | [diff] [blame] | 2063 | call assert_equal([ |
| 2064 | \ [[bufnr('%'), 1, 4, 0], [bufnr('%'), 1, 5, 0]], |
| 2065 | \ [[bufnr('%'), 2, 7, 0], [bufnr('%'), 2, 10, 0]], |
| 2066 | \ [[bufnr('%'), 3, 4, 0], [bufnr('%'), 3, 5, 0]], |
| 2067 | \ ], |
| 2068 | \ getregionpos(getpos('v'), getpos('.'), {'type': "\<C-v>" })) |
| 2069 | |
Yegappan Lakshmanan | 4d55c54 | 2024-02-29 17:30:43 +0100 | [diff] [blame] | 2070 | call cursor(1, 5) |
| 2071 | call feedkeys("\<Esc>\<C-v>jj", 'xt') |
| 2072 | call assert_equal(['e', ' ', '5'], |
| 2073 | \ getregion(getpos('v'), getpos('.'), {'type': "\<C-v>" })) |
Shougo Matsushita | b4757e6 | 2024-05-07 20:49:24 +0200 | [diff] [blame] | 2074 | call assert_equal([ |
zeertzjq | c95e64f | 2024-05-20 14:00:31 +0200 | [diff] [blame] | 2075 | \ [[bufnr('%'), 1, 5, 0], [bufnr('%'), 1, 5, 0]], |
zeertzjq | ef73374 | 2024-05-26 18:42:18 +0200 | [diff] [blame] | 2076 | \ [[bufnr('%'), 2, 7, 1], [bufnr('%'), 2, 7, 2]], |
zeertzjq | c95e64f | 2024-05-20 14:00:31 +0200 | [diff] [blame] | 2077 | \ [[bufnr('%'), 3, 5, 0], [bufnr('%'), 3, 5, 0]], |
| 2078 | \ ], |
| 2079 | \ getregionpos(getpos('v'), getpos('.'), {'type': "\<C-v>" })) |
zeertzjq | ef73374 | 2024-05-26 18:42:18 +0200 | [diff] [blame] | 2080 | call assert_equal(['efghijk«', '🇦«🇧«🇨«🇩', '12345'], |
| 2081 | \ getregion(getpos('v'), getpos('.'), {'type': 'v' })) |
zeertzjq | c95e64f | 2024-05-20 14:00:31 +0200 | [diff] [blame] | 2082 | call assert_equal([ |
Shougo Matsushita | b4757e6 | 2024-05-07 20:49:24 +0200 | [diff] [blame] | 2083 | \ [[bufnr('%'), 1, 5, 0], [bufnr('%'), 1, 13, 0]], |
| 2084 | \ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 22, 0]], |
| 2085 | \ [[bufnr('%'), 3, 1, 0], [bufnr('%'), 3, 5, 0]], |
| 2086 | \ ], |
| 2087 | \ getregionpos(getpos('v'), getpos('.'), {'type': 'v' })) |
zeertzjq | c95e64f | 2024-05-20 14:00:31 +0200 | [diff] [blame] | 2088 | |
zeertzjq | ef73374 | 2024-05-26 18:42:18 +0200 | [diff] [blame] | 2089 | call cursor(1, 5) |
| 2090 | call feedkeys("\<Esc>\<C-v>5l2j", 'xt') |
| 2091 | call assert_equal(['efghij', ' «🇨« ', '567890'], |
| 2092 | \ getregion(getpos('v'), getpos('.'), {'type': "\<C-v>" })) |
| 2093 | call assert_equal([ |
| 2094 | \ [[bufnr('%'), 1, 5, 0], [bufnr('%'), 1, 10, 0]], |
| 2095 | \ [[bufnr('%'), 2, 7, 1], [bufnr('%'), 2, 19, 1]], |
| 2096 | \ [[bufnr('%'), 3, 5, 0], [bufnr('%'), 3, 10, 0]], |
| 2097 | \ ], |
| 2098 | \ getregionpos(getpos('v'), getpos('.'), {'type': "\<C-v>" })) |
| 2099 | |
| 2100 | call cursor(1, 4) |
| 2101 | call feedkeys("\<Esc>\<C-v>02j", 'xt') |
| 2102 | call assert_equal(['abcd', '🇦« ', '1234'], |
| 2103 | \ getregion(getpos('v'), getpos('.'), {'type': "\<C-v>" })) |
| 2104 | call assert_equal([ |
| 2105 | \ [[bufnr('%'), 1, 1, 0], [bufnr('%'), 1, 4, 0]], |
| 2106 | \ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 7, 1]], |
| 2107 | \ [[bufnr('%'), 3, 1, 0], [bufnr('%'), 3, 4, 0]], |
| 2108 | \ ], |
| 2109 | \ getregionpos(getpos('v'), getpos('.'), {'type': "\<C-v>" })) |
| 2110 | |
zeertzjq | 52a6f34 | 2024-05-22 16:42:44 +0200 | [diff] [blame] | 2111 | #" characterwise selection with multibyte chars |
Yegappan Lakshmanan | 4d55c54 | 2024-02-29 17:30:43 +0100 | [diff] [blame] | 2112 | call cursor(1, 1) |
| 2113 | call feedkeys("\<Esc>vj", 'xt') |
| 2114 | call assert_equal(['abcdefghijk«', "\U0001f1e6"], |
| 2115 | \ getregion(getpos('v'), getpos('.'), {'type': 'v' })) |
zeertzjq | c95e64f | 2024-05-20 14:00:31 +0200 | [diff] [blame] | 2116 | call assert_equal([ |
| 2117 | \ [[bufnr('%'), 1, 1, 0], [bufnr('%'), 1, 13, 0]], |
| 2118 | \ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 4, 0]], |
| 2119 | \ ], |
| 2120 | \ getregionpos(getpos('v'), getpos('.'), {'type': 'v' })) |
Shougo Matsushita | 19b7188 | 2024-02-28 22:48:12 +0100 | [diff] [blame] | 2121 | |
zeertzjq | 52a6f34 | 2024-05-22 16:42:44 +0200 | [diff] [blame] | 2122 | set selection=exclusive |
| 2123 | call feedkeys('l', 'xt') |
| 2124 | call assert_equal(['abcdefghijk«', "\U0001f1e6"], |
| 2125 | \ getregion(getpos('v'), getpos('.'), {'type': 'v' })) |
| 2126 | call assert_equal([ |
| 2127 | \ [[bufnr('%'), 1, 1, 0], [bufnr('%'), 1, 13, 0]], |
| 2128 | \ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 4, 0]], |
| 2129 | \ ], |
| 2130 | \ getregionpos(getpos('v'), getpos('.'), {'type': 'v' })) |
| 2131 | |
Yegappan Lakshmanan | 4d55c54 | 2024-02-29 17:30:43 +0100 | [diff] [blame] | 2132 | #" marks on multibyte chars |
Yegappan Lakshmanan | 4d55c54 | 2024-02-29 17:30:43 +0100 | [diff] [blame] | 2133 | call setpos("'a", [0, 1, 11, 0]) |
| 2134 | call setpos("'b", [0, 2, 16, 0]) |
| 2135 | call setpos("'c", [0, 2, 0, 0]) |
| 2136 | call cursor(1, 1) |
zeertzjq | c95e64f | 2024-05-20 14:00:31 +0200 | [diff] [blame] | 2137 | |
Yegappan Lakshmanan | 4d55c54 | 2024-02-29 17:30:43 +0100 | [diff] [blame] | 2138 | call assert_equal(['ghijk', '🇨«🇩'], |
Shougo Matsushita | b4757e6 | 2024-05-07 20:49:24 +0200 | [diff] [blame] | 2139 | \ getregion(getpos("'a"), getpos("'b"), {'type': "\<C-v>" })) |
zeertzjq | c95e64f | 2024-05-20 14:00:31 +0200 | [diff] [blame] | 2140 | call assert_equal([ |
| 2141 | \ [[bufnr('%'), 1, 7, 0], [bufnr('%'), 1, 11, 0]], |
| 2142 | \ [[bufnr('%'), 2, 13, 0], [bufnr('%'), 2, 22, 0]], |
| 2143 | \ ], |
| 2144 | \ getregionpos(getpos("'a"), getpos("'b"), {'type': "\<C-v>" })) |
| 2145 | |
Yegappan Lakshmanan | 4d55c54 | 2024-02-29 17:30:43 +0100 | [diff] [blame] | 2146 | call assert_equal(['k«', '🇦«🇧«🇨'], |
| 2147 | \ getregion(getpos("'a"), getpos("'b"), {'type': 'v' })) |
zeertzjq | c95e64f | 2024-05-20 14:00:31 +0200 | [diff] [blame] | 2148 | call assert_equal([ |
| 2149 | \ [[bufnr('%'), 1, 11, 0], [bufnr('%'), 1, 13, 0]], |
| 2150 | \ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 16, 0]], |
| 2151 | \ ], |
| 2152 | \ getregionpos(getpos("'a"), getpos("'b"), {'type': 'v' })) |
| 2153 | |
Yegappan Lakshmanan | 4d55c54 | 2024-02-29 17:30:43 +0100 | [diff] [blame] | 2154 | call assert_equal(['k«'], |
| 2155 | \ getregion(getpos("'a"), getpos("'c"), {'type': 'v' })) |
zeertzjq | c95e64f | 2024-05-20 14:00:31 +0200 | [diff] [blame] | 2156 | call assert_equal([ |
| 2157 | \ [[bufnr('%'), 1, 11, 0], [bufnr('%'), 1, 13, 0]], |
| 2158 | \ ], |
| 2159 | \ getregionpos(getpos("'a"), getpos("'c"), {'type': 'v' })) |
Shougo Matsushita | 3f905ab | 2024-02-21 00:02:45 +0100 | [diff] [blame] | 2160 | |
Yegappan Lakshmanan | 4d55c54 | 2024-02-29 17:30:43 +0100 | [diff] [blame] | 2161 | #" use inclusive selection, although 'selection' is exclusive |
| 2162 | call setpos("'a", [0, 1, 11, 0]) |
| 2163 | call setpos("'b", [0, 1, 1, 0]) |
| 2164 | call assert_equal(['abcdefghijk'], |
| 2165 | \ getregion(getpos("'a"), getpos("'b"), |
| 2166 | \ {'type': "\<c-v>", 'exclusive': v:false })) |
| 2167 | call assert_equal(['abcdefghij'], |
| 2168 | \ getregion(getpos("'a"), getpos("'b"), |
| 2169 | \ {'type': "\<c-v>", 'exclusive': v:true })) |
| 2170 | call assert_equal(['abcdefghijk'], |
| 2171 | \ getregion(getpos("'a"), getpos("'b"), |
| 2172 | \ {'type': 'v', 'exclusive': 0 })) |
| 2173 | call assert_equal(['abcdefghij'], |
| 2174 | \ getregion(getpos("'a"), getpos("'b"), |
| 2175 | \ {'type': 'v', 'exclusive': 1 })) |
| 2176 | call assert_equal(['abcdefghijk«'], |
| 2177 | \ getregion(getpos("'a"), getpos("'b"), |
| 2178 | \ {'type': 'V', 'exclusive': 0 })) |
| 2179 | call assert_equal(['abcdefghijk«'], |
| 2180 | \ getregion(getpos("'a"), getpos("'b"), |
| 2181 | \ {'type': 'V', 'exclusive': 1 })) |
zeertzjq | 2b09de9 | 2024-05-24 07:48:51 +0200 | [diff] [blame] | 2182 | |
| 2183 | set selection& |
| 2184 | bwipe! |
Yegappan Lakshmanan | 4d55c54 | 2024-02-29 17:30:43 +0100 | [diff] [blame] | 2185 | END |
| 2186 | call v9.CheckLegacyAndVim9Success(lines) |
Shougo Matsushita | 3f905ab | 2024-02-21 00:02:45 +0100 | [diff] [blame] | 2187 | |
Yegappan Lakshmanan | 4d55c54 | 2024-02-29 17:30:43 +0100 | [diff] [blame] | 2188 | let lines =<< trim END |
| 2189 | #" Exclusive selection |
| 2190 | new |
| 2191 | set selection=exclusive |
| 2192 | call setline(1, ["a\tc", "x\tz", '', '']) |
| 2193 | call cursor(1, 1) |
| 2194 | call feedkeys("\<Esc>v2l", 'xt') |
| 2195 | call assert_equal(["a\t"], |
| 2196 | \ getregion(getpos('v'), getpos('.'), {'type': 'v' })) |
| 2197 | call cursor(1, 1) |
| 2198 | call feedkeys("\<Esc>v$G", 'xt') |
| 2199 | call assert_equal(["a\tc", "x\tz", ''], |
| 2200 | \ getregion(getpos('v'), getpos('.'), {'type': 'v' })) |
| 2201 | call cursor(1, 1) |
| 2202 | call feedkeys("\<Esc>v$j", 'xt') |
| 2203 | call assert_equal(["a\tc", "x\tz"], |
| 2204 | \ getregion(getpos('v'), getpos('.'), {'type': 'v' })) |
| 2205 | call cursor(1, 1) |
| 2206 | call feedkeys("\<Esc>\<C-v>$j", 'xt') |
| 2207 | call assert_equal(["a\tc", "x\tz"], |
| 2208 | \ getregion(getpos('v'), getpos('.'), {'type': "\<C-v>" })) |
| 2209 | call cursor(1, 1) |
| 2210 | call feedkeys("\<Esc>\<C-v>$G", 'xt') |
| 2211 | call assert_equal(["a", "x", '', ''], |
| 2212 | \ getregion(getpos('v'), getpos('.'), {'type': "\<C-v>" })) |
| 2213 | call cursor(1, 1) |
| 2214 | call feedkeys("\<Esc>wv2j", 'xt') |
| 2215 | call assert_equal(["c", "x\tz"], |
| 2216 | \ getregion(getpos('v'), getpos('.'), {'type': 'v' })) |
| 2217 | set selection& |
zeertzjq | 52a6f34 | 2024-05-22 16:42:44 +0200 | [diff] [blame] | 2218 | bwipe! |
Yegappan Lakshmanan | 4d55c54 | 2024-02-29 17:30:43 +0100 | [diff] [blame] | 2219 | |
| 2220 | #" Exclusive selection 2 |
| 2221 | new |
| 2222 | call setline(1, ["a\tc", "x\tz", '', '']) |
zeertzjq | 701ad50 | 2024-05-23 07:47:55 +0200 | [diff] [blame] | 2223 | |
Yegappan Lakshmanan | 4d55c54 | 2024-02-29 17:30:43 +0100 | [diff] [blame] | 2224 | call cursor(1, 1) |
| 2225 | call feedkeys("\<Esc>v2l", 'xt') |
| 2226 | call assert_equal(["a\t"], |
| 2227 | \ getregion(getpos('v'), getpos('.'), {'exclusive': v:true })) |
zeertzjq | 701ad50 | 2024-05-23 07:47:55 +0200 | [diff] [blame] | 2228 | call assert_equal([ |
| 2229 | \ [[bufnr('%'), 1, 1, 0], [bufnr('%'), 1, 2, 0]], |
| 2230 | \ ], |
| 2231 | \ getregionpos(getpos('v'), getpos('.'), {'exclusive': v:true })) |
| 2232 | |
Yegappan Lakshmanan | 4d55c54 | 2024-02-29 17:30:43 +0100 | [diff] [blame] | 2233 | call cursor(1, 1) |
| 2234 | call feedkeys("\<Esc>v$G", 'xt') |
| 2235 | call assert_equal(["a\tc", "x\tz", ''], |
| 2236 | \ getregion(getpos('v'), getpos('.'), {'exclusive': v:true })) |
zeertzjq | 701ad50 | 2024-05-23 07:47:55 +0200 | [diff] [blame] | 2237 | call assert_equal([ |
| 2238 | \ [[bufnr('%'), 1, 1, 0], [bufnr('%'), 1, 3, 0]], |
| 2239 | \ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 3, 0]], |
| 2240 | \ [[bufnr('%'), 3, 0, 0], [bufnr('%'), 3, 0, 0]], |
| 2241 | \ ], |
| 2242 | \ getregionpos(getpos('v'), getpos('.'), {'exclusive': v:true })) |
| 2243 | |
Yegappan Lakshmanan | 4d55c54 | 2024-02-29 17:30:43 +0100 | [diff] [blame] | 2244 | call cursor(1, 1) |
| 2245 | call feedkeys("\<Esc>v$j", 'xt') |
| 2246 | call assert_equal(["a\tc", "x\tz"], |
| 2247 | \ getregion(getpos('v'), getpos('.'), {'exclusive': v:true })) |
zeertzjq | 701ad50 | 2024-05-23 07:47:55 +0200 | [diff] [blame] | 2248 | call assert_equal([ |
| 2249 | \ [[bufnr('%'), 1, 1, 0], [bufnr('%'), 1, 3, 0]], |
| 2250 | \ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 3, 0]], |
| 2251 | \ ], |
| 2252 | \ getregionpos(getpos('v'), getpos('.'), {'exclusive': v:true })) |
| 2253 | |
Yegappan Lakshmanan | 4d55c54 | 2024-02-29 17:30:43 +0100 | [diff] [blame] | 2254 | call cursor(1, 1) |
| 2255 | call feedkeys("\<Esc>\<C-v>$j", 'xt') |
| 2256 | call assert_equal(["a\tc", "x\tz"], |
| 2257 | \ getregion(getpos('v'), getpos('.'), |
| 2258 | \ {'exclusive': v:true, 'type': "\<C-v>" })) |
zeertzjq | 701ad50 | 2024-05-23 07:47:55 +0200 | [diff] [blame] | 2259 | call assert_equal([ |
| 2260 | \ [[bufnr('%'), 1, 1, 0], [bufnr('%'), 1, 3, 0]], |
| 2261 | \ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 3, 0]], |
| 2262 | \ ], |
| 2263 | \ getregionpos(getpos('v'), getpos('.'), |
| 2264 | \ {'exclusive': v:true, 'type': "\<C-v>" })) |
| 2265 | |
Yegappan Lakshmanan | 4d55c54 | 2024-02-29 17:30:43 +0100 | [diff] [blame] | 2266 | call cursor(1, 1) |
| 2267 | call feedkeys("\<Esc>\<C-v>$G", 'xt') |
| 2268 | call assert_equal(["a", "x", '', ''], |
| 2269 | \ getregion(getpos('v'), getpos('.'), |
| 2270 | \ {'exclusive': v:true, 'type': "\<C-v>" })) |
zeertzjq | 701ad50 | 2024-05-23 07:47:55 +0200 | [diff] [blame] | 2271 | call assert_equal([ |
| 2272 | \ [[bufnr('%'), 1, 1, 0], [bufnr('%'), 1, 1, 0]], |
| 2273 | \ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 1, 0]], |
| 2274 | \ [[bufnr('%'), 3, 0, 0], [bufnr('%'), 3, 0, 0]], |
| 2275 | \ [[bufnr('%'), 4, 0, 0], [bufnr('%'), 4, 0, 0]], |
| 2276 | \ ], |
| 2277 | \ getregionpos(getpos('v'), getpos('.'), |
| 2278 | \ {'exclusive': v:true, 'type': "\<C-v>" })) |
| 2279 | |
Yegappan Lakshmanan | 4d55c54 | 2024-02-29 17:30:43 +0100 | [diff] [blame] | 2280 | call cursor(1, 1) |
| 2281 | call feedkeys("\<Esc>wv2j", 'xt') |
| 2282 | call assert_equal(["c", "x\tz"], |
| 2283 | \ getregion(getpos('v'), getpos('.'), {'exclusive': v:true })) |
zeertzjq | 701ad50 | 2024-05-23 07:47:55 +0200 | [diff] [blame] | 2284 | call assert_equal([ |
| 2285 | \ [[bufnr('%'), 1, 3, 0], [bufnr('%'), 1, 3, 0]], |
| 2286 | \ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 3, 0]], |
| 2287 | \ ], |
| 2288 | \ getregionpos(getpos('v'), getpos('.'), {'exclusive': v:true })) |
Yegappan Lakshmanan | 4d55c54 | 2024-02-29 17:30:43 +0100 | [diff] [blame] | 2289 | |
zeertzjq | 701ad50 | 2024-05-23 07:47:55 +0200 | [diff] [blame] | 2290 | #" 'virtualedit' with exclusive selection |
Yegappan Lakshmanan | 4d55c54 | 2024-02-29 17:30:43 +0100 | [diff] [blame] | 2291 | set selection=exclusive |
| 2292 | set virtualedit=all |
zeertzjq | c95e64f | 2024-05-20 14:00:31 +0200 | [diff] [blame] | 2293 | |
Yegappan Lakshmanan | 4d55c54 | 2024-02-29 17:30:43 +0100 | [diff] [blame] | 2294 | call cursor(1, 1) |
zeertzjq | 701ad50 | 2024-05-23 07:47:55 +0200 | [diff] [blame] | 2295 | call feedkeys("\<Esc>vj", 'xt') |
| 2296 | call assert_equal(["a\tc"], |
| 2297 | \ getregion(getpos('v'), getpos('.'), {'type': 'v' })) |
| 2298 | call assert_equal([ |
| 2299 | \ [[bufnr('%'), 1, 1, 0], [bufnr('%'), 1, 3, 0]], |
| 2300 | \ ], |
| 2301 | \ getregionpos(getpos('v'), getpos('.'), {'type': 'v' })) |
| 2302 | |
| 2303 | call cursor(1, 1) |
| 2304 | call feedkeys("\<Esc>v8l", 'xt') |
| 2305 | call assert_equal(["a\t"], |
| 2306 | \ getregion(getpos('v'), getpos('.'), {'type': 'v' })) |
| 2307 | call assert_equal([ |
| 2308 | \ [[bufnr('%'), 1, 1, 0], [bufnr('%'), 1, 2, 0]], |
| 2309 | \ ], |
| 2310 | \ getregionpos(getpos('v'), getpos('.'), {'type': 'v' })) |
| 2311 | |
| 2312 | call cursor(1, 1) |
| 2313 | call feedkeys("\<Esc>v6l", 'xt') |
| 2314 | call assert_equal(['a '], |
| 2315 | \ getregion(getpos('v'), getpos('.'), {'type': 'v' })) |
| 2316 | call assert_equal([ |
| 2317 | \ [[bufnr('%'), 1, 1, 0], [bufnr('%'), 1, 2, 5]], |
| 2318 | \ ], |
| 2319 | \ getregionpos(getpos('v'), getpos('.'), {'type': 'v' })) |
| 2320 | |
| 2321 | call cursor(1, 1) |
| 2322 | call feedkeys("\<Esc>6lv2l", 'xt') |
| 2323 | call assert_equal([' '], |
| 2324 | \ getregion(getpos('v'), getpos('.'), {'type': 'v' })) |
| 2325 | call assert_equal([ |
| 2326 | \ [[bufnr('%'), 1, 2, 5], [bufnr('%'), 1, 2, 0]], |
| 2327 | \ ], |
| 2328 | \ getregionpos(getpos('v'), getpos('.'), {'type': 'v' })) |
| 2329 | |
| 2330 | call cursor(1, 1) |
zeertzjq | 52a6f34 | 2024-05-22 16:42:44 +0200 | [diff] [blame] | 2331 | call feedkeys("\<Esc>lv2l", 'xt') |
| 2332 | call assert_equal([' '], |
| 2333 | \ getregion(getpos('v'), getpos('.'), {'type': 'v' })) |
| 2334 | call assert_equal([ |
| 2335 | \ [[bufnr('%'), 1, 2, 0], [bufnr('%'), 1, 2, 2]], |
| 2336 | \ ], |
| 2337 | \ getregionpos(getpos('v'), getpos('.'), {'type': 'v' })) |
| 2338 | |
| 2339 | call cursor(1, 1) |
| 2340 | call feedkeys("\<Esc>2lv2l", 'xt') |
| 2341 | call assert_equal([' '], |
| 2342 | \ getregion(getpos('v'), getpos('.'), {'type': 'v' })) |
| 2343 | call assert_equal([ |
| 2344 | \ [[bufnr('%'), 1, 2, 1], [bufnr('%'), 1, 2, 3]], |
| 2345 | \ ], |
| 2346 | \ getregionpos(getpos('v'), getpos('.'), {'type': 'v' })) |
| 2347 | |
| 2348 | call feedkeys('j', 'xt') |
Yegappan Lakshmanan | 4d55c54 | 2024-02-29 17:30:43 +0100 | [diff] [blame] | 2349 | call assert_equal([' c', 'x '], |
| 2350 | \ getregion(getpos('v'), getpos('.'), {'type': 'v' })) |
zeertzjq | c95e64f | 2024-05-20 14:00:31 +0200 | [diff] [blame] | 2351 | call assert_equal([ |
| 2352 | \ [[bufnr('%'), 1, 2, 1], [bufnr('%'), 1, 3, 0]], |
| 2353 | \ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 2, 3]], |
| 2354 | \ ], |
| 2355 | \ getregionpos(getpos('v'), getpos('.'), {'type': 'v' })) |
| 2356 | |
Yegappan Lakshmanan | 4d55c54 | 2024-02-29 17:30:43 +0100 | [diff] [blame] | 2357 | call cursor(1, 1) |
zeertzjq | 52a6f34 | 2024-05-22 16:42:44 +0200 | [diff] [blame] | 2358 | call feedkeys("\<Esc>6l\<C-v>2lj", 'xt') |
| 2359 | call assert_equal([' ', ' '], |
| 2360 | \ getregion(getpos('v'), getpos('.'), {'type': "\<C-v>" })) |
| 2361 | call assert_equal([ |
| 2362 | \ [[bufnr('%'), 1, 2, 5], [bufnr('%'), 1, 2, 7]], |
| 2363 | \ [[bufnr('%'), 2, 2, 5], [bufnr('%'), 2, 2, 7]], |
| 2364 | \ ], |
| 2365 | \ getregionpos(getpos('v'), getpos('.'), {'type': "\<C-v>" })) |
| 2366 | |
| 2367 | call cursor(1, 1) |
| 2368 | call feedkeys("\<Esc>l\<C-v>2l2j", 'xt') |
| 2369 | call assert_equal([' ', ' ', ' '], |
| 2370 | \ getregion(getpos('v'), getpos('.'), {'type': "\<C-v>" })) |
| 2371 | call assert_equal([ |
| 2372 | \ [[bufnr('%'), 1, 2, 0], [bufnr('%'), 1, 2, 2]], |
| 2373 | \ [[bufnr('%'), 2, 2, 0], [bufnr('%'), 2, 2, 2]], |
zeertzjq | 2b09de9 | 2024-05-24 07:48:51 +0200 | [diff] [blame] | 2374 | \ [[bufnr('%'), 3, 0, 0], [bufnr('%'), 3, 0, 0]], |
zeertzjq | 52a6f34 | 2024-05-22 16:42:44 +0200 | [diff] [blame] | 2375 | \ ], |
| 2376 | \ getregionpos(getpos('v'), getpos('.'), {'type': "\<C-v>" })) |
zeertzjq | 2b09de9 | 2024-05-24 07:48:51 +0200 | [diff] [blame] | 2377 | call assert_equal([ |
| 2378 | \ [[bufnr('%'), 1, 2, 0], [bufnr('%'), 1, 2, 2]], |
| 2379 | \ [[bufnr('%'), 2, 2, 0], [bufnr('%'), 2, 2, 2]], |
| 2380 | \ [[bufnr('%'), 3, 1, 1], [bufnr('%'), 3, 1, 3]], |
| 2381 | \ ], |
| 2382 | \ getregionpos(getpos('v'), getpos('.'), |
| 2383 | \ {'type': "\<C-v>", "eol": v:true })) |
zeertzjq | 52a6f34 | 2024-05-22 16:42:44 +0200 | [diff] [blame] | 2384 | |
| 2385 | call cursor(1, 1) |
Yegappan Lakshmanan | 4d55c54 | 2024-02-29 17:30:43 +0100 | [diff] [blame] | 2386 | call feedkeys("\<Esc>2l\<C-v>2l2j", 'xt') |
| 2387 | call assert_equal([' ', ' ', ' '], |
| 2388 | \ getregion(getpos('v'), getpos('.'), {'type': "\<C-v>" })) |
zeertzjq | c95e64f | 2024-05-20 14:00:31 +0200 | [diff] [blame] | 2389 | call assert_equal([ |
zeertzjq | 52a6f34 | 2024-05-22 16:42:44 +0200 | [diff] [blame] | 2390 | \ [[bufnr('%'), 1, 2, 1], [bufnr('%'), 1, 2, 3]], |
| 2391 | \ [[bufnr('%'), 2, 2, 1], [bufnr('%'), 2, 2, 3]], |
zeertzjq | 2b09de9 | 2024-05-24 07:48:51 +0200 | [diff] [blame] | 2392 | \ [[bufnr('%'), 3, 0, 0], [bufnr('%'), 3, 0, 0]], |
zeertzjq | c95e64f | 2024-05-20 14:00:31 +0200 | [diff] [blame] | 2393 | \ ], |
| 2394 | \ getregionpos(getpos('v'), getpos('.'), {'type': "\<C-v>" })) |
zeertzjq | 2b09de9 | 2024-05-24 07:48:51 +0200 | [diff] [blame] | 2395 | call assert_equal([ |
| 2396 | \ [[bufnr('%'), 1, 2, 1], [bufnr('%'), 1, 2, 3]], |
| 2397 | \ [[bufnr('%'), 2, 2, 1], [bufnr('%'), 2, 2, 3]], |
| 2398 | \ [[bufnr('%'), 3, 1, 2], [bufnr('%'), 3, 1, 4]], |
| 2399 | \ ], |
| 2400 | \ getregionpos(getpos('v'), getpos('.'), |
| 2401 | \ {'type': "\<C-v>", "eol": v:true })) |
zeertzjq | c95e64f | 2024-05-20 14:00:31 +0200 | [diff] [blame] | 2402 | |
zeertzjq | 701ad50 | 2024-05-23 07:47:55 +0200 | [diff] [blame] | 2403 | #" 'virtualedit' with inclusive selection |
Yegappan Lakshmanan | 4d55c54 | 2024-02-29 17:30:43 +0100 | [diff] [blame] | 2404 | set selection& |
| 2405 | |
zeertzjq | 701ad50 | 2024-05-23 07:47:55 +0200 | [diff] [blame] | 2406 | call cursor(1, 1) |
| 2407 | call feedkeys("\<Esc>vj", 'xt') |
| 2408 | call assert_equal(["a\tc", 'x'], |
| 2409 | \ getregion(getpos('v'), getpos('.'), {'type': 'v' })) |
| 2410 | call assert_equal([ |
| 2411 | \ [[bufnr('%'), 1, 1, 0], [bufnr('%'), 1, 3, 0]], |
| 2412 | \ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 1, 0]], |
| 2413 | \ ], |
| 2414 | \ getregionpos(getpos('v'), getpos('.'), {'type': 'v' })) |
| 2415 | |
| 2416 | call cursor(1, 1) |
| 2417 | call feedkeys("\<Esc>v8l", 'xt') |
| 2418 | call assert_equal(["a\tc"], |
| 2419 | \ getregion(getpos('v'), getpos('.'), {'type': 'v' })) |
| 2420 | call assert_equal([ |
| 2421 | \ [[bufnr('%'), 1, 1, 0], [bufnr('%'), 1, 3, 0]], |
| 2422 | \ ], |
| 2423 | \ getregionpos(getpos('v'), getpos('.'), {'type': 'v' })) |
| 2424 | |
| 2425 | call cursor(1, 1) |
| 2426 | call feedkeys("\<Esc>v6l", 'xt') |
| 2427 | call assert_equal(['a '], |
| 2428 | \ getregion(getpos('v'), getpos('.'), {'type': 'v' })) |
| 2429 | call assert_equal([ |
| 2430 | \ [[bufnr('%'), 1, 1, 0], [bufnr('%'), 1, 2, 6]], |
| 2431 | \ ], |
| 2432 | \ getregionpos(getpos('v'), getpos('.'), {'type': 'v' })) |
| 2433 | |
| 2434 | call cursor(1, 1) |
| 2435 | call feedkeys("\<Esc>6lv2l", 'xt') |
| 2436 | call assert_equal([' c'], |
| 2437 | \ getregion(getpos('v'), getpos('.'), {'type': 'v' })) |
| 2438 | call assert_equal([ |
| 2439 | \ [[bufnr('%'), 1, 2, 5], [bufnr('%'), 1, 3, 0]], |
| 2440 | \ ], |
| 2441 | \ getregionpos(getpos('v'), getpos('.'), {'type': 'v' })) |
| 2442 | |
| 2443 | call cursor(1, 1) |
| 2444 | call feedkeys("\<Esc>lv2l", 'xt') |
| 2445 | call assert_equal([' '], |
| 2446 | \ getregion(getpos('v'), getpos('.'), {'type': 'v' })) |
| 2447 | call assert_equal([ |
| 2448 | \ [[bufnr('%'), 1, 2, 0], [bufnr('%'), 1, 2, 3]], |
| 2449 | \ ], |
| 2450 | \ getregionpos(getpos('v'), getpos('.'), {'type': 'v' })) |
| 2451 | |
| 2452 | call cursor(1, 1) |
| 2453 | call feedkeys("\<Esc>2lv2l", 'xt') |
| 2454 | call assert_equal([' '], |
| 2455 | \ getregion(getpos('v'), getpos('.'), {'type': 'v' })) |
| 2456 | call assert_equal([ |
| 2457 | \ [[bufnr('%'), 1, 2, 1], [bufnr('%'), 1, 2, 4]], |
| 2458 | \ ], |
| 2459 | \ getregionpos(getpos('v'), getpos('.'), {'type': 'v' })) |
| 2460 | |
| 2461 | call feedkeys('j', 'xt') |
| 2462 | call assert_equal([' c', 'x '], |
| 2463 | \ getregion(getpos('v'), getpos('.'), {'type': 'v' })) |
| 2464 | call assert_equal([ |
| 2465 | \ [[bufnr('%'), 1, 2, 1], [bufnr('%'), 1, 3, 0]], |
| 2466 | \ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 2, 4]], |
| 2467 | \ ], |
| 2468 | \ getregionpos(getpos('v'), getpos('.'), {'type': 'v' })) |
| 2469 | |
| 2470 | call cursor(1, 1) |
| 2471 | call feedkeys("\<Esc>6l\<C-v>2lj", 'xt') |
| 2472 | call assert_equal([' c', ' z'], |
| 2473 | \ getregion(getpos('v'), getpos('.'), {'type': "\<C-v>" })) |
| 2474 | call assert_equal([ |
| 2475 | \ [[bufnr('%'), 1, 2, 5], [bufnr('%'), 1, 3, 0]], |
| 2476 | \ [[bufnr('%'), 2, 2, 5], [bufnr('%'), 2, 3, 0]], |
| 2477 | \ ], |
| 2478 | \ getregionpos(getpos('v'), getpos('.'), {'type': "\<C-v>" })) |
| 2479 | |
| 2480 | call cursor(1, 1) |
| 2481 | call feedkeys("\<Esc>l\<C-v>2l2j", 'xt') |
| 2482 | call assert_equal([' ', ' ', ' '], |
| 2483 | \ getregion(getpos('v'), getpos('.'), {'type': "\<C-v>" })) |
| 2484 | call assert_equal([ |
| 2485 | \ [[bufnr('%'), 1, 2, 0], [bufnr('%'), 1, 2, 3]], |
| 2486 | \ [[bufnr('%'), 2, 2, 0], [bufnr('%'), 2, 2, 3]], |
zeertzjq | 2b09de9 | 2024-05-24 07:48:51 +0200 | [diff] [blame] | 2487 | \ [[bufnr('%'), 3, 0, 0], [bufnr('%'), 3, 0, 0]], |
zeertzjq | 701ad50 | 2024-05-23 07:47:55 +0200 | [diff] [blame] | 2488 | \ ], |
| 2489 | \ getregionpos(getpos('v'), getpos('.'), {'type': "\<C-v>" })) |
zeertzjq | 2b09de9 | 2024-05-24 07:48:51 +0200 | [diff] [blame] | 2490 | call assert_equal([ |
| 2491 | \ [[bufnr('%'), 1, 2, 0], [bufnr('%'), 1, 2, 3]], |
| 2492 | \ [[bufnr('%'), 2, 2, 0], [bufnr('%'), 2, 2, 3]], |
| 2493 | \ [[bufnr('%'), 3, 1, 1], [bufnr('%'), 3, 1, 4]], |
| 2494 | \ ], |
| 2495 | \ getregionpos(getpos('v'), getpos('.'), |
| 2496 | \ {'type': "\<C-v>", "eol": v:true })) |
zeertzjq | 701ad50 | 2024-05-23 07:47:55 +0200 | [diff] [blame] | 2497 | |
| 2498 | call cursor(1, 1) |
| 2499 | call feedkeys("\<Esc>2l\<C-v>2l2j", 'xt') |
| 2500 | call assert_equal([' ', ' ', ' '], |
| 2501 | \ getregion(getpos('v'), getpos('.'), {'type': "\<C-v>" })) |
| 2502 | call assert_equal([ |
| 2503 | \ [[bufnr('%'), 1, 2, 1], [bufnr('%'), 1, 2, 4]], |
| 2504 | \ [[bufnr('%'), 2, 2, 1], [bufnr('%'), 2, 2, 4]], |
zeertzjq | 2b09de9 | 2024-05-24 07:48:51 +0200 | [diff] [blame] | 2505 | \ [[bufnr('%'), 3, 0, 0], [bufnr('%'), 3, 0, 0]], |
zeertzjq | 701ad50 | 2024-05-23 07:47:55 +0200 | [diff] [blame] | 2506 | \ ], |
| 2507 | \ getregionpos(getpos('v'), getpos('.'), {'type': "\<C-v>" })) |
zeertzjq | 2b09de9 | 2024-05-24 07:48:51 +0200 | [diff] [blame] | 2508 | call assert_equal([ |
| 2509 | \ [[bufnr('%'), 1, 2, 1], [bufnr('%'), 1, 2, 4]], |
| 2510 | \ [[bufnr('%'), 2, 2, 1], [bufnr('%'), 2, 2, 4]], |
| 2511 | \ [[bufnr('%'), 3, 1, 2], [bufnr('%'), 3, 1, 5]], |
| 2512 | \ ], |
| 2513 | \ getregionpos(getpos('v'), getpos('.'), |
| 2514 | \ {'type': "\<C-v>", "eol": v:true })) |
| 2515 | |
| 2516 | set virtualedit& |
| 2517 | bwipe! |
| 2518 | END |
| 2519 | call v9.CheckLegacyAndVim9Success(lines) |
| 2520 | |
| 2521 | let lines =<< trim END |
| 2522 | #" 'virtualedit' with TABs at end of line |
| 2523 | new |
| 2524 | set virtualedit=all |
| 2525 | call setline(1, ["\t", "a\t", "aa\t"]) |
| 2526 | |
| 2527 | call feedkeys("gg06l\<C-v>3l2j", 'xt') |
| 2528 | call assert_equal([' ', ' ', ' '], |
| 2529 | \ getregion(getpos('v'), getpos('.'), {'type': "\<C-v>" })) |
| 2530 | call assert_equal([ |
| 2531 | \ [[bufnr('%'), 1, 1, 6], [bufnr('%'), 1, 1, 0]], |
| 2532 | \ [[bufnr('%'), 2, 2, 5], [bufnr('%'), 2, 2, 0]], |
| 2533 | \ [[bufnr('%'), 3, 3, 4], [bufnr('%'), 3, 3, 0]], |
| 2534 | \ ], |
| 2535 | \ getregionpos(getpos('v'), getpos('.'), {'type': "\<C-v>" })) |
| 2536 | call assert_equal([ |
| 2537 | \ [[bufnr('%'), 1, 1, 6], [bufnr('%'), 1, 2, 2]], |
| 2538 | \ [[bufnr('%'), 2, 2, 5], [bufnr('%'), 2, 3, 2]], |
| 2539 | \ [[bufnr('%'), 3, 3, 4], [bufnr('%'), 3, 4, 2]], |
| 2540 | \ ], |
| 2541 | \ getregionpos(getpos('v'), getpos('.'), |
| 2542 | \ {'type': "\<C-v>", "eol": v:true })) |
| 2543 | |
| 2544 | call feedkeys("gg06lv3l", 'xt') |
| 2545 | call assert_equal([' '], |
| 2546 | \ getregion(getpos('v'), getpos('.'), {'type': 'v' })) |
| 2547 | call assert_equal([ |
| 2548 | \ [[bufnr('%'), 1, 1, 6], [bufnr('%'), 1, 1, 0]], |
| 2549 | \ ], |
| 2550 | \ getregionpos(getpos('v'), getpos('.'), {'type': 'v' })) |
| 2551 | call assert_equal([ |
| 2552 | \ [[bufnr('%'), 1, 1, 6], [bufnr('%'), 1, 2, 2]], |
| 2553 | \ ], |
| 2554 | \ getregionpos(getpos('v'), getpos('.'), |
| 2555 | \ {'type': 'v', "eol": v:true })) |
zeertzjq | 701ad50 | 2024-05-23 07:47:55 +0200 | [diff] [blame] | 2556 | |
| 2557 | set virtualedit& |
Yegappan Lakshmanan | 4d55c54 | 2024-02-29 17:30:43 +0100 | [diff] [blame] | 2558 | bwipe! |
| 2559 | END |
| 2560 | call v9.CheckLegacyAndVim9Success(lines) |
Shougo Matsushita | 3f905ab | 2024-02-21 00:02:45 +0100 | [diff] [blame] | 2561 | endfunc |
| 2562 | |
Shougo Matsushita | 84bf6e6 | 2024-03-06 21:10:18 +0100 | [diff] [blame] | 2563 | func Test_getregion_invalid_buf() |
| 2564 | new |
| 2565 | help |
| 2566 | call cursor(5, 7) |
| 2567 | norm! mA |
| 2568 | call cursor(5, 18) |
| 2569 | norm! mB |
| 2570 | call assert_equal(['Move around:'], getregion(getpos("'A"), getpos("'B"))) |
| 2571 | " close the help window |
| 2572 | q |
zeertzjq | 26dd09a | 2024-03-10 15:46:58 +0100 | [diff] [blame] | 2573 | call assert_fails("call getregion(getpos(\"'A\"), getpos(\"'B\"))", 'E681:') |
Shougo Matsushita | 84bf6e6 | 2024-03-06 21:10:18 +0100 | [diff] [blame] | 2574 | bwipe! |
| 2575 | endfunc |
| 2576 | |
zeertzjq | afc2295 | 2024-05-24 19:07:12 +0200 | [diff] [blame] | 2577 | func Test_getregion_after_yank() |
| 2578 | func! Check_Results(type) |
| 2579 | call assert_equal(g:expected_region, |
| 2580 | \ getregion(getpos("'["), getpos("']"), #{ type: a:type })) |
| 2581 | call assert_equal(g:expected_regionpos, |
| 2582 | \ getregionpos(getpos("'["), getpos("']"), #{ type: a:type })) |
| 2583 | call assert_equal(g:expected_region, |
| 2584 | \ getregion(getpos("']"), getpos("'["), #{ type: a:type })) |
| 2585 | call assert_equal(g:expected_regionpos, |
| 2586 | \ getregionpos(getpos("']"), getpos("'["), #{ type: a:type })) |
| 2587 | let g:checked = 1 |
| 2588 | endfunc |
| 2589 | |
Shougo Matsushita | b4757e6 | 2024-05-07 20:49:24 +0200 | [diff] [blame] | 2590 | autocmd TextYankPost * |
| 2591 | \ : if v:event.operator ==? 'y' |
zeertzjq | afc2295 | 2024-05-24 19:07:12 +0200 | [diff] [blame] | 2592 | \ | call Check_Results(v:event.regtype) |
Shougo Matsushita | b4757e6 | 2024-05-07 20:49:24 +0200 | [diff] [blame] | 2593 | \ | endif |
zeertzjq | afc2295 | 2024-05-24 19:07:12 +0200 | [diff] [blame] | 2594 | |
| 2595 | new |
| 2596 | call setline(1, ['abcd', 'efghijk', 'lmn']) |
| 2597 | |
| 2598 | let g:expected_region = ['abcd'] |
| 2599 | let g:expected_regionpos = [ |
| 2600 | \ [[bufnr('%'), 1, 1, 0], [bufnr('%'), 1, 4, 0]], |
| 2601 | \ ] |
| 2602 | let g:checked = 0 |
Shougo Matsushita | b4757e6 | 2024-05-07 20:49:24 +0200 | [diff] [blame] | 2603 | normal yy |
zeertzjq | afc2295 | 2024-05-24 19:07:12 +0200 | [diff] [blame] | 2604 | call assert_equal(1, g:checked) |
| 2605 | call Check_Results(getregtype('"')) |
| 2606 | |
| 2607 | let g:expected_region = ['cd', 'ghijk', 'n'] |
| 2608 | let g:expected_regionpos = [ |
| 2609 | \ [[bufnr('%'), 1, 3, 0], [bufnr('%'), 1, 4, 0]], |
| 2610 | \ [[bufnr('%'), 2, 3, 0], [bufnr('%'), 2, 7, 0]], |
| 2611 | \ [[bufnr('%'), 3, 3, 0], [bufnr('%'), 3, 3, 0]], |
| 2612 | \ ] |
| 2613 | let g:checked = 0 |
| 2614 | call feedkeys("gg0ll\<C-V>jj$y", 'tx') |
| 2615 | call assert_equal(1, g:checked) |
| 2616 | call Check_Results(getregtype('"')) |
zeertzjq | dff55a3 | 2024-05-25 10:25:36 +0200 | [diff] [blame] | 2617 | call assert_equal(g:expected_region, getreg('"', v:true, v:true)) |
zeertzjq | afc2295 | 2024-05-24 19:07:12 +0200 | [diff] [blame] | 2618 | |
| 2619 | let g:expected_region = ['bc', 'fg', 'mn'] |
| 2620 | let g:expected_regionpos = [ |
| 2621 | \ [[bufnr('%'), 1, 2, 0], [bufnr('%'), 1, 3, 0]], |
| 2622 | \ [[bufnr('%'), 2, 2, 0], [bufnr('%'), 2, 3, 0]], |
| 2623 | \ [[bufnr('%'), 3, 2, 0], [bufnr('%'), 3, 3, 0]], |
| 2624 | \ ] |
| 2625 | let g:checked = 0 |
| 2626 | call feedkeys("gg0l\<C-V>jjly", 'tx') |
| 2627 | call assert_equal(1, g:checked) |
| 2628 | call Check_Results(getregtype('"')) |
zeertzjq | dff55a3 | 2024-05-25 10:25:36 +0200 | [diff] [blame] | 2629 | call assert_equal(g:expected_region, getreg('"', v:true, v:true)) |
| 2630 | |
| 2631 | bwipe! |
| 2632 | |
| 2633 | new |
| 2634 | let lines = ['asdfghjkl', '«口=口»', 'qwertyuiop', '口口=口口', 'zxcvbnm'] |
| 2635 | call setline(1, lines) |
| 2636 | |
| 2637 | let g:expected_region = lines |
| 2638 | let g:expected_regionpos = [ |
| 2639 | \ [[bufnr('%'), 1, 1, 0], [bufnr('%'), 1, 9, 0]], |
| 2640 | \ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 11, 0]], |
| 2641 | \ [[bufnr('%'), 3, 1, 0], [bufnr('%'), 3, 10, 0]], |
| 2642 | \ [[bufnr('%'), 4, 1, 0], [bufnr('%'), 4, 13, 0]], |
| 2643 | \ [[bufnr('%'), 5, 1, 0], [bufnr('%'), 5, 7, 0]], |
| 2644 | \ ] |
| 2645 | let g:checked = 0 |
| 2646 | call feedkeys('ggyG', 'tx') |
| 2647 | call assert_equal(1, g:checked) |
| 2648 | call Check_Results(getregtype('"')) |
| 2649 | call assert_equal(g:expected_region, getreg('"', v:true, v:true)) |
| 2650 | |
| 2651 | let g:expected_region = ['=口»', 'qwertyuiop', '口口=口'] |
| 2652 | let g:expected_regionpos = [ |
| 2653 | \ [[bufnr('%'), 2, 6, 0], [bufnr('%'), 2, 11, 0]], |
| 2654 | \ [[bufnr('%'), 3, 1, 0], [bufnr('%'), 3, 10, 0]], |
| 2655 | \ [[bufnr('%'), 4, 1, 0], [bufnr('%'), 4, 10, 0]], |
| 2656 | \ ] |
| 2657 | let g:checked = 0 |
| 2658 | call feedkeys('2gg02lv2j2ly', 'tx') |
| 2659 | call assert_equal(1, g:checked) |
| 2660 | call Check_Results(getregtype('"')) |
| 2661 | call assert_equal(g:expected_region, getreg('"', v:true, v:true)) |
| 2662 | |
| 2663 | let g:expected_region = ['asdf', '«口=', 'qwer', '口口', 'zxcv'] |
| 2664 | let g:expected_regionpos = [ |
| 2665 | \ [[bufnr('%'), 1, 1, 0], [bufnr('%'), 1, 4, 0]], |
| 2666 | \ [[bufnr('%'), 2, 1, 0], [bufnr('%'), 2, 6, 0]], |
| 2667 | \ [[bufnr('%'), 3, 1, 0], [bufnr('%'), 3, 4, 0]], |
| 2668 | \ [[bufnr('%'), 4, 1, 0], [bufnr('%'), 4, 6, 0]], |
| 2669 | \ [[bufnr('%'), 5, 1, 0], [bufnr('%'), 5, 4, 0]], |
| 2670 | \ ] |
| 2671 | let g:checked = 0 |
| 2672 | call feedkeys("G0\<C-V>3l4ky", 'tx') |
| 2673 | call assert_equal(1, g:checked) |
| 2674 | call Check_Results(getregtype('"')) |
| 2675 | call assert_equal(g:expected_region, getreg('"', v:true, v:true)) |
| 2676 | |
| 2677 | let g:expected_region = ['ghjkl', '口»', 'tyuiop', '=口口', 'bnm'] |
| 2678 | let g:expected_regionpos = [ |
| 2679 | \ [[bufnr('%'), 1, 5, 0], [bufnr('%'), 1, 9, 0]], |
| 2680 | \ [[bufnr('%'), 2, 7, 0], [bufnr('%'), 2, 11, 0]], |
| 2681 | \ [[bufnr('%'), 3, 5, 0], [bufnr('%'), 3, 10, 0]], |
| 2682 | \ [[bufnr('%'), 4, 7, 0], [bufnr('%'), 4, 13, 0]], |
| 2683 | \ [[bufnr('%'), 5, 5, 0], [bufnr('%'), 5, 7, 0]], |
| 2684 | \ ] |
| 2685 | let g:checked = 0 |
| 2686 | call feedkeys("G04l\<C-V>$4ky", 'tx') |
| 2687 | call assert_equal(1, g:checked) |
| 2688 | call Check_Results(getregtype('"')) |
| 2689 | call assert_equal(g:expected_region, getreg('"', v:true, v:true)) |
zeertzjq | afc2295 | 2024-05-24 19:07:12 +0200 | [diff] [blame] | 2690 | |
Shougo Matsushita | b4757e6 | 2024-05-07 20:49:24 +0200 | [diff] [blame] | 2691 | bwipe! |
zeertzjq | afc2295 | 2024-05-24 19:07:12 +0200 | [diff] [blame] | 2692 | |
| 2693 | unlet g:expected_region |
| 2694 | unlet g:expected_regionpos |
| 2695 | unlet g:checked |
| 2696 | autocmd! TextYankPost |
| 2697 | delfunc Check_Results |
Shougo Matsushita | b4757e6 | 2024-05-07 20:49:24 +0200 | [diff] [blame] | 2698 | endfunc |
| 2699 | |
Christian Brabandt | d5c8c09 | 2024-05-08 22:17:19 +0200 | [diff] [blame] | 2700 | func Test_visual_block_cursor_delete() |
| 2701 | new |
| 2702 | call setline(1, 'ab') |
| 2703 | exe ":norm! $\<c-v>hI\<Del>\<ESC>" |
| 2704 | call assert_equal(['b'], getline(1, 1)) |
| 2705 | bwipe! |
| 2706 | endfunc |
| 2707 | |
Christian Brabandt | 1fb9eae | 2024-06-11 20:30:14 +0200 | [diff] [blame] | 2708 | func Test_visual_block_cursor_insert_enter() |
| 2709 | new |
| 2710 | call setline(1, ['asdf asdf', 'asdf asdf', 'asdf asdf', 'asdf asdf']) |
| 2711 | call cursor(1, 5) |
| 2712 | exe ":norm! \<c-v>3jcw\<cr>" |
| 2713 | call assert_equal(['asdfw', 'asdf', 'asdfasdf', 'asdfasdf', 'asdfasdf'], getline(1, '$')) |
| 2714 | bwipe! |
| 2715 | endfunc |
| 2716 | |
Christian Brabandt | bb95589 | 2024-12-16 22:49:15 +0100 | [diff] [blame] | 2717 | func Test_visual_block_exclusive_selection() |
| 2718 | new |
| 2719 | set selection=exclusive |
| 2720 | call setline(1, ['asöd asdf', 'asdf asdf', 'as€d asdf', 'asdf asdf']) |
| 2721 | call cursor(1, 1) |
| 2722 | exe ":norm! \<c-v>eh3j~" |
| 2723 | call assert_equal(['ASÖd asdf', 'ASDf asdf', 'AS€d asdf', 'ASDf asdf'], getline(1, '$')) |
| 2724 | exe ":norm! 1v~" |
| 2725 | call assert_equal(['asöd asdf', 'asdf asdf', 'as€d asdf', 'asdf asdf'], getline(1, '$')) |
| 2726 | bwipe! |
| 2727 | set selection&vim |
| 2728 | endfunc |
| 2729 | |
| 2730 | func Test_visual_block_exclusive_selection_adjusted() |
| 2731 | new |
| 2732 | " Test that the end-position of the visual selection is adjusted for exclusive selection |
| 2733 | set selection=exclusive |
| 2734 | call setline(1, ['asöd asdf ', 'asdf asdf ', 'as€d asdf ', 'asdf asdf ']) |
| 2735 | call cursor(1, 1) |
| 2736 | " inclusive motion |
| 2737 | exe ":norm! \<c-v>e3jy" |
| 2738 | call assert_equal([0, 4, 5, 0], getpos("'>")) |
| 2739 | " exclusive motion |
| 2740 | exe ":norm! \<c-v>ta3jy" |
| 2741 | call assert_equal([0, 4, 6, 0], getpos("'>")) |
| 2742 | " another inclusive motion |
| 2743 | exe ":norm! \<c-v>g_3jy" |
| 2744 | call assert_equal([0, 4, 10, 0], getpos("'>")) |
| 2745 | |
| 2746 | " Reset selection option to Vim default |
| 2747 | set selection&vim |
| 2748 | call cursor(1, 1) |
| 2749 | |
| 2750 | " inclusive motion |
| 2751 | exe ":norm! \<c-v>e3jy" |
| 2752 | call assert_equal([0, 4, 4, 0], getpos("'>")) |
| 2753 | " exclusive motion |
| 2754 | exe ":norm! \<c-v>ta3jy" |
| 2755 | call assert_equal([0, 4, 5, 0], getpos("'>")) |
| 2756 | " another inclusive motion |
| 2757 | exe ":norm! \<c-v>g_3jy" |
| 2758 | call assert_equal([0, 4, 9, 0], getpos("'>")) |
| 2759 | bwipe! |
| 2760 | set selection&vim |
| 2761 | endfunc |
| 2762 | |
Christian Brabandt | c9a1e25 | 2025-01-11 15:25:00 +0100 | [diff] [blame] | 2763 | " the following caused a Heap-Overflow, because Vim was accessing outside of a |
| 2764 | " line end |
| 2765 | func Test_visual_pos_buffer_heap_overflow() |
| 2766 | set virtualedit=all |
| 2767 | args Xa Xb |
| 2768 | all |
| 2769 | call setline(1, ['', '', '']) |
| 2770 | call cursor(3, 1) |
| 2771 | wincmd w |
| 2772 | call setline(1, 'foobar') |
| 2773 | normal! $lv0 |
| 2774 | all |
| 2775 | call setreg('"', 'baz') |
| 2776 | normal! [P |
| 2777 | set virtualedit= |
| 2778 | bw! Xa Xb |
| 2779 | endfunc |
| 2780 | |
Bram Moolenaar | 6f1f0ca | 2019-12-01 18:16:18 +0100 | [diff] [blame] | 2781 | " vim: shiftwidth=2 sts=2 expandtab |