robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

robinmerge: 1dc9728daa1d8a2702

master
13.2 KiB423 linesraw
1" Test for cursorline and cursorlineopt
2
3source check.vim
4source screendump.vim
5
6func s:screen_attr(lnum) abort
7  return map(range(1, 8), 'screenattr(a:lnum, v:val)')
8endfunc
9
10func s:test_windows(h, w) abort
11  call NewWindow(a:h, a:w)
12endfunc
13
14func s:close_windows() abort
15  call CloseWindow()
16endfunc
17
18func s:new_hi() abort
19  redir => save_hi
20  silent! hi CursorLineNr
21  redir END
22  let save_hi = join(split(substitute(save_hi, '\s*xxx\s*', ' ', ''), "\n"), '')
23  exe 'hi' save_hi 'ctermbg=0 guibg=Black'
24  return save_hi
25endfunc
26
27func Test_cursorline_highlight1()
28  let save_hi = s:new_hi()
29  try
30    call s:test_windows(10, 20)
31    call setline(1, repeat(['aaaa'], 10))
32    redraw
33    let attr01 = s:screen_attr(1)
34    call assert_equal(repeat([attr01[0]], 8), attr01)
35
36    setl number numberwidth=4
37    redraw
38    let attr11 = s:screen_attr(1)
39    call assert_equal(repeat([attr11[0]], 4), attr11[0:3])
40    call assert_equal(repeat([attr11[4]], 4), attr11[4:7])
41    call assert_notequal(attr11[0], attr11[4])
42
43    setl cursorline
44    redraw
45    let attr21 = s:screen_attr(1)
46    let attr22 = s:screen_attr(2)
47    call assert_equal(repeat([attr21[0]], 4), attr21[0:3])
48    call assert_equal(repeat([attr21[4]], 4), attr21[4:7])
49    call assert_equal(attr11, attr22)
50    call assert_notequal(attr22, attr21)
51
52    setl nocursorline relativenumber
53    redraw
54    let attr31 = s:screen_attr(1)
55    call assert_equal(attr22[0:3], attr31[0:3])
56    call assert_equal(attr11[4:7], attr31[4:7])
57
58    call s:close_windows()
59  finally
60    exe 'hi' save_hi
61  endtry
62endfunc
63
64func Test_cursorline_highlight2()
65  CheckOption cursorlineopt
66
67  let save_hi = s:new_hi()
68  try
69    call s:test_windows(10, 20)
70    call setline(1, repeat(['aaaa'], 10))
71    redraw
72    let attr0 = s:screen_attr(1)
73    call assert_equal(repeat([attr0[0]], 8), attr0)
74
75    setl number
76    redraw
77    let attr1 = s:screen_attr(1)
78    call assert_notequal(attr0[0:3], attr1[0:3])
79    call assert_equal(attr0[0:3], attr1[4:7])
80
81    setl cursorline cursorlineopt=both
82    redraw
83    let attr2 = s:screen_attr(1)
84    call assert_notequal(attr1[0:3], attr2[0:3])
85    call assert_notequal(attr1[4:7], attr2[4:7])
86
87    setl cursorlineopt=line
88    redraw
89    let attr3 = s:screen_attr(1)
90    call assert_equal(attr1[0:3], attr3[0:3])
91    call assert_equal(attr2[4:7], attr3[4:7])
92
93    setl cursorlineopt=number
94    redraw
95    let attr4 = s:screen_attr(1)
96    call assert_equal(attr2[0:3], attr4[0:3])
97    call assert_equal(attr1[4:7], attr4[4:7])
98
99    setl nonumber
100    redraw
101    let attr5 = s:screen_attr(1)
102    call assert_equal(attr0, attr5)
103
104    call s:close_windows()
105  finally
106    exe 'hi' save_hi
107  endtry
108endfunc
109
110func Test_cursorline_fold_sign_independent_of_culopt()
111  " CursorLineFold/CursorLineSign follow 'cursorline', not 'cursorlineopt'.
112  CheckOption cursorlineopt
113  CheckFeature signs
114  CheckFeature folding
115
116  call s:test_windows(10, 20)
117  try
118    call setline(1, repeat(['aaaa'], 5))
119    setl number numberwidth=4 signcolumn=yes foldcolumn=1
120    hi FoldColumn ctermbg=1 guibg=Red
121    hi CursorLineFold ctermbg=2 guibg=Green
122    hi SignColumn ctermbg=3 guibg=Yellow
123    hi CursorLineSign ctermbg=4 guibg=Blue
124
125    setl nocursorline
126    redraw
127    let fold_off = screenattr(1, 1)
128    let sign_off = screenattr(1, 2)
129
130    " 'cursorlineopt' is "line" only: fold/sign on the cursor line still
131    " use CursorLineFold / CursorLineSign.
132    setl cursorline cursorlineopt=line
133    redraw
134    call assert_notequal(fold_off, screenattr(1, 1))
135    call assert_notequal(sign_off, screenattr(1, 2))
136    call assert_equal(fold_off, screenattr(2, 1))
137    call assert_equal(sign_off, screenattr(2, 2))
138
139    setl cursorlineopt=number
140    redraw
141    call assert_notequal(fold_off, screenattr(1, 1))
142    call assert_notequal(sign_off, screenattr(1, 2))
143
144    setl cursorlineopt=both
145    redraw
146    call assert_notequal(fold_off, screenattr(1, 1))
147    call assert_notequal(sign_off, screenattr(1, 2))
148  finally
149    setl number& numberwidth& signcolumn& foldcolumn& cursorline& cursorlineopt&
150    hi clear FoldColumn
151    hi clear CursorLineFold
152    hi clear SignColumn
153    hi clear CursorLineSign
154    hi default link CursorLineFold FoldColumn
155    hi default link CursorLineSign SignColumn
156    call s:close_windows()
157  endtry
158endfunc
159
160func Test_cursorline_screenline()
161  CheckScreendump
162  CheckOption cursorlineopt
163
164  let filename='Xcursorline'
165  let lines = []
166
167  let file_content =<< trim END
168    1 foooooooo ar eins‍zwei drei vier fünf sechs sieben acht un zehn elf zwöfl dreizehn	v ierzehn	fünfzehn
169    2 foooooooo bar eins zwei drei vier fünf sechs sieben
170    3 foooooooo bar eins zwei drei vier fünf sechs sieben
171    4 foooooooo bar eins zwei drei vier fünf sechs sieben
172  END
173  let lines1 =<< trim END1
174    set nocp
175    set display=lastline
176    set cursorlineopt=screenline cursorline nu wrap sbr=>
177    hi CursorLineNr ctermfg=blue
178    25vsp
179  END1
180  let lines2 =<< trim END2
181    call cursor(1,1)
182  END2
183  call extend(lines, lines1)
184  call extend(lines,  ["call append(0, ".. string(file_content).. ')'])
185  call extend(lines, lines2)
186  call writefile(lines, filename)
187  " basic test
188  let buf = RunVimInTerminal('-S '. filename, #{rows: 20})
189  call VerifyScreenDump(buf, 'Test_'. filename. '_1', {})
190  call term_sendkeys(buf, "fagj")
191  call VerifyScreenDump(buf, 'Test_'. filename. '_2', {})
192  call term_sendkeys(buf, "gj")
193  call VerifyScreenDump(buf, 'Test_'. filename. '_3', {})
194  call term_sendkeys(buf, "gj")
195  call VerifyScreenDump(buf, 'Test_'. filename. '_4', {})
196  call term_sendkeys(buf, "gj")
197  call VerifyScreenDump(buf, 'Test_'. filename. '_5', {})
198  call term_sendkeys(buf, "gj")
199  call VerifyScreenDump(buf, 'Test_'. filename. '_6', {})
200  " test with set list and cursorlineopt containing number
201  call term_sendkeys(buf, "gg0")
202  call term_sendkeys(buf, ":set list cursorlineopt+=number listchars=space:-\<cr>")
203  call VerifyScreenDump(buf, 'Test_'. filename. '_7', {})
204  call term_sendkeys(buf, "fagj")
205  call VerifyScreenDump(buf, 'Test_'. filename. '_8', {})
206  call term_sendkeys(buf, "gj")
207  call VerifyScreenDump(buf, 'Test_'. filename. '_9', {})
208  call term_sendkeys(buf, "gj")
209  call VerifyScreenDump(buf, 'Test_'. filename. '_10', {})
210  call term_sendkeys(buf, "gj")
211  call VerifyScreenDump(buf, 'Test_'. filename. '_11', {})
212  call term_sendkeys(buf, "gj")
213  call VerifyScreenDump(buf, 'Test_'. filename. '_12', {})
214  if exists("+foldcolumn") && exists("+signcolumn") && exists("+breakindent")
215    " test with set foldcolumn signcolumn and breakindent
216    call term_sendkeys(buf, "gg0")
217    call term_sendkeys(buf, ":set breakindent foldcolumn=2 signcolumn=yes\<cr>")
218    call VerifyScreenDump(buf, 'Test_'. filename. '_13', {})
219    call term_sendkeys(buf, "fagj")
220    call VerifyScreenDump(buf, 'Test_'. filename. '_14', {})
221    call term_sendkeys(buf, "gj")
222    call VerifyScreenDump(buf, 'Test_'. filename. '_15', {})
223    call term_sendkeys(buf, "gj")
224    call VerifyScreenDump(buf, 'Test_'. filename. '_16', {})
225    call term_sendkeys(buf, "gj")
226    call VerifyScreenDump(buf, 'Test_'. filename. '_17', {})
227    call term_sendkeys(buf, "gj")
228    call VerifyScreenDump(buf, 'Test_'. filename. '_18', {})
229    call term_sendkeys(buf, ":set breakindent& foldcolumn& signcolumn&\<cr>")
230  endif
231  " showbreak should not be highlighted with CursorLine when 'number' is off
232  call term_sendkeys(buf, "gg0")
233  call term_sendkeys(buf, ":set list cursorlineopt=screenline listchars=space:-\<cr>")
234  call term_sendkeys(buf, ":set nonumber\<cr>")
235  call VerifyScreenDump(buf, 'Test_'. filename. '_19', {})
236  call term_sendkeys(buf, "fagj")
237  call VerifyScreenDump(buf, 'Test_'. filename. '_20', {})
238  call term_sendkeys(buf, "gj")
239  call VerifyScreenDump(buf, 'Test_'. filename. '_21', {})
240  call term_sendkeys(buf, "gj")
241  call VerifyScreenDump(buf, 'Test_'. filename. '_22', {})
242  call term_sendkeys(buf, "gj")
243  call VerifyScreenDump(buf, 'Test_'. filename. '_23', {})
244  call term_sendkeys(buf, "gj")
245  call VerifyScreenDump(buf, 'Test_'. filename. '_24', {})
246  call term_sendkeys(buf, ":set list& cursorlineopt& listchars&\<cr>")
247
248  call StopVimInTerminal(buf)
249  call delete(filename)
250endfunc
251
252func Test_cursorline_redraw()
253  CheckScreendump
254  CheckOption cursorlineopt
255
256  let textlines =<< END
257			When the option is a list of flags, {value} must be
258			exactly as they appear in the option.  Remove flags
259			one by one to avoid problems.
260			Also see |:set-args| above.
261
262The {option} arguments to ":set" may be repeated.  For example: >
263	:set ai nosi sw=3 ts=3
264If you make an error in one of the arguments, an error message will be given
265and the following arguments will be ignored.
266
267							*:set-verbose*
268When 'verbose' is non-zero, displaying an option value will also tell where it
269was last set.  Example: >
270	:verbose set shiftwidth cindent?
271<  shiftwidth=4 ~
272	  Last set from modeline line 1 ~
273  cindent ~
274	  Last set from /usr/local/share/vim/vim60/ftplugin/c.vim line 30 ~
275This is only done when specific option values are requested, not for ":verbose
276set all" or ":verbose set" without an argument.
277When the option was set by hand there is no "Last set" message.
278When the option was set while executing a function, user command or
279END
280  call writefile(textlines, 'Xtextfile')
281
282  let script =<< trim END
283      set cursorline scrolloff=2
284      normal 12G
285  END
286  call writefile(script, 'Xscript')
287
288  let buf = RunVimInTerminal('-S Xscript Xtextfile', #{rows: 20, cols: 40})
289  call VerifyScreenDump(buf, 'Test_cursorline_redraw_1', {})
290  call term_sendkeys(buf, "zt")
291  call TermWait(buf)
292  call term_sendkeys(buf, "\<C-U>")
293  call VerifyScreenDump(buf, 'Test_cursorline_redraw_2', {})
294
295  call StopVimInTerminal(buf)
296  call delete('Xscript')
297  call delete('Xtextfile')
298endfunc
299
300func Test_cursorline_callback()
301  CheckScreendump
302  CheckFeature timers
303
304  let lines =<< trim END
305      call setline(1, ['aaaaa', 'bbbbb', 'ccccc', 'ddddd'])
306      set cursorline
307      call cursor(4, 1)
308
309      func Func(timer)
310        call cursor(2, 1)
311      endfunc
312
313      call timer_start(300, 'Func')
314  END
315  call writefile(lines, 'Xcul_timer', 'D')
316
317  let buf = RunVimInTerminal('-S Xcul_timer', #{rows: 8})
318  call TermWait(buf, 310)
319  call VerifyScreenDump(buf, 'Test_cursorline_callback_1', {})
320
321  call StopVimInTerminal(buf)
322endfunc
323
324func Test_cursorline_screenline_resize()
325  CheckScreendump
326
327  let lines =<< trim END
328      50vnew
329      call setline(1, repeat('xyz ', 30))
330      setlocal number cursorline cursorlineopt=screenline
331      normal! $
332  END
333  call writefile(lines, 'Xcul_screenline_resize', 'D')
334
335  let buf = RunVimInTerminal('-S Xcul_screenline_resize', #{rows: 8})
336  call VerifyScreenDump(buf, 'Test_cursorline_screenline_resize_1', {})
337  call term_sendkeys(buf, ":vertical resize -4\<CR>")
338  call VerifyScreenDump(buf, 'Test_cursorline_screenline_resize_2', {})
339  call term_sendkeys(buf, ":set cpoptions+=n\<CR>")
340  call VerifyScreenDump(buf, 'Test_cursorline_screenline_resize_3', {})
341
342  call StopVimInTerminal(buf)
343endfunc
344
345func Test_cursorline_screenline_update()
346  CheckScreendump
347
348  let lines =<< trim END
349      func TestRetab()
350        let w = winwidth(0)
351        call cursor([1, w + 1, 0, w + 1])
352        call line('w0')
353        retab 8
354      endfunc
355
356      call setline(1, repeat('xyz ', 30))
357      set cursorline cursorlineopt=screenline tabstop=8
358      inoremap <F2> <Cmd>call cursor(1, 1)<CR>
359      inoremap <F3> <Cmd>call TestRetab()<CR>
360  END
361  call writefile(lines, 'Xcul_screenline', 'D')
362
363  let buf = RunVimInTerminal('-S Xcul_screenline', #{rows: 8})
364  call term_sendkeys(buf, "A")
365  call VerifyScreenDump(buf, 'Test_cursorline_screenline_1', {})
366  call term_sendkeys(buf, "\<F2>")
367  call VerifyScreenDump(buf, 'Test_cursorline_screenline_2', {})
368  call term_sendkeys(buf, "\<F3>")
369  call VerifyScreenDump(buf, 'Test_cursorline_screenline_3', {})
370  call term_sendkeys(buf, "\<Esc>")
371
372  call StopVimInTerminal(buf)
373endfunc
374
375func Test_cursorline_screenline_zero_width()
376  CheckOption foldcolumn
377
378  set cursorline culopt=screenline winminwidth=1 foldcolumn=1
379  " This used to crash Vim
380  1vnew | redraw
381
382  bwipe!
383  set cursorline& culopt& winminwidth& foldcolumn&
384endfunc
385
386func Test_cursorline_cursorbind_horizontal_scroll()
387  CheckScreendump
388
389  let lines =<< trim END
390      call setline(1, 'aa bb cc dd ee ff gg hh ii jj kk ll mm' ..
391                    \ ' nn oo pp qq rr ss tt uu vv ww xx yy zz')
392      set nowrap
393      " The following makes the cursor apparent on the screen dump
394      set sidescroll=1 cursorcolumn
395      " add empty lines, required for cursorcolumn
396      call append(1, ['','','',''])
397      20vsp
398      windo :set cursorbind
399  END
400  call writefile(lines, 'Xhor_scroll')
401
402  let buf = RunVimInTerminal('-S Xhor_scroll', #{rows: 8})
403  call term_sendkeys(buf, "20l")
404  call VerifyScreenDump(buf, 'Test_hor_scroll_1', {})
405  call term_sendkeys(buf, "10l")
406  call VerifyScreenDump(buf, 'Test_hor_scroll_2', {})
407  call term_sendkeys(buf, ":windo :set cursorline\<cr>")
408  call term_sendkeys(buf, "0")
409  call term_sendkeys(buf, "20l")
410  call VerifyScreenDump(buf, 'Test_hor_scroll_3', {})
411  call term_sendkeys(buf, "10l")
412  call VerifyScreenDump(buf, 'Test_hor_scroll_4', {})
413  call term_sendkeys(buf, ":windo :set nocursorline nocursorcolumn\<cr>")
414  call term_sendkeys(buf, "0")
415  call term_sendkeys(buf, "40l")
416  call VerifyScreenDump(buf, 'Test_hor_scroll_5', {})
417
418  call StopVimInTerminal(buf)
419  call delete('Xhor_scroll')
420endfunc
421
422
423" vim: shiftwidth=2 sts=2 expandtab