Bram Moolenaar | 6f02b00 | 2021-01-10 20:22:54 +0100 | [diff] [blame] | 1 | " Tests for cursor() and other functions that get/set the cursor position |
Bram Moolenaar | 5a46a58 | 2016-01-15 15:56:58 +0100 | [diff] [blame] | 2 | |
| 3 | func Test_wrong_arguments() |
Bram Moolenaar | 3717540 | 2017-03-18 20:18:45 +0100 | [diff] [blame] | 4 | call assert_fails('call cursor(1. 3)', 'E474:') |
Bram Moolenaar | 92b83cc | 2020-04-25 15:24:44 +0200 | [diff] [blame] | 5 | call assert_fails('call cursor(test_null_list())', 'E474:') |
Bram Moolenaar | 5a46a58 | 2016-01-15 15:56:58 +0100 | [diff] [blame] | 6 | endfunc |
| 7 | |
| 8 | func Test_move_cursor() |
| 9 | new |
| 10 | call setline(1, ['aaa', 'bbb', 'ccc', 'ddd']) |
| 11 | |
| 12 | call cursor([1, 1, 0, 1]) |
| 13 | call assert_equal([1, 1, 0, 1], getcurpos()[1:]) |
| 14 | call cursor([4, 3, 0, 3]) |
| 15 | call assert_equal([4, 3, 0, 3], getcurpos()[1:]) |
| 16 | |
| 17 | call cursor(2, 2) |
Bram Moolenaar | 2ab375e | 2016-02-10 22:23:06 +0100 | [diff] [blame] | 18 | call assert_equal([2, 2, 0, 2], getcurpos()[1:]) |
Bram Moolenaar | 5a46a58 | 2016-01-15 15:56:58 +0100 | [diff] [blame] | 19 | " line number zero keeps the line number |
| 20 | call cursor(0, 1) |
Bram Moolenaar | 2ab375e | 2016-02-10 22:23:06 +0100 | [diff] [blame] | 21 | call assert_equal([2, 1, 0, 1], getcurpos()[1:]) |
Bram Moolenaar | 5a46a58 | 2016-01-15 15:56:58 +0100 | [diff] [blame] | 22 | " col number zero keeps the column |
| 23 | call cursor(3, 0) |
Bram Moolenaar | 2ab375e | 2016-02-10 22:23:06 +0100 | [diff] [blame] | 24 | call assert_equal([3, 1, 0, 1], getcurpos()[1:]) |
Bram Moolenaar | 5a46a58 | 2016-01-15 15:56:58 +0100 | [diff] [blame] | 25 | " below last line goes to last line |
Bram Moolenaar | 1a3a891 | 2019-08-23 22:31:37 +0200 | [diff] [blame] | 26 | eval [9, 1]->cursor() |
Bram Moolenaar | 2ab375e | 2016-02-10 22:23:06 +0100 | [diff] [blame] | 27 | call assert_equal([4, 1, 0, 1], getcurpos()[1:]) |
Bram Moolenaar | 9ebcf23 | 2021-01-16 16:52:49 +0100 | [diff] [blame] | 28 | " pass string arguments |
| 29 | call cursor('3', '3') |
| 30 | call assert_equal([3, 3, 0, 3], getcurpos()[1:]) |
Bram Moolenaar | 5a46a58 | 2016-01-15 15:56:58 +0100 | [diff] [blame] | 31 | |
Bram Moolenaar | 17aca70 | 2019-05-16 22:24:55 +0200 | [diff] [blame] | 32 | call setline(1, ["\<TAB>"]) |
| 33 | call cursor(1, 1, 1) |
| 34 | call assert_equal([1, 1, 1], getcurpos()[1:3]) |
| 35 | |
Bram Moolenaar | 9a96337 | 2020-12-21 21:58:46 +0100 | [diff] [blame] | 36 | call assert_fails('call cursor(-1, -1)', 'E475:') |
Bram Moolenaar | 17aca70 | 2019-05-16 22:24:55 +0200 | [diff] [blame] | 37 | |
Bram Moolenaar | 5a46a58 | 2016-01-15 15:56:58 +0100 | [diff] [blame] | 38 | quit! |
| 39 | endfunc |
Bram Moolenaar | 2ab375e | 2016-02-10 22:23:06 +0100 | [diff] [blame] | 40 | |
| 41 | " Very short version of what matchparen does. |
| 42 | function s:Highlight_Matching_Pair() |
| 43 | let save_cursor = getcurpos() |
Bram Moolenaar | aad222c | 2019-09-06 22:46:09 +0200 | [diff] [blame] | 44 | eval save_cursor->setpos('.') |
Bram Moolenaar | 2ab375e | 2016-02-10 22:23:06 +0100 | [diff] [blame] | 45 | endfunc |
| 46 | |
| 47 | func Test_curswant_with_autocommand() |
| 48 | new |
| 49 | call setline(1, ['func()', '{', '}', '----']) |
| 50 | autocmd! CursorMovedI * call s:Highlight_Matching_Pair() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 51 | call test_override("char_avail", 1) |
Bram Moolenaar | 2ab375e | 2016-02-10 22:23:06 +0100 | [diff] [blame] | 52 | exe "normal! 3Ga\<Down>X\<Esc>" |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 53 | call test_override("char_avail", 0) |
Bram Moolenaar | 2ab375e | 2016-02-10 22:23:06 +0100 | [diff] [blame] | 54 | call assert_equal('-X---', getline(4)) |
| 55 | autocmd! CursorMovedI * |
| 56 | quit! |
| 57 | endfunc |
| 58 | |
Bram Moolenaar | 177ab9e | 2019-01-15 21:12:57 +0100 | [diff] [blame] | 59 | " Tests for behavior of curswant with cursorcolumn/line |
| 60 | func Test_curswant_with_cursorcolumn() |
| 61 | new |
| 62 | call setline(1, ['01234567', '']) |
| 63 | exe "normal! ggf6j" |
| 64 | call assert_equal(6, winsaveview().curswant) |
| 65 | set cursorcolumn |
| 66 | call assert_equal(6, winsaveview().curswant) |
| 67 | quit! |
| 68 | endfunc |
| 69 | |
| 70 | func Test_curswant_with_cursorline() |
| 71 | new |
| 72 | call setline(1, ['01234567', '']) |
| 73 | exe "normal! ggf6j" |
| 74 | call assert_equal(6, winsaveview().curswant) |
| 75 | set cursorline |
| 76 | call assert_equal(6, winsaveview().curswant) |
| 77 | quit! |
| 78 | endfunc |
Bram Moolenaar | b3d17a2 | 2019-07-07 18:28:14 +0200 | [diff] [blame] | 79 | |
| 80 | func Test_screenpos() |
| 81 | rightbelow new |
| 82 | rightbelow 20vsplit |
| 83 | call setline(1, ["\tsome text", "long wrapping line here", "next line"]) |
| 84 | redraw |
| 85 | let winid = win_getid() |
| 86 | let [winrow, wincol] = win_screenpos(winid) |
| 87 | call assert_equal({'row': winrow, |
| 88 | \ 'col': wincol + 0, |
| 89 | \ 'curscol': wincol + 7, |
Bram Moolenaar | f92e58c | 2019-09-08 21:51:41 +0200 | [diff] [blame] | 90 | \ 'endcol': wincol + 7}, winid->screenpos(1, 1)) |
Bram Moolenaar | b3d17a2 | 2019-07-07 18:28:14 +0200 | [diff] [blame] | 91 | call assert_equal({'row': winrow, |
| 92 | \ 'col': wincol + 13, |
| 93 | \ 'curscol': wincol + 13, |
Bram Moolenaar | 196b466 | 2019-09-06 21:34:30 +0200 | [diff] [blame] | 94 | \ 'endcol': wincol + 13}, winid->screenpos(1, 7)) |
Bram Moolenaar | b3d17a2 | 2019-07-07 18:28:14 +0200 | [diff] [blame] | 95 | call assert_equal({'row': winrow + 2, |
| 96 | \ 'col': wincol + 1, |
| 97 | \ 'curscol': wincol + 1, |
| 98 | \ 'endcol': wincol + 1}, screenpos(winid, 2, 22)) |
| 99 | setlocal number |
| 100 | call assert_equal({'row': winrow + 3, |
| 101 | \ 'col': wincol + 9, |
| 102 | \ 'curscol': wincol + 9, |
| 103 | \ 'endcol': wincol + 9}, screenpos(winid, 2, 22)) |
Bram Moolenaar | 189663b | 2021-07-21 18:04:56 +0200 | [diff] [blame^] | 104 | |
| 105 | let wininfo = getwininfo(winid)[0] |
| 106 | call setline(3, ['x']->repeat(wininfo.height)) |
| 107 | call setline(line('$') + 1, 'x'->repeat(wininfo.width * 3)) |
| 108 | setlocal nonumber display=lastline so=0 |
| 109 | exe "normal G\<C-Y>\<C-Y>" |
| 110 | redraw |
| 111 | call assert_equal({'row': winrow + wininfo.height - 1, |
| 112 | \ 'col': wincol + 7, |
| 113 | \ 'curscol': wincol + 7, |
| 114 | \ 'endcol': wincol + 7}, winid->screenpos(line('$'), 8)) |
| 115 | call assert_equal({'row': winrow - 1, 'col': 0, 'curscol': 0, 'endcol': 0}, |
| 116 | \ winid->screenpos(line('$'), 22)) |
| 117 | |
Bram Moolenaar | b3d17a2 | 2019-07-07 18:28:14 +0200 | [diff] [blame] | 118 | close |
Bram Moolenaar | bdd2c29 | 2020-06-22 21:34:30 +0200 | [diff] [blame] | 119 | call assert_equal({}, screenpos(999, 1, 1)) |
Bram Moolenaar | 189663b | 2021-07-21 18:04:56 +0200 | [diff] [blame^] | 120 | |
Bram Moolenaar | b3d17a2 | 2019-07-07 18:28:14 +0200 | [diff] [blame] | 121 | bwipe! |
Bram Moolenaar | 189663b | 2021-07-21 18:04:56 +0200 | [diff] [blame^] | 122 | set display& |
Bram Moolenaar | 8dd46e7 | 2020-12-17 21:35:29 +0100 | [diff] [blame] | 123 | |
| 124 | call assert_equal({'col': 1, 'row': 1, 'endcol': 1, 'curscol': 1}, screenpos(win_getid(), 1, 1)) |
| 125 | nmenu WinBar.TEST : |
| 126 | call assert_equal({'col': 1, 'row': 2, 'endcol': 1, 'curscol': 1}, screenpos(win_getid(), 1, 1)) |
| 127 | nunmenu WinBar.TEST |
Bram Moolenaar | b3d17a2 | 2019-07-07 18:28:14 +0200 | [diff] [blame] | 128 | endfunc |
Bram Moolenaar | 38ba4dc | 2019-10-27 21:39:09 +0100 | [diff] [blame] | 129 | |
| 130 | func Test_screenpos_number() |
| 131 | rightbelow new |
| 132 | rightbelow 73vsplit |
| 133 | call setline (1, repeat('x', 66)) |
| 134 | setlocal number |
| 135 | redraw |
| 136 | let winid = win_getid() |
| 137 | let [winrow, wincol] = win_screenpos(winid) |
| 138 | let pos = screenpos(winid, 1, 66) |
| 139 | call assert_equal(winrow, pos.row) |
| 140 | call assert_equal(wincol + 66 + 3, pos.col) |
| 141 | close |
| 142 | bwipe! |
| 143 | endfunc |
Bram Moolenaar | 08f4157 | 2020-04-20 16:50:00 +0200 | [diff] [blame] | 144 | |
Bram Moolenaar | 9145846 | 2021-01-13 20:08:38 +0100 | [diff] [blame] | 145 | " Save the visual start character position |
Bram Moolenaar | 6f02b00 | 2021-01-10 20:22:54 +0100 | [diff] [blame] | 146 | func SaveVisualStartCharPos() |
| 147 | call add(g:VisualStartPos, getcharpos('v')) |
| 148 | return '' |
| 149 | endfunc |
| 150 | |
Bram Moolenaar | 9145846 | 2021-01-13 20:08:38 +0100 | [diff] [blame] | 151 | " Save the current cursor character position in insert mode |
| 152 | func SaveInsertCurrentCharPos() |
| 153 | call add(g:InsertCurrentPos, getcharpos('.')) |
| 154 | return '' |
| 155 | endfunc |
| 156 | |
Bram Moolenaar | 6f02b00 | 2021-01-10 20:22:54 +0100 | [diff] [blame] | 157 | " Test for the getcharpos() function |
| 158 | func Test_getcharpos() |
| 159 | call assert_fails('call getcharpos({})', 'E731:') |
| 160 | call assert_equal([0, 0, 0, 0], getcharpos(0)) |
| 161 | new |
| 162 | call setline(1, ['', "01\tà4è678", 'Ⅵ', '012345678']) |
| 163 | |
| 164 | " Test for '.' and '$' |
| 165 | normal 1G |
| 166 | call assert_equal([0, 1, 1, 0], getcharpos('.')) |
| 167 | call assert_equal([0, 4, 1, 0], getcharpos('$')) |
| 168 | normal 2G6l |
| 169 | call assert_equal([0, 2, 7, 0], getcharpos('.')) |
| 170 | normal 3G$ |
| 171 | call assert_equal([0, 3, 1, 0], getcharpos('.')) |
| 172 | normal 4G$ |
| 173 | call assert_equal([0, 4, 9, 0], getcharpos('.')) |
| 174 | |
| 175 | " Test for a mark |
| 176 | normal 2G7lmmgg |
| 177 | call assert_equal([0, 2, 8, 0], getcharpos("'m")) |
| 178 | delmarks m |
| 179 | call assert_equal([0, 0, 0, 0], getcharpos("'m")) |
| 180 | |
| 181 | " Test for the visual start column |
| 182 | vnoremap <expr> <F3> SaveVisualStartCharPos() |
| 183 | let g:VisualStartPos = [] |
| 184 | exe "normal 2G6lv$\<F3>ohh\<F3>o\<F3>" |
Bram Moolenaar | 9145846 | 2021-01-13 20:08:38 +0100 | [diff] [blame] | 185 | call assert_equal([[0, 2, 7, 0], [0, 2, 10, 0], [0, 2, 5, 0]], g:VisualStartPos) |
Bram Moolenaar | 6f02b00 | 2021-01-10 20:22:54 +0100 | [diff] [blame] | 186 | call assert_equal([0, 2, 9, 0], getcharpos('v')) |
| 187 | let g:VisualStartPos = [] |
| 188 | exe "normal 3Gv$\<F3>o\<F3>" |
Bram Moolenaar | 9145846 | 2021-01-13 20:08:38 +0100 | [diff] [blame] | 189 | call assert_equal([[0, 3, 1, 0], [0, 3, 2, 0]], g:VisualStartPos) |
Bram Moolenaar | 6f02b00 | 2021-01-10 20:22:54 +0100 | [diff] [blame] | 190 | let g:VisualStartPos = [] |
| 191 | exe "normal 1Gv$\<F3>o\<F3>" |
| 192 | call assert_equal([[0, 1, 1, 0], [0, 1, 1, 0]], g:VisualStartPos) |
| 193 | vunmap <F3> |
| 194 | |
Bram Moolenaar | 9145846 | 2021-01-13 20:08:38 +0100 | [diff] [blame] | 195 | " Test for getting the position in insert mode with the cursor after the |
| 196 | " last character in a line |
| 197 | inoremap <expr> <F3> SaveInsertCurrentCharPos() |
| 198 | let g:InsertCurrentPos = [] |
| 199 | exe "normal 1GA\<F3>" |
| 200 | exe "normal 2GA\<F3>" |
| 201 | exe "normal 3GA\<F3>" |
| 202 | exe "normal 4GA\<F3>" |
| 203 | exe "normal 2G6li\<F3>" |
| 204 | call assert_equal([[0, 1, 1, 0], [0, 2, 10, 0], [0, 3, 2, 0], [0, 4, 10, 0], |
| 205 | \ [0, 2, 7, 0]], g:InsertCurrentPos) |
| 206 | iunmap <F3> |
| 207 | |
Bram Moolenaar | 6f02b00 | 2021-01-10 20:22:54 +0100 | [diff] [blame] | 208 | %bw! |
| 209 | endfunc |
| 210 | |
| 211 | " Test for the setcharpos() function |
| 212 | func Test_setcharpos() |
| 213 | call assert_equal(-1, setcharpos('.', test_null_list())) |
| 214 | new |
| 215 | call setline(1, ['', "01\tà4è678", 'Ⅵ', '012345678']) |
| 216 | call setcharpos('.', [0, 1, 1, 0]) |
| 217 | call assert_equal([1, 1], [line('.'), col('.')]) |
| 218 | call setcharpos('.', [0, 2, 7, 0]) |
| 219 | call assert_equal([2, 9], [line('.'), col('.')]) |
| 220 | call setcharpos('.', [0, 3, 4, 0]) |
| 221 | call assert_equal([3, 1], [line('.'), col('.')]) |
| 222 | call setcharpos('.', [0, 3, 1, 0]) |
| 223 | call assert_equal([3, 1], [line('.'), col('.')]) |
| 224 | call setcharpos('.', [0, 4, 0, 0]) |
| 225 | call assert_equal([4, 1], [line('.'), col('.')]) |
| 226 | call setcharpos('.', [0, 4, 20, 0]) |
| 227 | call assert_equal([4, 9], [line('.'), col('.')]) |
| 228 | |
| 229 | " Test for mark |
| 230 | delmarks m |
| 231 | call setcharpos("'m", [0, 2, 9, 0]) |
| 232 | normal `m |
| 233 | call assert_equal([2, 11], [line('.'), col('.')]) |
Bram Moolenaar | 9145846 | 2021-01-13 20:08:38 +0100 | [diff] [blame] | 234 | " unload the buffer and try to set the mark |
| 235 | let bnr = bufnr() |
| 236 | enew! |
| 237 | call assert_equal(-1, setcharpos("'m", [bnr, 2, 2, 0])) |
Bram Moolenaar | 6f02b00 | 2021-01-10 20:22:54 +0100 | [diff] [blame] | 238 | |
| 239 | %bw! |
| 240 | call assert_equal(-1, setcharpos('.', [10, 3, 1, 0])) |
| 241 | endfunc |
| 242 | |
| 243 | func SaveVisualStartCharCol() |
| 244 | call add(g:VisualStartCol, charcol('v')) |
| 245 | return '' |
| 246 | endfunc |
| 247 | |
Bram Moolenaar | 9145846 | 2021-01-13 20:08:38 +0100 | [diff] [blame] | 248 | func SaveInsertCurrentCharCol() |
| 249 | call add(g:InsertCurrentCol, charcol('.')) |
| 250 | return '' |
| 251 | endfunc |
| 252 | |
Bram Moolenaar | 6f02b00 | 2021-01-10 20:22:54 +0100 | [diff] [blame] | 253 | " Test for the charcol() function |
| 254 | func Test_charcol() |
| 255 | call assert_fails('call charcol({})', 'E731:') |
| 256 | call assert_equal(0, charcol(0)) |
| 257 | new |
| 258 | call setline(1, ['', "01\tà4è678", 'Ⅵ', '012345678']) |
| 259 | |
| 260 | " Test for '.' and '$' |
| 261 | normal 1G |
| 262 | call assert_equal(1, charcol('.')) |
| 263 | call assert_equal(1, charcol('$')) |
| 264 | normal 2G6l |
| 265 | call assert_equal(7, charcol('.')) |
| 266 | call assert_equal(10, charcol('$')) |
| 267 | normal 3G$ |
| 268 | call assert_equal(1, charcol('.')) |
| 269 | call assert_equal(2, charcol('$')) |
| 270 | normal 4G$ |
| 271 | call assert_equal(9, charcol('.')) |
| 272 | call assert_equal(10, charcol('$')) |
| 273 | |
| 274 | " Test for [lnum, '$'] |
| 275 | call assert_equal(1, charcol([1, '$'])) |
| 276 | call assert_equal(10, charcol([2, '$'])) |
| 277 | call assert_equal(2, charcol([3, '$'])) |
| 278 | call assert_equal(0, charcol([5, '$'])) |
| 279 | |
| 280 | " Test for a mark |
| 281 | normal 2G7lmmgg |
| 282 | call assert_equal(8, charcol("'m")) |
| 283 | delmarks m |
| 284 | call assert_equal(0, charcol("'m")) |
| 285 | |
| 286 | " Test for the visual start column |
| 287 | vnoremap <expr> <F3> SaveVisualStartCharCol() |
| 288 | let g:VisualStartCol = [] |
| 289 | exe "normal 2G6lv$\<F3>ohh\<F3>o\<F3>" |
Bram Moolenaar | 9145846 | 2021-01-13 20:08:38 +0100 | [diff] [blame] | 290 | call assert_equal([7, 10, 5], g:VisualStartCol) |
Bram Moolenaar | 6f02b00 | 2021-01-10 20:22:54 +0100 | [diff] [blame] | 291 | call assert_equal(9, charcol('v')) |
| 292 | let g:VisualStartCol = [] |
| 293 | exe "normal 3Gv$\<F3>o\<F3>" |
Bram Moolenaar | 9145846 | 2021-01-13 20:08:38 +0100 | [diff] [blame] | 294 | call assert_equal([1, 2], g:VisualStartCol) |
Bram Moolenaar | 6f02b00 | 2021-01-10 20:22:54 +0100 | [diff] [blame] | 295 | let g:VisualStartCol = [] |
| 296 | exe "normal 1Gv$\<F3>o\<F3>" |
| 297 | call assert_equal([1, 1], g:VisualStartCol) |
| 298 | vunmap <F3> |
| 299 | |
Bram Moolenaar | 9145846 | 2021-01-13 20:08:38 +0100 | [diff] [blame] | 300 | " Test for getting the column number in insert mode with the cursor after |
| 301 | " the last character in a line |
| 302 | inoremap <expr> <F3> SaveInsertCurrentCharCol() |
| 303 | let g:InsertCurrentCol = [] |
| 304 | exe "normal 1GA\<F3>" |
| 305 | exe "normal 2GA\<F3>" |
| 306 | exe "normal 3GA\<F3>" |
| 307 | exe "normal 4GA\<F3>" |
| 308 | exe "normal 2G6li\<F3>" |
| 309 | call assert_equal([1, 10, 2, 10, 7], g:InsertCurrentCol) |
| 310 | iunmap <F3> |
| 311 | |
Bram Moolenaar | 6f02b00 | 2021-01-10 20:22:54 +0100 | [diff] [blame] | 312 | %bw! |
| 313 | endfunc |
| 314 | |
Bram Moolenaar | 9145846 | 2021-01-13 20:08:38 +0100 | [diff] [blame] | 315 | func SaveInsertCursorCharPos() |
| 316 | call add(g:InsertCursorPos, getcursorcharpos('.')) |
| 317 | return '' |
| 318 | endfunc |
| 319 | |
Bram Moolenaar | 6f02b00 | 2021-01-10 20:22:54 +0100 | [diff] [blame] | 320 | " Test for getcursorcharpos() |
| 321 | func Test_getcursorcharpos() |
| 322 | call assert_equal(getcursorcharpos(), getcursorcharpos(0)) |
| 323 | call assert_equal([0, 0, 0, 0, 0], getcursorcharpos(-1)) |
| 324 | call assert_equal([0, 0, 0, 0, 0], getcursorcharpos(1999)) |
| 325 | |
| 326 | new |
| 327 | call setline(1, ['', "01\tà4è678", 'Ⅵ', '012345678']) |
| 328 | normal 1G9l |
| 329 | call assert_equal([0, 1, 1, 0, 1], getcursorcharpos()) |
| 330 | normal 2G9l |
| 331 | call assert_equal([0, 2, 9, 0, 14], getcursorcharpos()) |
| 332 | normal 3G9l |
| 333 | call assert_equal([0, 3, 1, 0, 1], getcursorcharpos()) |
| 334 | normal 4G9l |
| 335 | call assert_equal([0, 4, 9, 0, 9], getcursorcharpos()) |
| 336 | |
Bram Moolenaar | 9145846 | 2021-01-13 20:08:38 +0100 | [diff] [blame] | 337 | " Test for getting the cursor position in insert mode with the cursor after |
| 338 | " the last character in a line |
| 339 | inoremap <expr> <F3> SaveInsertCursorCharPos() |
| 340 | let g:InsertCursorPos = [] |
| 341 | exe "normal 1GA\<F3>" |
| 342 | exe "normal 2GA\<F3>" |
| 343 | exe "normal 3GA\<F3>" |
| 344 | exe "normal 4GA\<F3>" |
| 345 | exe "normal 2G6li\<F3>" |
| 346 | call assert_equal([[0, 1, 1, 0, 1], [0, 2, 10, 0, 15], [0, 3, 2, 0, 2], |
| 347 | \ [0, 4, 10, 0, 10], [0, 2, 7, 0, 12]], g:InsertCursorPos) |
| 348 | iunmap <F3> |
| 349 | |
Bram Moolenaar | 6f02b00 | 2021-01-10 20:22:54 +0100 | [diff] [blame] | 350 | let winid = win_getid() |
| 351 | normal 2G5l |
| 352 | wincmd w |
| 353 | call assert_equal([0, 2, 6, 0, 11], getcursorcharpos(winid)) |
| 354 | %bw! |
| 355 | endfunc |
| 356 | |
| 357 | " Test for setcursorcharpos() |
| 358 | func Test_setcursorcharpos() |
| 359 | call assert_fails('call setcursorcharpos(test_null_list())', 'E474:') |
| 360 | call assert_fails('call setcursorcharpos([1])', 'E474:') |
| 361 | call assert_fails('call setcursorcharpos([1, 1, 1, 1, 1])', 'E474:') |
| 362 | new |
| 363 | call setline(1, ['', "01\tà4è678", 'Ⅵ', '012345678']) |
| 364 | normal G |
| 365 | call setcursorcharpos([1, 1]) |
| 366 | call assert_equal([1, 1], [line('.'), col('.')]) |
| 367 | call setcursorcharpos([2, 7, 0]) |
| 368 | call assert_equal([2, 9], [line('.'), col('.')]) |
| 369 | call setcursorcharpos(3, 4) |
| 370 | call assert_equal([3, 1], [line('.'), col('.')]) |
| 371 | call setcursorcharpos([3, 1]) |
| 372 | call assert_equal([3, 1], [line('.'), col('.')]) |
| 373 | call setcursorcharpos([4, 0, 0, 0]) |
| 374 | call assert_equal([4, 1], [line('.'), col('.')]) |
| 375 | call setcursorcharpos([4, 20]) |
| 376 | call assert_equal([4, 9], [line('.'), col('.')]) |
| 377 | normal 1G |
| 378 | call setcursorcharpos([100, 100, 100, 100]) |
| 379 | call assert_equal([4, 9], [line('.'), col('.')]) |
| 380 | normal 1G |
| 381 | call setcursorcharpos('$', 1) |
| 382 | call assert_equal([4, 1], [line('.'), col('.')]) |
| 383 | |
| 384 | %bw! |
| 385 | endfunc |
| 386 | |
Bram Moolenaar | 08f4157 | 2020-04-20 16:50:00 +0200 | [diff] [blame] | 387 | " vim: shiftwidth=2 sts=2 expandtab |