test_cursor_func.vim (19633B)
1 " Tests for cursor() and other functions that get/set the cursor position 2 3 source check.vim 4 5 func Test_wrong_arguments() 6 call assert_fails('call cursor(1. 3)', 'E474:') 7 call assert_fails('call cursor(v:_null_list)', 'E474:') 8 endfunc 9 10 func Test_move_cursor() 11 new 12 call setline(1, ['aaa', 'bbb', 'ccc', 'ddd']) 13 14 call cursor([1, 1, 0, 1]) 15 call assert_equal([1, 1, 0, 1], getcurpos()[1:]) 16 call cursor([4, 3, 0, 3]) 17 call assert_equal([4, 3, 0, 3], getcurpos()[1:]) 18 19 call cursor(2, 2) 20 call assert_equal([2, 2, 0, 2], getcurpos()[1:]) 21 " line number zero keeps the line number 22 call cursor(0, 1) 23 call assert_equal([2, 1, 0, 1], getcurpos()[1:]) 24 " col number zero keeps the column 25 call cursor(3, 0) 26 call assert_equal([3, 1, 0, 1], getcurpos()[1:]) 27 " below last line goes to last line 28 eval [9, 1]->cursor() 29 call assert_equal([4, 1, 0, 1], getcurpos()[1:]) 30 " pass string arguments 31 call cursor('3', '3') 32 call assert_equal([3, 3, 0, 3], getcurpos()[1:]) 33 34 call setline(1, ["\<TAB>"]) 35 call cursor(1, 1, 1) 36 call assert_equal([1, 1, 1], getcurpos()[1:3]) 37 38 call assert_fails('call cursor(-1, -1)', 'E475:') 39 40 quit! 41 endfunc 42 43 func Test_curswant_maxcol() 44 new 45 call setline(1, 'foo') 46 47 " Test that after "$" command curswant is set to the same value as v:maxcol. 48 normal! 1G$ 49 call assert_equal(v:maxcol, getcurpos()[4]) 50 call assert_equal(v:maxcol, winsaveview().curswant) 51 52 quit! 53 endfunc 54 55 " Very short version of what matchparen does. 56 function s:Highlight_Matching_Pair() 57 let save_cursor = getcurpos() 58 eval save_cursor->setpos('.') 59 endfunc 60 61 func Test_curswant_with_autocommand() 62 new 63 call setline(1, ['func()', '{', '}', '----']) 64 autocmd! CursorMovedI * call s:Highlight_Matching_Pair() 65 exe "normal! 3Ga\<Down>X\<Esc>" 66 call assert_equal('-X---', getline(4)) 67 autocmd! CursorMovedI * 68 quit! 69 endfunc 70 71 " Tests for behavior of curswant with cursorcolumn/line 72 func Test_curswant_with_cursorcolumn() 73 new 74 call setline(1, ['01234567', '']) 75 exe "normal! ggf6j" 76 call assert_equal(6, winsaveview().curswant) 77 set cursorcolumn 78 call assert_equal(6, winsaveview().curswant) 79 quit! 80 endfunc 81 82 func Test_curswant_with_cursorline() 83 new 84 call setline(1, ['01234567', '']) 85 exe "normal! ggf6j" 86 call assert_equal(6, winsaveview().curswant) 87 set cursorline 88 call assert_equal(6, winsaveview().curswant) 89 quit! 90 endfunc 91 92 func Test_screenpos() 93 if has('gui_running') 94 set lines=25 95 set columns=78 96 endif 97 rightbelow new 98 rightbelow 20vsplit 99 call setline(1, ["\tsome text", "long wrapping line here", "next line"]) 100 redraw 101 let winid = win_getid() 102 let [winrow, wincol] = win_screenpos(winid) 103 call assert_equal({'row': winrow, 104 \ 'col': wincol + 0, 105 \ 'curscol': wincol + 7, 106 \ 'endcol': wincol + 7}, winid->screenpos(1, 1)) 107 call assert_equal({'row': winrow, 108 \ 'col': wincol + 13, 109 \ 'curscol': wincol + 13, 110 \ 'endcol': wincol + 13}, winid->screenpos(1, 7)) 111 call assert_equal({'row': winrow + 2, 112 \ 'col': wincol + 1, 113 \ 'curscol': wincol + 1, 114 \ 'endcol': wincol + 1}, screenpos(winid, 2, 22)) 115 setlocal number 116 call assert_equal({'row': winrow + 3, 117 \ 'col': wincol + 9, 118 \ 'curscol': wincol + 9, 119 \ 'endcol': wincol + 9}, screenpos(winid, 2, 22)) 120 121 let wininfo = getwininfo(winid)[0] 122 call setline(3, ['x']->repeat(wininfo.height)) 123 call setline(line('$') + 1, 'x'->repeat(wininfo.width * 3)) 124 setlocal nonumber display=lastline so=0 125 exe "normal G\<C-Y>\<C-Y>" 126 redraw 127 call assert_equal({'row': winrow + wininfo.height - 1, 128 \ 'col': wincol + 7, 129 \ 'curscol': wincol + 7, 130 \ 'endcol': wincol + 7}, winid->screenpos(line('$'), 8)) 131 call assert_equal({'row': 0, 'col': 0, 'curscol': 0, 'endcol': 0}, 132 \ winid->screenpos(line('$'), 22)) 133 134 1split 135 136 " w_leftcol should be subtracted 137 setlocal nowrap 138 normal G050zl$ 139 redraw 140 call assert_equal({'row': winrow + 0, 141 \ 'col': wincol + 10 - 1, 142 \ 'curscol': wincol + 10 - 1, 143 \ 'endcol': wincol + 10 - 1}, 144 \ screenpos(win_getid(), line('.'), col('.'))) 145 146 " w_skipcol should be taken into account 147 setlocal wrap 148 normal $ 149 redraw 150 call assert_equal({'row': winrow + 0, 151 \ 'col': wincol + 20 - 1, 152 \ 'curscol': wincol + 20 - 1, 153 \ 'endcol': wincol + 20 - 1}, 154 \ screenpos(win_getid(), line('.'), col('.'))) 155 call assert_equal({'row': 0, 'col': 0, 'curscol': 0, 'endcol': 0}, 156 \ screenpos(win_getid(), line('.'), col('.') - 20)) 157 setlocal number 158 redraw 159 call assert_equal({'row': winrow + 0, 160 \ 'col': wincol + 16 - 1, 161 \ 'curscol': wincol + 16 - 1, 162 \ 'endcol': wincol + 16 - 1}, 163 \ screenpos(win_getid(), line('.'), col('.'))) 164 call assert_equal({'row': 0, 'col': 0, 'curscol': 0, 'endcol': 0}, 165 \ screenpos(win_getid(), line('.'), col('.') - 16)) 166 set cpoptions+=n 167 redraw 168 call assert_equal({'row': winrow + 0, 169 \ 'col': wincol + 4 - 1, 170 \ 'curscol': wincol + 4 - 1, 171 \ 'endcol': wincol + 4 - 1}, 172 \ screenpos(win_getid(), line('.'), col('.'))) 173 call assert_equal({'row': 0, 'col': 0, 'curscol': 0, 'endcol': 0}, 174 \ screenpos(win_getid(), line('.'), col('.') - 4)) 175 176 wincmd + 177 call setline(line('$') + 1, 'last line') 178 setlocal smoothscroll 179 normal G$ 180 redraw 181 call assert_equal({'row': winrow + 1, 182 \ 'col': wincol + 4 + 9 - 1, 183 \ 'curscol': wincol + 4 + 9 - 1, 184 \ 'endcol': wincol + 4 + 9 - 1}, 185 \ screenpos(win_getid(), line('.'), col('.'))) 186 set cpoptions-=n 187 redraw 188 call assert_equal({'row': winrow + 1, 189 \ 'col': wincol + 4 + 9 - 1, 190 \ 'curscol': wincol + 4 + 9 - 1, 191 \ 'endcol': wincol + 4 + 9 - 1}, 192 \ screenpos(win_getid(), line('.'), col('.'))) 193 setlocal nonumber 194 redraw 195 call assert_equal({'row': winrow + 1, 196 \ 'col': wincol + 9 - 1, 197 \ 'curscol': wincol + 9 - 1, 198 \ 'endcol': wincol + 9 - 1}, 199 \ screenpos(win_getid(), line('.'), col('.'))) 200 201 close 202 call assert_equal({}, screenpos(999, 1, 1)) 203 204 bwipe! 205 set display& 206 207 call assert_equal(#{col: 1, row: 1, endcol: 1, curscol: 1}, screenpos(win_getid(), 1, 1)) 208 " nmenu WinBar.TEST : 209 setlocal winbar=TEST 210 call assert_equal(#{col: 1, row: 2, endcol: 1, curscol: 1}, screenpos(win_getid(), 1, 1)) 211 " nunmenu WinBar.TEST 212 setlocal winbar& 213 call assert_equal(#{col: 1, row: 1, endcol: 1, curscol: 1}, screenpos(win_getid(), 1, 1)) 214 215 call assert_equal(#{col: 0, row: 0, endcol: 0, curscol: 0}, screenpos(0, 0, 1)) 216 call assert_equal(#{col: 0, row: 0, endcol: 0, curscol: 0}, screenpos(0, -1, 1)) 217 call assert_equal(#{col: 1, row: 1, endcol: 1, curscol: 1}, screenpos(0, 1, -v:maxcol)) 218 endfunc 219 220 func Test_screenpos_fold() 221 CheckFeature folding 222 223 enew! 224 call setline(1, range(10)) 225 3,5fold 226 redraw 227 call assert_equal(2, screenpos(1, 2, 1).row) 228 call assert_equal(#{col: 1, row: 3, endcol: 1, curscol: 1}, screenpos(1, 3, 1)) 229 call assert_equal(#{col: 1, row: 3, endcol: 1, curscol: 1}, screenpos(1, 4, 1)) 230 call assert_equal(#{col: 1, row: 3, endcol: 1, curscol: 1}, screenpos(1, 5, 1)) 231 setlocal number 232 call assert_equal(#{col: 5, row: 3, endcol: 5, curscol: 5}, screenpos(1, 3, 1)) 233 call assert_equal(#{col: 5, row: 3, endcol: 5, curscol: 5}, screenpos(1, 4, 1)) 234 call assert_equal(#{col: 5, row: 3, endcol: 5, curscol: 5}, screenpos(1, 5, 1)) 235 call assert_equal(4, screenpos(1, 6, 1).row) 236 bwipe! 237 endfunc 238 239 func Test_screenpos_diff() 240 CheckFeature diff 241 242 enew! 243 call setline(1, ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']) 244 vnew 245 call setline(1, ['a', 'b', 'c', 'g', 'h', 'i']) 246 windo diffthis 247 wincmd w 248 call assert_equal(#{col: 3, row: 7, endcol: 3, curscol: 3}, screenpos(0, 4, 1)) 249 call assert_equal(#{col: 3, row: 8, endcol: 3, curscol: 3}, screenpos(0, 5, 1)) 250 exe "normal! 3\<C-E>" 251 call assert_equal(#{col: 3, row: 4, endcol: 3, curscol: 3}, screenpos(0, 4, 1)) 252 call assert_equal(#{col: 3, row: 5, endcol: 3, curscol: 3}, screenpos(0, 5, 1)) 253 exe "normal! \<C-E>" 254 call assert_equal(#{col: 3, row: 3, endcol: 3, curscol: 3}, screenpos(0, 4, 1)) 255 call assert_equal(#{col: 3, row: 4, endcol: 3, curscol: 3}, screenpos(0, 5, 1)) 256 exe "normal! \<C-E>" 257 call assert_equal(#{col: 3, row: 2, endcol: 3, curscol: 3}, screenpos(0, 4, 1)) 258 call assert_equal(#{col: 3, row: 3, endcol: 3, curscol: 3}, screenpos(0, 5, 1)) 259 exe "normal! \<C-E>" 260 call assert_equal(#{col: 3, row: 1, endcol: 3, curscol: 3}, screenpos(0, 4, 1)) 261 call assert_equal(#{col: 3, row: 2, endcol: 3, curscol: 3}, screenpos(0, 5, 1)) 262 263 windo diffoff 264 bwipe! 265 bwipe! 266 endfunc 267 268 func Test_screenpos_number() 269 rightbelow new 270 rightbelow 73vsplit 271 call setline (1, repeat('x', 66)) 272 setlocal number 273 redraw 274 let winid = win_getid() 275 let [winrow, wincol] = win_screenpos(winid) 276 let pos = screenpos(winid, 1, 66) 277 call assert_equal(winrow, pos.row) 278 call assert_equal(wincol + 66 + 3, pos.col) 279 280 call assert_fails('echo screenpos(0, 2, 1)', 'E966:') 281 282 close 283 bwipe! 284 endfunc 285 286 func Test_screenpos_edit_newfile() 287 new 288 20vsp 289 setl nowrap 290 call setline(1, 'abcdefghijklmnopqrstuvwxyz') 291 call cursor(1, 10) 292 norm! 5zl 293 call assert_equal(#{col: 5, row: 1, endcol: 5, curscol: 5}, screenpos(win_getid(), 1, 10)) 294 enew! 295 call assert_equal(1, &l:wrap) 296 call assert_equal(#{col: 1, row: 1, endcol: 1, curscol: 1}, screenpos(win_getid(), 1, 1)) 297 298 bwipe! 299 endfunc 300 301 " Save the visual start character position 302 func SaveVisualStartCharPos() 303 call add(g:VisualStartPos, getcharpos('v')) 304 return '' 305 endfunc 306 307 " Save the current cursor character position in insert mode 308 func SaveInsertCurrentCharPos() 309 call add(g:InsertCurrentPos, getcharpos('.')) 310 return '' 311 endfunc 312 313 " Test for the getcharpos() function 314 func Test_getcharpos() 315 call assert_fails('call getcharpos({})', 'E731:') 316 call assert_equal([0, 0, 0, 0], getcharpos(0)) 317 new 318 call setline(1, ['', "01\tà4è678", 'Ⅵ', '012345678', ' │ x']) 319 320 " Test for '.' and '$' 321 normal 1G 322 call assert_equal([0, 1, 1, 0], getcharpos('.')) 323 call assert_equal([0, 5, 1, 0], getcharpos('$')) 324 normal 2G6l 325 call assert_equal([0, 2, 7, 0], getcharpos('.')) 326 normal 3G$ 327 call assert_equal([0, 3, 1, 0], getcharpos('.')) 328 normal 4G$ 329 call assert_equal([0, 4, 9, 0], getcharpos('.')) 330 331 " Test for a mark 332 normal 2G7lmmgg 333 call assert_equal([0, 2, 8, 0], getcharpos("'m")) 334 delmarks m 335 call assert_equal([0, 0, 0, 0], getcharpos("'m")) 336 337 " Check mark does not move 338 normal 5Gfxma 339 call assert_equal([0, 5, 5, 0], getcharpos("'a")) 340 call assert_equal([0, 5, 5, 0], getcharpos("'a")) 341 call assert_equal([0, 5, 5, 0], getcharpos("'a")) 342 343 " Test for the visual start column 344 vnoremap <expr> <F3> SaveVisualStartCharPos() 345 let g:VisualStartPos = [] 346 exe "normal 2G6lv$\<F3>ohh\<F3>o\<F3>" 347 call assert_equal([[0, 2, 7, 0], [0, 2, 10, 0], [0, 2, 5, 0]], g:VisualStartPos) 348 call assert_equal([0, 2, 9, 0], getcharpos('v')) 349 let g:VisualStartPos = [] 350 exe "normal 3Gv$\<F3>o\<F3>" 351 call assert_equal([[0, 3, 1, 0], [0, 3, 2, 0]], g:VisualStartPos) 352 let g:VisualStartPos = [] 353 exe "normal 1Gv$\<F3>o\<F3>" 354 call assert_equal([[0, 1, 1, 0], [0, 1, 1, 0]], g:VisualStartPos) 355 vunmap <F3> 356 357 " Test for getting the position in insert mode with the cursor after the 358 " last character in a line 359 inoremap <expr> <F3> SaveInsertCurrentCharPos() 360 let g:InsertCurrentPos = [] 361 exe "normal 1GA\<F3>" 362 exe "normal 2GA\<F3>" 363 exe "normal 3GA\<F3>" 364 exe "normal 4GA\<F3>" 365 exe "normal 2G6li\<F3>" 366 call assert_equal([[0, 1, 1, 0], [0, 2, 10, 0], [0, 3, 2, 0], [0, 4, 10, 0], 367 \ [0, 2, 7, 0]], g:InsertCurrentPos) 368 iunmap <F3> 369 370 %bw! 371 endfunc 372 373 " Test for the setcharpos() function 374 func Test_setcharpos() 375 call assert_equal(-1, setcharpos('.', v:_null_list)) 376 new 377 call setline(1, ['', "01\tà4è678", 'Ⅵ', '012345678']) 378 call setcharpos('.', [0, 1, 1, 0]) 379 call assert_equal([1, 1], [line('.'), col('.')]) 380 call setcharpos('.', [0, 2, 7, 0]) 381 call assert_equal([2, 9], [line('.'), col('.')]) 382 call setcharpos('.', [0, 3, 4, 0]) 383 call assert_equal([3, 1], [line('.'), col('.')]) 384 call setcharpos('.', [0, 3, 1, 0]) 385 call assert_equal([3, 1], [line('.'), col('.')]) 386 call setcharpos('.', [0, 4, 0, 0]) 387 call assert_equal([4, 1], [line('.'), col('.')]) 388 call setcharpos('.', [0, 4, 20, 0]) 389 call assert_equal([4, 9], [line('.'), col('.')]) 390 391 " Test for mark 392 delmarks m 393 call setcharpos("'m", [0, 2, 9, 0]) 394 normal `m 395 call assert_equal([2, 11], [line('.'), col('.')]) 396 " unload the buffer and try to set the mark 397 let bnr = bufnr() 398 enew! 399 call assert_equal(-1, setcharpos("'m", [bnr, 2, 2, 0])) 400 401 %bw! 402 call assert_equal(-1, setcharpos('.', [10, 3, 1, 0])) 403 endfunc 404 405 func SaveVisualStartCharCol() 406 call add(g:VisualStartCol, charcol('v')) 407 return '' 408 endfunc 409 410 func SaveInsertCurrentCharCol() 411 call add(g:InsertCurrentCol, charcol('.')) 412 return '' 413 endfunc 414 415 " Test for the charcol() function 416 func Test_charcol() 417 call assert_fails('call charcol({})', 'E1222:') 418 call assert_fails('call charcol(".", [])', 'E1210:') 419 call assert_fails('call charcol(0)', 'E1222:') 420 new 421 call setline(1, ['', "01\tà4è678", 'Ⅵ', '012345678']) 422 423 " Test for '.' and '$' 424 normal 1G 425 call assert_equal(1, charcol('.')) 426 call assert_equal(1, charcol('$')) 427 normal 2G6l 428 call assert_equal(7, charcol('.')) 429 call assert_equal(10, charcol('$')) 430 normal 3G$ 431 call assert_equal(1, charcol('.')) 432 call assert_equal(2, charcol('$')) 433 normal 4G$ 434 call assert_equal(9, charcol('.')) 435 call assert_equal(10, charcol('$')) 436 437 " Test for [lnum, '$'] 438 call assert_equal(1, charcol([1, '$'])) 439 call assert_equal(10, charcol([2, '$'])) 440 call assert_equal(2, charcol([3, '$'])) 441 call assert_equal(0, charcol([5, '$'])) 442 443 " Test for a mark 444 normal 2G7lmmgg 445 call assert_equal(8, charcol("'m")) 446 delmarks m 447 call assert_equal(0, charcol("'m")) 448 449 " Test for the visual start column 450 vnoremap <expr> <F3> SaveVisualStartCharCol() 451 let g:VisualStartCol = [] 452 exe "normal 2G6lv$\<F3>ohh\<F3>o\<F3>" 453 call assert_equal([7, 10, 5], g:VisualStartCol) 454 call assert_equal(9, charcol('v')) 455 let g:VisualStartCol = [] 456 exe "normal 3Gv$\<F3>o\<F3>" 457 call assert_equal([1, 2], g:VisualStartCol) 458 let g:VisualStartCol = [] 459 exe "normal 1Gv$\<F3>o\<F3>" 460 call assert_equal([1, 1], g:VisualStartCol) 461 vunmap <F3> 462 463 " Test for getting the column number in insert mode with the cursor after 464 " the last character in a line 465 inoremap <expr> <F3> SaveInsertCurrentCharCol() 466 let g:InsertCurrentCol = [] 467 exe "normal 1GA\<F3>" 468 exe "normal 2GA\<F3>" 469 exe "normal 3GA\<F3>" 470 exe "normal 4GA\<F3>" 471 exe "normal 2G6li\<F3>" 472 call assert_equal([1, 10, 2, 10, 7], g:InsertCurrentCol) 473 iunmap <F3> 474 475 " Test for getting the column number in another window. 476 let winid = win_getid() 477 new 478 call win_execute(winid, 'normal 1G') 479 call assert_equal(1, charcol('.', winid)) 480 call assert_equal(1, charcol('$', winid)) 481 call win_execute(winid, 'normal 2G6l') 482 call assert_equal(7, charcol('.', winid)) 483 call assert_equal(10, charcol('$', winid)) 484 485 " calling from another tab page also works 486 tabnew 487 call assert_equal(7, charcol('.', winid)) 488 call assert_equal(10, charcol('$', winid)) 489 tabclose 490 491 " unknown window ID 492 call assert_equal(0, charcol('.', 10001)) 493 494 %bw! 495 endfunc 496 497 func SaveInsertCursorCharPos() 498 call add(g:InsertCursorPos, getcursorcharpos('.')) 499 return '' 500 endfunc 501 502 " Test for getcursorcharpos() 503 func Test_getcursorcharpos() 504 call assert_equal(getcursorcharpos(), getcursorcharpos(0)) 505 call assert_equal([0, 0, 0, 0, 0], getcursorcharpos(-1)) 506 call assert_equal([0, 0, 0, 0, 0], getcursorcharpos(1999)) 507 508 new 509 call setline(1, ['', "01\tà4è678", 'Ⅵ', '012345678']) 510 normal 1G9l 511 call assert_equal([0, 1, 1, 0, 1], getcursorcharpos()) 512 normal 2G9l 513 call assert_equal([0, 2, 9, 0, 14], getcursorcharpos()) 514 normal 3G9l 515 call assert_equal([0, 3, 1, 0, 1], getcursorcharpos()) 516 normal 4G9l 517 call assert_equal([0, 4, 9, 0, 9], getcursorcharpos()) 518 519 " Test for getting the cursor position in insert mode with the cursor after 520 " the last character in a line 521 inoremap <expr> <F3> SaveInsertCursorCharPos() 522 let g:InsertCursorPos = [] 523 exe "normal 1GA\<F3>" 524 exe "normal 2GA\<F3>" 525 exe "normal 3GA\<F3>" 526 exe "normal 4GA\<F3>" 527 exe "normal 2G6li\<F3>" 528 call assert_equal([[0, 1, 1, 0, 1], [0, 2, 10, 0, 15], [0, 3, 2, 0, 2], 529 \ [0, 4, 10, 0, 10], [0, 2, 7, 0, 12]], g:InsertCursorPos) 530 iunmap <F3> 531 532 let winid = win_getid() 533 normal 2G5l 534 wincmd w 535 call assert_equal([0, 2, 6, 0, 11], getcursorcharpos(winid)) 536 %bw! 537 endfunc 538 539 " Test for setcursorcharpos() 540 func Test_setcursorcharpos() 541 call assert_fails('call setcursorcharpos(v:_null_list)', 'E474:') 542 call assert_fails('call setcursorcharpos([1])', 'E474:') 543 call assert_fails('call setcursorcharpos([1, 1, 1, 1, 1])', 'E474:') 544 new 545 call setline(1, ['', "01\tà4è678", 'Ⅵ', '012345678']) 546 normal G 547 call setcursorcharpos([1, 1]) 548 call assert_equal([1, 1], [line('.'), col('.')]) 549 550 call setcursorcharpos([2, 7, 0]) 551 call assert_equal([2, 9], [line('.'), col('.')]) 552 call setcursorcharpos([0, 7, 0]) 553 call assert_equal([2, 9], [line('.'), col('.')]) 554 call setcursorcharpos(0, 7, 0) 555 call assert_equal([2, 9], [line('.'), col('.')]) 556 557 call setcursorcharpos(3, 4) 558 call assert_equal([3, 1], [line('.'), col('.')]) 559 call setcursorcharpos([3, 1]) 560 call assert_equal([3, 1], [line('.'), col('.')]) 561 call setcursorcharpos([4, 0, 0, 0]) 562 call assert_equal([4, 1], [line('.'), col('.')]) 563 call setcursorcharpos([4, 20]) 564 call assert_equal([4, 9], [line('.'), col('.')]) 565 normal 1G 566 call setcursorcharpos([100, 100, 100, 100]) 567 call assert_equal([4, 9], [line('.'), col('.')]) 568 normal 1G 569 call setcursorcharpos('$', 1) 570 call assert_equal([4, 1], [line('.'), col('.')]) 571 572 %bw! 573 endfunc 574 575 " Test for virtcol2col() 576 func Test_virtcol2col() 577 new 578 call setline(1, ["a\tb\tc"]) 579 call assert_equal(1, virtcol2col(0, 1, 1)) 580 call assert_equal(2, virtcol2col(0, 1, 2)) 581 call assert_equal(2, virtcol2col(0, 1, 8)) 582 call assert_equal(3, virtcol2col(0, 1, 9)) 583 call assert_equal(4, virtcol2col(0, 1, 10)) 584 call assert_equal(4, virtcol2col(0, 1, 16)) 585 call assert_equal(5, virtcol2col(0, 1, 17)) 586 call assert_equal(-1, virtcol2col(10, 1, 1)) 587 call assert_equal(-1, virtcol2col(0, 10, 1)) 588 call assert_equal(-1, virtcol2col(0, -1, 1)) 589 call assert_equal(-1, virtcol2col(0, 1, -1)) 590 call assert_equal(5, virtcol2col(0, 1, 20)) 591 592 " Multibyte character 593 call setline(1, ['a✅✅✅']) 594 call assert_equal(1, virtcol2col(0, 1, 1)) 595 call assert_equal(2, virtcol2col(0, 1, 3)) 596 call assert_equal(5, virtcol2col(0, 1, 5)) 597 call assert_equal(8, virtcol2col(0, 1, 7)) 598 call assert_equal(8, virtcol2col(0, 1, 8)) 599 600 " These used to cause invalid memory access 601 call setline(1, '') 602 call assert_equal(0, virtcol2col(0, 1, 1)) 603 call assert_equal(0, virtcol2col(0, 1, 2)) 604 605 let w = winwidth(0) 606 call setline(2, repeat('a', w + 2)) 607 let win_nosbr = win_getid() 608 split 609 setlocal showbreak=!! 610 let win_sbr = win_getid() 611 call assert_equal(w, virtcol2col(win_nosbr, 2, w)) 612 call assert_equal(w + 1, virtcol2col(win_nosbr, 2, w + 1)) 613 call assert_equal(w + 2, virtcol2col(win_nosbr, 2, w + 2)) 614 call assert_equal(w + 2, virtcol2col(win_nosbr, 2, w + 3)) 615 call assert_equal(w, virtcol2col(win_sbr, 2, w)) 616 call assert_equal(w + 1, virtcol2col(win_sbr, 2, w + 1)) 617 call assert_equal(w + 1, virtcol2col(win_sbr, 2, w + 2)) 618 call assert_equal(w + 1, virtcol2col(win_sbr, 2, w + 3)) 619 call assert_equal(w + 2, virtcol2col(win_sbr, 2, w + 4)) 620 call assert_equal(w + 2, virtcol2col(win_sbr, 2, w + 5)) 621 close 622 623 call assert_fails('echo virtcol2col("0", 1, 20)', 'E1210:') 624 call assert_fails('echo virtcol2col(0, "1", 20)', 'E1210:') 625 call assert_fails('echo virtcol2col(0, 1, "1")', 'E1210:') 626 627 bw! 628 endfunc 629 630 " vim: shiftwidth=2 sts=2 expandtab