blob: 776eea85673bcc1b89396d652d2b4521afbf9c14 [file] [log] [blame]
Bram Moolenaar410e98a2019-09-09 22:05:49 +02001" Test for cursorline and cursorlineopt
Bram Moolenaar017ba072019-09-14 21:01:23 +02002
Bram Moolenaar410e98a2019-09-09 22:05:49 +02003source check.vim
Bram Moolenaar017ba072019-09-14 21:01:23 +02004source screendump.vim
Bram Moolenaar410e98a2019-09-09 22:05:49 +02005
6function! s:screen_attr(lnum) abort
7 return map(range(1, 8), 'screenattr(a:lnum, v:val)')
8endfunction
9
10function! s:test_windows(h, w) abort
11 call NewWindow(a:h, a:w)
12endfunction
13
14function! s:close_windows() abort
15 call CloseWindow()
16endfunction
17
18function! 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
25endfunction
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)
Bram Moolenaar49474ca2019-10-05 21:57:12 +020055 call assert_equal(attr22[0:3], attr31[0:3])
Bram Moolenaar410e98a2019-09-09 22:05:49 +020056 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
Bram Moolenaar017ba072019-09-14 21:01:23 +0200109
110func Test_cursorline_screenline()
111 CheckScreendump
112 CheckOption cursorlineopt
Bram Moolenaarc9e7e342021-07-22 21:33:03 +0200113
Bram Moolenaar017ba072019-09-14 21:01:23 +0200114 let filename='Xcursorline'
115 let lines = []
116
117 let file_content =<< trim END
118 1 foooooooo ar eins‍zwei drei vier fünf sechs sieben acht un zehn elf zwöfl dreizehn v ierzehn fünfzehn
119 2 foooooooo bar eins zwei drei vier fünf sechs sieben
120 3 foooooooo bar eins zwei drei vier fünf sechs sieben
121 4 foooooooo bar eins zwei drei vier fünf sechs sieben
122 END
123 let lines1 =<< trim END1
124 set nocp
125 set display=lastline
126 set cursorlineopt=screenline cursorline nu wrap sbr=>
127 hi CursorLineNr ctermfg=blue
128 25vsp
129 END1
130 let lines2 =<< trim END2
131 call cursor(1,1)
132 END2
133 call extend(lines, lines1)
134 call extend(lines, ["call append(0, ".. string(file_content).. ')'])
135 call extend(lines, lines2)
136 call writefile(lines, filename)
137 " basic test
138 let buf = RunVimInTerminal('-S '. filename, #{rows: 20})
Bram Moolenaar017ba072019-09-14 21:01:23 +0200139 call VerifyScreenDump(buf, 'Test_'. filename. '_1', {})
140 call term_sendkeys(buf, "fagj")
Bram Moolenaar017ba072019-09-14 21:01:23 +0200141 call VerifyScreenDump(buf, 'Test_'. filename. '_2', {})
142 call term_sendkeys(buf, "gj")
Bram Moolenaar017ba072019-09-14 21:01:23 +0200143 call VerifyScreenDump(buf, 'Test_'. filename. '_3', {})
144 call term_sendkeys(buf, "gj")
Bram Moolenaar017ba072019-09-14 21:01:23 +0200145 call VerifyScreenDump(buf, 'Test_'. filename. '_4', {})
146 call term_sendkeys(buf, "gj")
Bram Moolenaar017ba072019-09-14 21:01:23 +0200147 call VerifyScreenDump(buf, 'Test_'. filename. '_5', {})
148 call term_sendkeys(buf, "gj")
Bram Moolenaar017ba072019-09-14 21:01:23 +0200149 call VerifyScreenDump(buf, 'Test_'. filename. '_6', {})
150 " test with set list and cursorlineopt containing number
151 call term_sendkeys(buf, "gg0")
152 call term_sendkeys(buf, ":set list cursorlineopt+=number listchars=space:-\<cr>")
153 call VerifyScreenDump(buf, 'Test_'. filename. '_7', {})
154 call term_sendkeys(buf, "fagj")
Bram Moolenaar017ba072019-09-14 21:01:23 +0200155 call VerifyScreenDump(buf, 'Test_'. filename. '_8', {})
156 call term_sendkeys(buf, "gj")
Bram Moolenaar017ba072019-09-14 21:01:23 +0200157 call VerifyScreenDump(buf, 'Test_'. filename. '_9', {})
158 call term_sendkeys(buf, "gj")
Bram Moolenaar017ba072019-09-14 21:01:23 +0200159 call VerifyScreenDump(buf, 'Test_'. filename. '_10', {})
160 call term_sendkeys(buf, "gj")
Bram Moolenaar017ba072019-09-14 21:01:23 +0200161 call VerifyScreenDump(buf, 'Test_'. filename. '_11', {})
162 call term_sendkeys(buf, "gj")
Bram Moolenaar017ba072019-09-14 21:01:23 +0200163 call VerifyScreenDump(buf, 'Test_'. filename. '_12', {})
164 if exists("+foldcolumn") && exists("+signcolumn") && exists("+breakindent")
Dominique Pelle81b573d2022-03-22 21:14:55 +0000165 " test with set foldcolumn signcolumn and breakindent
Bram Moolenaar017ba072019-09-14 21:01:23 +0200166 call term_sendkeys(buf, "gg0")
167 call term_sendkeys(buf, ":set breakindent foldcolumn=2 signcolumn=yes\<cr>")
168 call VerifyScreenDump(buf, 'Test_'. filename. '_13', {})
169 call term_sendkeys(buf, "fagj")
Bram Moolenaar017ba072019-09-14 21:01:23 +0200170 call VerifyScreenDump(buf, 'Test_'. filename. '_14', {})
171 call term_sendkeys(buf, "gj")
Bram Moolenaar017ba072019-09-14 21:01:23 +0200172 call VerifyScreenDump(buf, 'Test_'. filename. '_15', {})
173 call term_sendkeys(buf, "gj")
Bram Moolenaar017ba072019-09-14 21:01:23 +0200174 call VerifyScreenDump(buf, 'Test_'. filename. '_16', {})
175 call term_sendkeys(buf, "gj")
Bram Moolenaar017ba072019-09-14 21:01:23 +0200176 call VerifyScreenDump(buf, 'Test_'. filename. '_17', {})
177 call term_sendkeys(buf, "gj")
Bram Moolenaar017ba072019-09-14 21:01:23 +0200178 call VerifyScreenDump(buf, 'Test_'. filename. '_18', {})
zeertzjq4f33bc22021-08-05 17:57:02 +0200179 call term_sendkeys(buf, ":set breakindent& foldcolumn& signcolumn&\<cr>")
Bram Moolenaar017ba072019-09-14 21:01:23 +0200180 endif
zeertzjq4f33bc22021-08-05 17:57:02 +0200181 " showbreak should not be highlighted with CursorLine when 'number' is off
182 call term_sendkeys(buf, "gg0")
183 call term_sendkeys(buf, ":set list cursorlineopt=screenline listchars=space:-\<cr>")
184 call term_sendkeys(buf, ":set nonumber\<cr>")
185 call VerifyScreenDump(buf, 'Test_'. filename. '_19', {})
186 call term_sendkeys(buf, "fagj")
zeertzjq4f33bc22021-08-05 17:57:02 +0200187 call VerifyScreenDump(buf, 'Test_'. filename. '_20', {})
188 call term_sendkeys(buf, "gj")
zeertzjq4f33bc22021-08-05 17:57:02 +0200189 call VerifyScreenDump(buf, 'Test_'. filename. '_21', {})
190 call term_sendkeys(buf, "gj")
zeertzjq4f33bc22021-08-05 17:57:02 +0200191 call VerifyScreenDump(buf, 'Test_'. filename. '_22', {})
192 call term_sendkeys(buf, "gj")
zeertzjq4f33bc22021-08-05 17:57:02 +0200193 call VerifyScreenDump(buf, 'Test_'. filename. '_23', {})
194 call term_sendkeys(buf, "gj")
zeertzjq4f33bc22021-08-05 17:57:02 +0200195 call VerifyScreenDump(buf, 'Test_'. filename. '_24', {})
196 call term_sendkeys(buf, ":set list& cursorlineopt& listchars&\<cr>")
Bram Moolenaar017ba072019-09-14 21:01:23 +0200197
198 call StopVimInTerminal(buf)
199 call delete(filename)
200endfunc
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200201
Bram Moolenaarc9e7e342021-07-22 21:33:03 +0200202func Test_cursorline_redraw()
203 CheckScreendump
204 CheckOption cursorlineopt
205
206 let textlines =<< END
207 When the option is a list of flags, {value} must be
208 exactly as they appear in the option. Remove flags
209 one by one to avoid problems.
210 Also see |:set-args| above.
211
212The {option} arguments to ":set" may be repeated. For example: >
213 :set ai nosi sw=3 ts=3
214If you make an error in one of the arguments, an error message will be given
215and the following arguments will be ignored.
216
217 *:set-verbose*
218When 'verbose' is non-zero, displaying an option value will also tell where it
219was last set. Example: >
220 :verbose set shiftwidth cindent?
221< shiftwidth=4 ~
222 Last set from modeline line 1 ~
223 cindent ~
224 Last set from /usr/local/share/vim/vim60/ftplugin/c.vim line 30 ~
225This is only done when specific option values are requested, not for ":verbose
226set all" or ":verbose set" without an argument.
227When the option was set by hand there is no "Last set" message.
228When the option was set while executing a function, user command or
229END
230 call writefile(textlines, 'Xtextfile')
231
232 let script =<< trim END
233 set cursorline scrolloff=2
234 normal 12G
235 END
236 call writefile(script, 'Xscript')
237
238 let buf = RunVimInTerminal('-S Xscript Xtextfile', #{rows: 20, cols: 40})
239 call VerifyScreenDump(buf, 'Test_cursorline_redraw_1', {})
240 call term_sendkeys(buf, "zt")
241 call TermWait(buf)
242 call term_sendkeys(buf, "\<C-U>")
243 call VerifyScreenDump(buf, 'Test_cursorline_redraw_2', {})
244
245 call StopVimInTerminal(buf)
246 call delete('Xscript')
247 call delete('Xtextfile')
248endfunc
249
Bram Moolenaare7a74d52022-03-19 11:10:15 +0000250func Test_cursorline_callback()
251 CheckScreendump
252 CheckFeature timers
253
254 let lines =<< trim END
255 call setline(1, ['aaaaa', 'bbbbb', 'ccccc', 'ddddd'])
256 set cursorline
257 call cursor(4, 1)
258
259 func Func(timer)
260 call cursor(2, 1)
261 endfunc
262
263 call timer_start(300, 'Func')
264 END
265 call writefile(lines, 'Xcul_timer')
266
267 let buf = RunVimInTerminal('-S Xcul_timer', #{rows: 8})
268 call TermWait(buf, 310)
269 call VerifyScreenDump(buf, 'Test_cursorline_callback_1', {})
270
271 call StopVimInTerminal(buf)
272 call delete('Xcul_timer')
273endfunc
274
Bram Moolenaarbf269ed2022-03-26 13:28:14 +0000275func Test_cursorline_screenline_update()
276 CheckScreendump
277
278 let lines =<< trim END
279 call setline(1, repeat('xyz ', 30))
280 set cursorline cursorlineopt=screenline
281 inoremap <F2> <Cmd>call cursor(1, 1)<CR>
282 END
283 call writefile(lines, 'Xcul_screenline')
284
285 let buf = RunVimInTerminal('-S Xcul_screenline', #{rows: 8})
286 call term_sendkeys(buf, "A")
287 call VerifyScreenDump(buf, 'Test_cursorline_screenline_1', {})
288 call term_sendkeys(buf, "\<F2>")
289 call VerifyScreenDump(buf, 'Test_cursorline_screenline_2', {})
290 call term_sendkeys(buf, "\<Esc>")
291
292 call StopVimInTerminal(buf)
293 call delete('Xcul_screenline')
294endfunc
295
Christian Brabandt2c645e82022-04-20 14:52:01 +0100296func Test_cursorline_cursorbind_horizontal_scroll()
297 CheckScreendump
298
299 let lines =<< trim END
300 call setline(1, 'aa bb cc dd ee ff gg hh ii jj kk ll mm' ..
301 \ ' nn oo pp qq rr ss tt uu vv ww xx yy zz')
302 set nowrap
303 " The following makes the cursor apparent on the screen dump
304 set sidescroll=1 cursorcolumn
305 " add empty lines, required for cursorcolumn
306 call append(1, ['','','',''])
307 20vsp
308 windo :set cursorbind
309 END
310 call writefile(lines, 'Xhor_scroll')
311
312 let buf = RunVimInTerminal('-S Xhor_scroll', #{rows: 8})
313 call term_sendkeys(buf, "20l")
314 call VerifyScreenDump(buf, 'Test_hor_scroll_1', {})
315 call term_sendkeys(buf, "10l")
316 call VerifyScreenDump(buf, 'Test_hor_scroll_2', {})
317 call term_sendkeys(buf, ":windo :set cursorline\<cr>")
318 call term_sendkeys(buf, "0")
319 call term_sendkeys(buf, "20l")
320 call VerifyScreenDump(buf, 'Test_hor_scroll_3', {})
321 call term_sendkeys(buf, "10l")
322 call VerifyScreenDump(buf, 'Test_hor_scroll_4', {})
323
324 call StopVimInTerminal(buf)
325 "call delete('Xhor_scroll')
326endfunc
327
Bram Moolenaare7a74d52022-03-19 11:10:15 +0000328
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200329" vim: shiftwidth=2 sts=2 expandtab