1" Tests for cursor(). 2 3func Test_wrong_arguments() 4 call assert_fails('call cursor(1. 3)', 'E474:') 5endfunc 6 7func Test_move_cursor() 8 new 9 call setline(1, ['aaa', 'bbb', 'ccc', 'ddd']) 10 11 call cursor([1, 1, 0, 1]) 12 call assert_equal([1, 1, 0, 1], getcurpos()[1:]) 13 call cursor([4, 3, 0, 3]) 14 call assert_equal([4, 3, 0, 3], getcurpos()[1:]) 15 16 call cursor(2, 2) 17 call assert_equal([2, 2, 0, 2], getcurpos()[1:]) 18 " line number zero keeps the line number 19 call cursor(0, 1) 20 call assert_equal([2, 1, 0, 1], getcurpos()[1:]) 21 " col number zero keeps the column 22 call cursor(3, 0) 23 call assert_equal([3, 1, 0, 1], getcurpos()[1:]) 24 " below last line goes to last line 25 eval [9, 1]->cursor() 26 call assert_equal([4, 1, 0, 1], getcurpos()[1:]) 27 28 call setline(1, ["\<TAB>"]) 29 call cursor(1, 1, 1) 30 call assert_equal([1, 1, 1], getcurpos()[1:3]) 31 32 call assert_equal(-1, cursor(-1, -1)) 33 34 quit! 35endfunc 36 37" Very short version of what matchparen does. 38function s:Highlight_Matching_Pair() 39 let save_cursor = getcurpos() 40 eval save_cursor->setpos('.') 41endfunc 42 43func Test_curswant_with_autocommand() 44 new 45 call setline(1, ['func()', '{', '}', '----']) 46 autocmd! CursorMovedI * call s:Highlight_Matching_Pair() 47 call test_override("char_avail", 1) 48 exe "normal! 3Ga\<Down>X\<Esc>" 49 call test_override("char_avail", 0) 50 call assert_equal('-X---', getline(4)) 51 autocmd! CursorMovedI * 52 quit! 53endfunc 54 55" Tests for behavior of curswant with cursorcolumn/line 56func Test_curswant_with_cursorcolumn() 57 new 58 call setline(1, ['01234567', '']) 59 exe "normal! ggf6j" 60 call assert_equal(6, winsaveview().curswant) 61 set cursorcolumn 62 call assert_equal(6, winsaveview().curswant) 63 quit! 64endfunc 65 66func Test_curswant_with_cursorline() 67 new 68 call setline(1, ['01234567', '']) 69 exe "normal! ggf6j" 70 call assert_equal(6, winsaveview().curswant) 71 set cursorline 72 call assert_equal(6, winsaveview().curswant) 73 quit! 74endfunc 75 76func Test_screenpos() 77 rightbelow new 78 rightbelow 20vsplit 79 call setline(1, ["\tsome text", "long wrapping line here", "next line"]) 80 redraw 81 let winid = win_getid() 82 let [winrow, wincol] = win_screenpos(winid) 83 call assert_equal({'row': winrow, 84 \ 'col': wincol + 0, 85 \ 'curscol': wincol + 7, 86 \ 'endcol': wincol + 7}, winid->screenpos(1, 1)) 87 call assert_equal({'row': winrow, 88 \ 'col': wincol + 13, 89 \ 'curscol': wincol + 13, 90 \ 'endcol': wincol + 13}, winid->screenpos(1, 7)) 91 call assert_equal({'row': winrow + 2, 92 \ 'col': wincol + 1, 93 \ 'curscol': wincol + 1, 94 \ 'endcol': wincol + 1}, screenpos(winid, 2, 22)) 95 setlocal number 96 call assert_equal({'row': winrow + 3, 97 \ 'col': wincol + 9, 98 \ 'curscol': wincol + 9, 99 \ 'endcol': wincol + 9}, screenpos(winid, 2, 22)) 100 close 101 bwipe! 102endfunc 103