blob: 8bdc956e269842a63aaf92dbc16dc2a117f622a9 [file] [log] [blame]
Bram Moolenaar6f02b002021-01-10 20:22:54 +01001" Tests for cursor() and other functions that get/set the cursor position
Bram Moolenaar5a46a582016-01-15 15:56:58 +01002
Bram Moolenaar4556a2e2022-02-15 13:40:17 +00003source check.vim
4
Bram Moolenaar5a46a582016-01-15 15:56:58 +01005func Test_wrong_arguments()
Bram Moolenaar37175402017-03-18 20:18:45 +01006 call assert_fails('call cursor(1. 3)', 'E474:')
Bram Moolenaar92b83cc2020-04-25 15:24:44 +02007 call assert_fails('call cursor(test_null_list())', 'E474:')
Bram Moolenaar5a46a582016-01-15 15:56:58 +01008endfunc
9
10func 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)
Bram Moolenaar2ab375e2016-02-10 22:23:06 +010020 call assert_equal([2, 2, 0, 2], getcurpos()[1:])
Bram Moolenaar5a46a582016-01-15 15:56:58 +010021 " line number zero keeps the line number
22 call cursor(0, 1)
Bram Moolenaar2ab375e2016-02-10 22:23:06 +010023 call assert_equal([2, 1, 0, 1], getcurpos()[1:])
Bram Moolenaar5a46a582016-01-15 15:56:58 +010024 " col number zero keeps the column
25 call cursor(3, 0)
Bram Moolenaar2ab375e2016-02-10 22:23:06 +010026 call assert_equal([3, 1, 0, 1], getcurpos()[1:])
Bram Moolenaar5a46a582016-01-15 15:56:58 +010027 " below last line goes to last line
Bram Moolenaar1a3a8912019-08-23 22:31:37 +020028 eval [9, 1]->cursor()
Bram Moolenaar2ab375e2016-02-10 22:23:06 +010029 call assert_equal([4, 1, 0, 1], getcurpos()[1:])
Bram Moolenaar9ebcf232021-01-16 16:52:49 +010030 " pass string arguments
31 call cursor('3', '3')
32 call assert_equal([3, 3, 0, 3], getcurpos()[1:])
Bram Moolenaar5a46a582016-01-15 15:56:58 +010033
Bram Moolenaar17aca702019-05-16 22:24:55 +020034 call setline(1, ["\<TAB>"])
35 call cursor(1, 1, 1)
36 call assert_equal([1, 1, 1], getcurpos()[1:3])
37
Bram Moolenaar9a963372020-12-21 21:58:46 +010038 call assert_fails('call cursor(-1, -1)', 'E475:')
Bram Moolenaar17aca702019-05-16 22:24:55 +020039
Bram Moolenaar5a46a582016-01-15 15:56:58 +010040 quit!
41endfunc
Bram Moolenaar2ab375e2016-02-10 22:23:06 +010042
naohiro ono56200ee2022-01-01 14:59:44 +000043func 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!
53endfunc
54
Bram Moolenaar2ab375e2016-02-10 22:23:06 +010055" Very short version of what matchparen does.
56function s:Highlight_Matching_Pair()
57 let save_cursor = getcurpos()
Bram Moolenaaraad222c2019-09-06 22:46:09 +020058 eval save_cursor->setpos('.')
Bram Moolenaar2ab375e2016-02-10 22:23:06 +010059endfunc
60
61func Test_curswant_with_autocommand()
62 new
63 call setline(1, ['func()', '{', '}', '----'])
64 autocmd! CursorMovedI * call s:Highlight_Matching_Pair()
Bram Moolenaareb992cb2017-03-09 18:20:16 +010065 call test_override("char_avail", 1)
Bram Moolenaar2ab375e2016-02-10 22:23:06 +010066 exe "normal! 3Ga\<Down>X\<Esc>"
Bram Moolenaareb992cb2017-03-09 18:20:16 +010067 call test_override("char_avail", 0)
Bram Moolenaar2ab375e2016-02-10 22:23:06 +010068 call assert_equal('-X---', getline(4))
69 autocmd! CursorMovedI *
70 quit!
71endfunc
72
Bram Moolenaar177ab9e2019-01-15 21:12:57 +010073" Tests for behavior of curswant with cursorcolumn/line
74func Test_curswant_with_cursorcolumn()
75 new
76 call setline(1, ['01234567', ''])
77 exe "normal! ggf6j"
78 call assert_equal(6, winsaveview().curswant)
79 set cursorcolumn
80 call assert_equal(6, winsaveview().curswant)
81 quit!
82endfunc
83
84func Test_curswant_with_cursorline()
85 new
86 call setline(1, ['01234567', ''])
87 exe "normal! ggf6j"
88 call assert_equal(6, winsaveview().curswant)
89 set cursorline
90 call assert_equal(6, winsaveview().curswant)
91 quit!
92endfunc
Bram Moolenaarb3d17a22019-07-07 18:28:14 +020093
94func Test_screenpos()
95 rightbelow new
96 rightbelow 20vsplit
97 call setline(1, ["\tsome text", "long wrapping line here", "next line"])
98 redraw
99 let winid = win_getid()
100 let [winrow, wincol] = win_screenpos(winid)
101 call assert_equal({'row': winrow,
102 \ 'col': wincol + 0,
103 \ 'curscol': wincol + 7,
Bram Moolenaarf92e58c2019-09-08 21:51:41 +0200104 \ 'endcol': wincol + 7}, winid->screenpos(1, 1))
Bram Moolenaarb3d17a22019-07-07 18:28:14 +0200105 call assert_equal({'row': winrow,
106 \ 'col': wincol + 13,
107 \ 'curscol': wincol + 13,
Bram Moolenaar196b4662019-09-06 21:34:30 +0200108 \ 'endcol': wincol + 13}, winid->screenpos(1, 7))
Bram Moolenaarb3d17a22019-07-07 18:28:14 +0200109 call assert_equal({'row': winrow + 2,
110 \ 'col': wincol + 1,
111 \ 'curscol': wincol + 1,
112 \ 'endcol': wincol + 1}, screenpos(winid, 2, 22))
113 setlocal number
114 call assert_equal({'row': winrow + 3,
115 \ 'col': wincol + 9,
116 \ 'curscol': wincol + 9,
117 \ 'endcol': wincol + 9}, screenpos(winid, 2, 22))
Bram Moolenaar189663b2021-07-21 18:04:56 +0200118
119 let wininfo = getwininfo(winid)[0]
120 call setline(3, ['x']->repeat(wininfo.height))
121 call setline(line('$') + 1, 'x'->repeat(wininfo.width * 3))
122 setlocal nonumber display=lastline so=0
123 exe "normal G\<C-Y>\<C-Y>"
124 redraw
125 call assert_equal({'row': winrow + wininfo.height - 1,
126 \ 'col': wincol + 7,
127 \ 'curscol': wincol + 7,
128 \ 'endcol': wincol + 7}, winid->screenpos(line('$'), 8))
Bram Moolenaar7924a172022-01-24 16:15:15 +0000129 call assert_equal({'row': 0, 'col': 0, 'curscol': 0, 'endcol': 0},
Bram Moolenaar189663b2021-07-21 18:04:56 +0200130 \ winid->screenpos(line('$'), 22))
131
Bram Moolenaarb3d17a22019-07-07 18:28:14 +0200132 close
Bram Moolenaarbdd2c292020-06-22 21:34:30 +0200133 call assert_equal({}, screenpos(999, 1, 1))
Bram Moolenaar189663b2021-07-21 18:04:56 +0200134
Bram Moolenaarb3d17a22019-07-07 18:28:14 +0200135 bwipe!
Bram Moolenaar189663b2021-07-21 18:04:56 +0200136 set display&
Bram Moolenaar8dd46e72020-12-17 21:35:29 +0100137
Bram Moolenaar4556a2e2022-02-15 13:40:17 +0000138 call assert_equal(#{col: 1, row: 1, endcol: 1, curscol: 1}, screenpos(win_getid(), 1, 1))
Bram Moolenaar8dd46e72020-12-17 21:35:29 +0100139 nmenu WinBar.TEST :
Bram Moolenaar4556a2e2022-02-15 13:40:17 +0000140 call assert_equal(#{col: 1, row: 2, endcol: 1, curscol: 1}, screenpos(win_getid(), 1, 1))
Bram Moolenaar8dd46e72020-12-17 21:35:29 +0100141 nunmenu WinBar.TEST
Bram Moolenaarb3d17a22019-07-07 18:28:14 +0200142endfunc
Bram Moolenaar38ba4dc2019-10-27 21:39:09 +0100143
Bram Moolenaar4556a2e2022-02-15 13:40:17 +0000144func Test_screenpos_fold()
145 CheckFeature folding
146
147 enew!
148 call setline(1, range(10))
149 3,5fold
150 redraw
151 call assert_equal(2, screenpos(1, 2, 1).row)
152 call assert_equal(#{col: 1, row: 3, endcol: 1, curscol: 1}, screenpos(1, 3, 1))
153 call assert_equal(3, screenpos(1, 4, 1).row)
154 call assert_equal(3, screenpos(1, 5, 1).row)
155 call assert_equal(4, screenpos(1, 6, 1).row)
156 bwipe!
157endfunc
158
Bram Moolenaar38ba4dc2019-10-27 21:39:09 +0100159func Test_screenpos_number()
160 rightbelow new
161 rightbelow 73vsplit
162 call setline (1, repeat('x', 66))
163 setlocal number
164 redraw
165 let winid = win_getid()
166 let [winrow, wincol] = win_screenpos(winid)
167 let pos = screenpos(winid, 1, 66)
168 call assert_equal(winrow, pos.row)
169 call assert_equal(wincol + 66 + 3, pos.col)
Bram Moolenaar99d19432022-12-05 16:23:24 +0000170
171 call assert_fails('echo screenpos(0, 2, 1)', 'E966:')
172
Bram Moolenaar38ba4dc2019-10-27 21:39:09 +0100173 close
174 bwipe!
175endfunc
Bram Moolenaar08f41572020-04-20 16:50:00 +0200176
Bram Moolenaar91458462021-01-13 20:08:38 +0100177" Save the visual start character position
Bram Moolenaar6f02b002021-01-10 20:22:54 +0100178func SaveVisualStartCharPos()
179 call add(g:VisualStartPos, getcharpos('v'))
180 return ''
181endfunc
182
Bram Moolenaar91458462021-01-13 20:08:38 +0100183" Save the current cursor character position in insert mode
184func SaveInsertCurrentCharPos()
185 call add(g:InsertCurrentPos, getcharpos('.'))
186 return ''
187endfunc
188
Bram Moolenaar6f02b002021-01-10 20:22:54 +0100189" Test for the getcharpos() function
190func Test_getcharpos()
191 call assert_fails('call getcharpos({})', 'E731:')
192 call assert_equal([0, 0, 0, 0], getcharpos(0))
193 new
Bram Moolenaar3caf1cc2022-04-11 13:05:16 +0100194 call setline(1, ['', "01\tà4è678", 'Ⅵ', '012345678', ' │ x'])
Bram Moolenaar6f02b002021-01-10 20:22:54 +0100195
196 " Test for '.' and '$'
197 normal 1G
198 call assert_equal([0, 1, 1, 0], getcharpos('.'))
Bram Moolenaar3caf1cc2022-04-11 13:05:16 +0100199 call assert_equal([0, 5, 1, 0], getcharpos('$'))
Bram Moolenaar6f02b002021-01-10 20:22:54 +0100200 normal 2G6l
201 call assert_equal([0, 2, 7, 0], getcharpos('.'))
202 normal 3G$
203 call assert_equal([0, 3, 1, 0], getcharpos('.'))
204 normal 4G$
205 call assert_equal([0, 4, 9, 0], getcharpos('.'))
206
207 " Test for a mark
208 normal 2G7lmmgg
209 call assert_equal([0, 2, 8, 0], getcharpos("'m"))
210 delmarks m
211 call assert_equal([0, 0, 0, 0], getcharpos("'m"))
212
Bram Moolenaar3caf1cc2022-04-11 13:05:16 +0100213 " Check mark does not move
214 normal 5Gfxma
215 call assert_equal([0, 5, 5, 0], getcharpos("'a"))
216 call assert_equal([0, 5, 5, 0], getcharpos("'a"))
217 call assert_equal([0, 5, 5, 0], getcharpos("'a"))
218
Bram Moolenaar6f02b002021-01-10 20:22:54 +0100219 " Test for the visual start column
220 vnoremap <expr> <F3> SaveVisualStartCharPos()
221 let g:VisualStartPos = []
222 exe "normal 2G6lv$\<F3>ohh\<F3>o\<F3>"
Bram Moolenaar91458462021-01-13 20:08:38 +0100223 call assert_equal([[0, 2, 7, 0], [0, 2, 10, 0], [0, 2, 5, 0]], g:VisualStartPos)
Bram Moolenaar6f02b002021-01-10 20:22:54 +0100224 call assert_equal([0, 2, 9, 0], getcharpos('v'))
225 let g:VisualStartPos = []
226 exe "normal 3Gv$\<F3>o\<F3>"
Bram Moolenaar91458462021-01-13 20:08:38 +0100227 call assert_equal([[0, 3, 1, 0], [0, 3, 2, 0]], g:VisualStartPos)
Bram Moolenaar6f02b002021-01-10 20:22:54 +0100228 let g:VisualStartPos = []
229 exe "normal 1Gv$\<F3>o\<F3>"
230 call assert_equal([[0, 1, 1, 0], [0, 1, 1, 0]], g:VisualStartPos)
231 vunmap <F3>
232
Bram Moolenaar91458462021-01-13 20:08:38 +0100233 " Test for getting the position in insert mode with the cursor after the
234 " last character in a line
235 inoremap <expr> <F3> SaveInsertCurrentCharPos()
236 let g:InsertCurrentPos = []
237 exe "normal 1GA\<F3>"
238 exe "normal 2GA\<F3>"
239 exe "normal 3GA\<F3>"
240 exe "normal 4GA\<F3>"
241 exe "normal 2G6li\<F3>"
242 call assert_equal([[0, 1, 1, 0], [0, 2, 10, 0], [0, 3, 2, 0], [0, 4, 10, 0],
243 \ [0, 2, 7, 0]], g:InsertCurrentPos)
244 iunmap <F3>
245
Bram Moolenaar6f02b002021-01-10 20:22:54 +0100246 %bw!
247endfunc
248
249" Test for the setcharpos() function
250func Test_setcharpos()
251 call assert_equal(-1, setcharpos('.', test_null_list()))
252 new
253 call setline(1, ['', "01\tà4è678", 'Ⅵ', '012345678'])
254 call setcharpos('.', [0, 1, 1, 0])
255 call assert_equal([1, 1], [line('.'), col('.')])
256 call setcharpos('.', [0, 2, 7, 0])
257 call assert_equal([2, 9], [line('.'), col('.')])
258 call setcharpos('.', [0, 3, 4, 0])
259 call assert_equal([3, 1], [line('.'), col('.')])
260 call setcharpos('.', [0, 3, 1, 0])
261 call assert_equal([3, 1], [line('.'), col('.')])
262 call setcharpos('.', [0, 4, 0, 0])
263 call assert_equal([4, 1], [line('.'), col('.')])
264 call setcharpos('.', [0, 4, 20, 0])
265 call assert_equal([4, 9], [line('.'), col('.')])
266
267 " Test for mark
268 delmarks m
269 call setcharpos("'m", [0, 2, 9, 0])
270 normal `m
271 call assert_equal([2, 11], [line('.'), col('.')])
Bram Moolenaar91458462021-01-13 20:08:38 +0100272 " unload the buffer and try to set the mark
273 let bnr = bufnr()
274 enew!
275 call assert_equal(-1, setcharpos("'m", [bnr, 2, 2, 0]))
Bram Moolenaar6f02b002021-01-10 20:22:54 +0100276
277 %bw!
278 call assert_equal(-1, setcharpos('.', [10, 3, 1, 0]))
279endfunc
280
281func SaveVisualStartCharCol()
282 call add(g:VisualStartCol, charcol('v'))
283 return ''
284endfunc
285
Bram Moolenaar91458462021-01-13 20:08:38 +0100286func SaveInsertCurrentCharCol()
287 call add(g:InsertCurrentCol, charcol('.'))
288 return ''
289endfunc
290
Bram Moolenaar6f02b002021-01-10 20:22:54 +0100291" Test for the charcol() function
292func Test_charcol()
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +0000293 call assert_fails('call charcol({})', 'E1222:')
294 call assert_fails('call charcol(".", [])', 'E1210:')
295 call assert_fails('call charcol(0)', 'E1222:')
Bram Moolenaar6f02b002021-01-10 20:22:54 +0100296 new
297 call setline(1, ['', "01\tà4è678", 'Ⅵ', '012345678'])
298
299 " Test for '.' and '$'
300 normal 1G
301 call assert_equal(1, charcol('.'))
302 call assert_equal(1, charcol('$'))
303 normal 2G6l
304 call assert_equal(7, charcol('.'))
305 call assert_equal(10, charcol('$'))
306 normal 3G$
307 call assert_equal(1, charcol('.'))
308 call assert_equal(2, charcol('$'))
309 normal 4G$
310 call assert_equal(9, charcol('.'))
311 call assert_equal(10, charcol('$'))
312
313 " Test for [lnum, '$']
314 call assert_equal(1, charcol([1, '$']))
315 call assert_equal(10, charcol([2, '$']))
316 call assert_equal(2, charcol([3, '$']))
317 call assert_equal(0, charcol([5, '$']))
318
319 " Test for a mark
320 normal 2G7lmmgg
321 call assert_equal(8, charcol("'m"))
322 delmarks m
323 call assert_equal(0, charcol("'m"))
324
325 " Test for the visual start column
326 vnoremap <expr> <F3> SaveVisualStartCharCol()
327 let g:VisualStartCol = []
328 exe "normal 2G6lv$\<F3>ohh\<F3>o\<F3>"
Bram Moolenaar91458462021-01-13 20:08:38 +0100329 call assert_equal([7, 10, 5], g:VisualStartCol)
Bram Moolenaar6f02b002021-01-10 20:22:54 +0100330 call assert_equal(9, charcol('v'))
331 let g:VisualStartCol = []
332 exe "normal 3Gv$\<F3>o\<F3>"
Bram Moolenaar91458462021-01-13 20:08:38 +0100333 call assert_equal([1, 2], g:VisualStartCol)
Bram Moolenaar6f02b002021-01-10 20:22:54 +0100334 let g:VisualStartCol = []
335 exe "normal 1Gv$\<F3>o\<F3>"
336 call assert_equal([1, 1], g:VisualStartCol)
337 vunmap <F3>
338
Bram Moolenaar91458462021-01-13 20:08:38 +0100339 " Test for getting the column number in insert mode with the cursor after
340 " the last character in a line
341 inoremap <expr> <F3> SaveInsertCurrentCharCol()
342 let g:InsertCurrentCol = []
343 exe "normal 1GA\<F3>"
344 exe "normal 2GA\<F3>"
345 exe "normal 3GA\<F3>"
346 exe "normal 4GA\<F3>"
347 exe "normal 2G6li\<F3>"
348 call assert_equal([1, 10, 2, 10, 7], g:InsertCurrentCol)
349 iunmap <F3>
350
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +0000351 " Test for getting the column number in another window.
352 let winid = win_getid()
353 new
354 call win_execute(winid, 'normal 1G')
355 call assert_equal(1, charcol('.', winid))
356 call assert_equal(1, charcol('$', winid))
357 call win_execute(winid, 'normal 2G6l')
358 call assert_equal(7, charcol('.', winid))
359 call assert_equal(10, charcol('$', winid))
360
361 " calling from another tab page also works
362 tabnew
363 call assert_equal(7, charcol('.', winid))
364 call assert_equal(10, charcol('$', winid))
365 tabclose
366
367 " unknown window ID
368 call assert_equal(0, charcol('.', 10001))
369
Bram Moolenaar6f02b002021-01-10 20:22:54 +0100370 %bw!
371endfunc
372
Bram Moolenaar91458462021-01-13 20:08:38 +0100373func SaveInsertCursorCharPos()
374 call add(g:InsertCursorPos, getcursorcharpos('.'))
375 return ''
376endfunc
377
Bram Moolenaar6f02b002021-01-10 20:22:54 +0100378" Test for getcursorcharpos()
379func Test_getcursorcharpos()
380 call assert_equal(getcursorcharpos(), getcursorcharpos(0))
381 call assert_equal([0, 0, 0, 0, 0], getcursorcharpos(-1))
382 call assert_equal([0, 0, 0, 0, 0], getcursorcharpos(1999))
383
384 new
385 call setline(1, ['', "01\tà4è678", 'Ⅵ', '012345678'])
386 normal 1G9l
387 call assert_equal([0, 1, 1, 0, 1], getcursorcharpos())
388 normal 2G9l
389 call assert_equal([0, 2, 9, 0, 14], getcursorcharpos())
390 normal 3G9l
391 call assert_equal([0, 3, 1, 0, 1], getcursorcharpos())
392 normal 4G9l
393 call assert_equal([0, 4, 9, 0, 9], getcursorcharpos())
394
Bram Moolenaar91458462021-01-13 20:08:38 +0100395 " Test for getting the cursor position in insert mode with the cursor after
396 " the last character in a line
397 inoremap <expr> <F3> SaveInsertCursorCharPos()
398 let g:InsertCursorPos = []
399 exe "normal 1GA\<F3>"
400 exe "normal 2GA\<F3>"
401 exe "normal 3GA\<F3>"
402 exe "normal 4GA\<F3>"
403 exe "normal 2G6li\<F3>"
404 call assert_equal([[0, 1, 1, 0, 1], [0, 2, 10, 0, 15], [0, 3, 2, 0, 2],
405 \ [0, 4, 10, 0, 10], [0, 2, 7, 0, 12]], g:InsertCursorPos)
406 iunmap <F3>
407
Bram Moolenaar6f02b002021-01-10 20:22:54 +0100408 let winid = win_getid()
409 normal 2G5l
410 wincmd w
411 call assert_equal([0, 2, 6, 0, 11], getcursorcharpos(winid))
412 %bw!
413endfunc
414
415" Test for setcursorcharpos()
416func Test_setcursorcharpos()
417 call assert_fails('call setcursorcharpos(test_null_list())', 'E474:')
418 call assert_fails('call setcursorcharpos([1])', 'E474:')
419 call assert_fails('call setcursorcharpos([1, 1, 1, 1, 1])', 'E474:')
420 new
421 call setline(1, ['', "01\tà4è678", 'Ⅵ', '012345678'])
422 normal G
423 call setcursorcharpos([1, 1])
424 call assert_equal([1, 1], [line('.'), col('.')])
Bram Moolenaar79f23442022-10-10 12:42:57 +0100425
Bram Moolenaar6f02b002021-01-10 20:22:54 +0100426 call setcursorcharpos([2, 7, 0])
427 call assert_equal([2, 9], [line('.'), col('.')])
Bram Moolenaar79f23442022-10-10 12:42:57 +0100428 call setcursorcharpos([0, 7, 0])
429 call assert_equal([2, 9], [line('.'), col('.')])
430 call setcursorcharpos(0, 7, 0)
431 call assert_equal([2, 9], [line('.'), col('.')])
432
Bram Moolenaar6f02b002021-01-10 20:22:54 +0100433 call setcursorcharpos(3, 4)
434 call assert_equal([3, 1], [line('.'), col('.')])
435 call setcursorcharpos([3, 1])
436 call assert_equal([3, 1], [line('.'), col('.')])
437 call setcursorcharpos([4, 0, 0, 0])
438 call assert_equal([4, 1], [line('.'), col('.')])
439 call setcursorcharpos([4, 20])
440 call assert_equal([4, 9], [line('.'), col('.')])
441 normal 1G
442 call setcursorcharpos([100, 100, 100, 100])
443 call assert_equal([4, 9], [line('.'), col('.')])
444 normal 1G
445 call setcursorcharpos('$', 1)
446 call assert_equal([4, 1], [line('.'), col('.')])
447
448 %bw!
449endfunc
450
Bram Moolenaar5a6ec102022-05-27 21:58:00 +0100451" Test for virtcol2col()
452func Test_virtcol2col()
453 new
454 call setline(1, ["a\tb\tc"])
455 call assert_equal(1, virtcol2col(0, 1, 1))
456 call assert_equal(2, virtcol2col(0, 1, 2))
457 call assert_equal(2, virtcol2col(0, 1, 8))
458 call assert_equal(3, virtcol2col(0, 1, 9))
459 call assert_equal(4, virtcol2col(0, 1, 10))
460 call assert_equal(4, virtcol2col(0, 1, 16))
461 call assert_equal(5, virtcol2col(0, 1, 17))
462 call assert_equal(-1, virtcol2col(10, 1, 1))
463 call assert_equal(-1, virtcol2col(0, 10, 1))
464 call assert_equal(-1, virtcol2col(0, -1, 1))
465 call assert_equal(-1, virtcol2col(0, 1, -1))
466 call assert_equal(5, virtcol2col(0, 1, 20))
467 call assert_fails('echo virtcol2col("0", 1, 20)', 'E1210:')
468 call assert_fails('echo virtcol2col(0, "1", 20)', 'E1210:')
469 call assert_fails('echo virtcol2col(0, 1, "1")', 'E1210:')
470 bw!
471endfunc
472
Bram Moolenaar08f41572020-04-20 16:50:00 +0200473" vim: shiftwidth=2 sts=2 expandtab