Mercurial > vim
comparison src/testdir/test_highlight.vim @ 12580:ba55861aa52c v8.0.1168
patch 8.0.1168: wrong highlighting with combination of match and 'cursorline'
commit https://github.com/vim/vim/commit/0aa398f55a327282c70f56e0bac2dcb9521da378
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Sep 30 21:23:55 2017 +0200
patch 8.0.1168: wrong highlighting with combination of match and 'cursorline'
Problem: wrong highlighting with combination of match and 'cursorline'.
Solution: Use "line_attr" when appropriate. (Ozaki Kiichi, closes https://github.com/vim/vim/issues/2111)
But don't highlight more than one character.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 30 Sep 2017 21:30:05 +0200 |
parents | 7d7835ab8b37 |
children | 97f0c74976c6 |
comparison
equal
deleted
inserted
replaced
12579:64b98c8e200a | 12580:ba55861aa52c |
---|---|
1 " Tests for ":highlight". | 1 " Tests for ":highlight" and highlighting. |
2 | |
3 source view_util.vim | |
4 | |
2 func Test_highlight() | 5 func Test_highlight() |
3 " basic test if ":highlight" doesn't crash | 6 " basic test if ":highlight" doesn't crash |
4 highlight | 7 highlight |
5 hi Search | 8 hi Search |
6 | 9 |
32 hi clear | 35 hi clear |
33 call assert_equal("Group3 xxx cleared", | 36 call assert_equal("Group3 xxx cleared", |
34 \ split(execute("hi Group3"), "\n")[0]) | 37 \ split(execute("hi Group3"), "\n")[0]) |
35 call assert_fails("hi Crash term='asdf", "E475:") | 38 call assert_fails("hi Crash term='asdf", "E475:") |
36 endfunc | 39 endfunc |
40 | |
41 function! HighlightArgs(name) | |
42 return 'hi ' . substitute(split(execute('hi ' . a:name), '\n')[0], '\<xxx\>', '', '') | |
43 endfunction | |
44 | |
45 function! IsColorable() | |
46 return has('gui_running') || str2nr(&t_Co) >= 8 | |
47 endfunction | |
48 | |
49 function! HiCursorLine() | |
50 let hiCursorLine = HighlightArgs('CursorLine') | |
51 if has('gui_running') | |
52 let guibg = matchstr(hiCursorLine, 'guibg=\w\+') | |
53 let hi_ul = 'hi CursorLine gui=underline guibg=NONE' | |
54 let hi_bg = 'hi CursorLine gui=NONE ' . guibg | |
55 else | |
56 let hi_ul = 'hi CursorLine cterm=underline ctermbg=NONE' | |
57 let hi_bg = 'hi CursorLine cterm=NONE ctermbg=Gray' | |
58 endif | |
59 return [hiCursorLine, hi_ul, hi_bg] | |
60 endfunction | |
61 | |
62 func Test_highlight_eol_with_cursorline() | |
63 let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine() | |
64 | |
65 call NewWindow('topleft 5', 20) | |
66 call setline(1, 'abcd') | |
67 call matchadd('Search', '\n') | |
68 | |
69 " expected: | |
70 " 'abcd ' | |
71 " ^^^^ ^^^^^ no highlight | |
72 " ^ 'Search' highlight | |
73 let attrs0 = ScreenAttrs(1, 10)[0] | |
74 call assert_equal(repeat([attrs0[0]], 4), attrs0[0:3]) | |
75 call assert_equal(repeat([attrs0[0]], 5), attrs0[5:9]) | |
76 call assert_notequal(attrs0[0], attrs0[4]) | |
77 | |
78 setlocal cursorline | |
79 | |
80 " underline | |
81 exe hi_ul | |
82 | |
83 " expected: | |
84 " 'abcd ' | |
85 " ^^^^ underline | |
86 " ^^^^^^ 'Search' highlight with underline | |
87 let attrs = ScreenAttrs(1, 10)[0] | |
88 call assert_equal(repeat([attrs[0]], 4), attrs[0:3]) | |
89 call assert_equal([attrs[4]] + repeat([attrs[5]], 5), attrs[4:9]) | |
90 call assert_notequal(attrs[0], attrs[4]) | |
91 call assert_notequal(attrs[4], attrs[5]) | |
92 call assert_notequal(attrs0[0], attrs[0]) | |
93 call assert_notequal(attrs0[4], attrs[4]) | |
94 | |
95 if IsColorable() | |
96 " bg-color | |
97 exe hi_bg | |
98 | |
99 " expected: | |
100 " 'abcd ' | |
101 " ^^^^ bg-color of 'CursorLine' | |
102 " ^ 'Search' highlight | |
103 " ^^^^^ bg-color of 'CursorLine' | |
104 let attrs = ScreenAttrs(1, 10)[0] | |
105 call assert_equal(repeat([attrs[0]], 4), attrs[0:3]) | |
106 call assert_equal(repeat([attrs[5]], 5), attrs[5:9]) | |
107 call assert_equal(attrs0[4], attrs[4]) | |
108 call assert_notequal(attrs[0], attrs[4]) | |
109 call assert_notequal(attrs[4], attrs[5]) | |
110 call assert_notequal(attrs0[0], attrs[0]) | |
111 call assert_notequal(attrs0[5], attrs[5]) | |
112 endif | |
113 | |
114 call CloseWindow() | |
115 exe hiCursorLine | |
116 endfunc | |
117 | |
118 func Test_highlight_eol_with_cursorline_vertsplit() | |
119 if !has('vertsplit') | |
120 return | |
121 endif | |
122 | |
123 let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine() | |
124 | |
125 call NewWindow('topleft 5', 5) | |
126 call setline(1, 'abcd') | |
127 call matchadd('Search', '\n') | |
128 | |
129 let expected = "abcd |abcd " | |
130 let actual = ScreenLines(1, 15)[0] | |
131 call assert_equal(expected, actual) | |
132 | |
133 " expected: | |
134 " 'abcd |abcd ' | |
135 " ^^^^ ^^^^^^^^^ no highlight | |
136 " ^ 'Search' highlight | |
137 " ^ 'VertSplit' highlight | |
138 let attrs0 = ScreenAttrs(1, 15)[0] | |
139 call assert_equal(repeat([attrs0[0]], 4), attrs0[0:3]) | |
140 call assert_equal(repeat([attrs0[0]], 9), attrs0[6:14]) | |
141 call assert_notequal(attrs0[0], attrs0[4]) | |
142 call assert_notequal(attrs0[0], attrs0[5]) | |
143 call assert_notequal(attrs0[4], attrs0[5]) | |
144 | |
145 setlocal cursorline | |
146 | |
147 " expected: | |
148 " 'abcd |abcd ' | |
149 " ^^^^ underline | |
150 " ^ 'Search' highlight with underline | |
151 " ^ 'VertSplit' highlight | |
152 " ^^^^^^^^^ no highlight | |
153 | |
154 " underline | |
155 exe hi_ul | |
156 | |
157 let actual = ScreenLines(1, 15)[0] | |
158 call assert_equal(expected, actual) | |
159 | |
160 let attrs = ScreenAttrs(1, 15)[0] | |
161 call assert_equal(repeat([attrs[0]], 4), attrs[0:3]) | |
162 call assert_equal(repeat([attrs[6]], 9), attrs[6:14]) | |
163 call assert_equal(attrs0[5:14], attrs[5:14]) | |
164 call assert_notequal(attrs[0], attrs[4]) | |
165 call assert_notequal(attrs[0], attrs[5]) | |
166 call assert_notequal(attrs[0], attrs[6]) | |
167 call assert_notequal(attrs[4], attrs[5]) | |
168 call assert_notequal(attrs[5], attrs[6]) | |
169 call assert_notequal(attrs0[0], attrs[0]) | |
170 call assert_notequal(attrs0[4], attrs[4]) | |
171 | |
172 if IsColorable() | |
173 " bg-color | |
174 exe hi_bg | |
175 | |
176 let actual = ScreenLines(1, 15)[0] | |
177 call assert_equal(expected, actual) | |
178 | |
179 let attrs = ScreenAttrs(1, 15)[0] | |
180 call assert_equal(repeat([attrs[0]], 4), attrs[0:3]) | |
181 call assert_equal(repeat([attrs[6]], 9), attrs[6:14]) | |
182 call assert_equal(attrs0[5:14], attrs[5:14]) | |
183 call assert_notequal(attrs[0], attrs[4]) | |
184 call assert_notequal(attrs[0], attrs[5]) | |
185 call assert_notequal(attrs[0], attrs[6]) | |
186 call assert_notequal(attrs[4], attrs[5]) | |
187 call assert_notequal(attrs[5], attrs[6]) | |
188 call assert_notequal(attrs0[0], attrs[0]) | |
189 call assert_equal(attrs0[4], attrs[4]) | |
190 endif | |
191 | |
192 call CloseWindow() | |
193 exe hiCursorLine | |
194 endfunc | |
195 | |
196 func Test_highlight_eol_with_cursorline_rightleft() | |
197 if !has('rightleft') | |
198 return | |
199 endif | |
200 | |
201 let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine() | |
202 | |
203 call NewWindow('topleft 5', 10) | |
204 setlocal rightleft | |
205 call setline(1, 'abcd') | |
206 call matchadd('Search', '\n') | |
207 let attrs0 = ScreenAttrs(1, 10)[0] | |
208 | |
209 setlocal cursorline | |
210 | |
211 " underline | |
212 exe hi_ul | |
213 | |
214 " expected: | |
215 " ' dcba' | |
216 " ^^^^ underline | |
217 " ^ 'Search' highlight with underline | |
218 " ^^^^^ underline | |
219 let attrs = ScreenAttrs(1, 10)[0] | |
220 call assert_equal(repeat([attrs[9]], 4), attrs[6:9]) | |
221 call assert_equal(repeat([attrs[4]], 5) + [attrs[5]], attrs[0:5]) | |
222 call assert_notequal(attrs[9], attrs[5]) | |
223 call assert_notequal(attrs[4], attrs[5]) | |
224 call assert_notequal(attrs0[9], attrs[9]) | |
225 call assert_notequal(attrs0[5], attrs[5]) | |
226 | |
227 if IsColorable() | |
228 " bg-color | |
229 exe hi_bg | |
230 | |
231 " expected: | |
232 " ' dcba' | |
233 " ^^^^ bg-color of 'CursorLine' | |
234 " ^ 'Search' highlight | |
235 " ^^^^^ bg-color of 'CursorLine' | |
236 let attrs = ScreenAttrs(1, 10)[0] | |
237 call assert_equal(repeat([attrs[9]], 4), attrs[6:9]) | |
238 call assert_equal(repeat([attrs[4]], 5), attrs[0:4]) | |
239 call assert_equal(attrs0[5], attrs[5]) | |
240 call assert_notequal(attrs[9], attrs[5]) | |
241 call assert_notequal(attrs[5], attrs[4]) | |
242 call assert_notequal(attrs0[9], attrs[9]) | |
243 call assert_notequal(attrs0[4], attrs[4]) | |
244 endif | |
245 | |
246 call CloseWindow() | |
247 exe hiCursorLine | |
248 endfunc | |
249 | |
250 func Test_highlight_eol_with_cursorline_linewrap() | |
251 let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine() | |
252 | |
253 call NewWindow('topleft 5', 10) | |
254 call setline(1, [repeat('a', 51) . 'bcd', '']) | |
255 call matchadd('Search', '\n') | |
256 | |
257 setlocal wrap | |
258 normal! gg$ | |
259 let attrs0 = ScreenAttrs(5, 10)[0] | |
260 setlocal cursorline | |
261 | |
262 " underline | |
263 exe hi_ul | |
264 | |
265 " expected: | |
266 " 'abcd ' | |
267 " ^^^^ underline | |
268 " ^ 'Search' highlight with underline | |
269 " ^^^^^ underline | |
270 let attrs = ScreenAttrs(5, 10)[0] | |
271 call assert_equal(repeat([attrs[0]], 4), attrs[0:3]) | |
272 call assert_equal([attrs[4]] + repeat([attrs[5]], 5), attrs[4:9]) | |
273 call assert_notequal(attrs[0], attrs[4]) | |
274 call assert_notequal(attrs[4], attrs[5]) | |
275 call assert_notequal(attrs0[0], attrs[0]) | |
276 call assert_notequal(attrs0[4], attrs[4]) | |
277 | |
278 if IsColorable() | |
279 " bg-color | |
280 exe hi_bg | |
281 | |
282 " expected: | |
283 " 'abcd ' | |
284 " ^^^^ bg-color of 'CursorLine' | |
285 " ^ 'Search' highlight | |
286 " ^^^^^ bg-color of 'CursorLine' | |
287 let attrs = ScreenAttrs(5, 10)[0] | |
288 call assert_equal(repeat([attrs[0]], 4), attrs[0:3]) | |
289 call assert_equal(repeat([attrs[5]], 5), attrs[5:9]) | |
290 call assert_equal(attrs0[4], attrs[4]) | |
291 call assert_notequal(attrs[0], attrs[4]) | |
292 call assert_notequal(attrs[4], attrs[5]) | |
293 call assert_notequal(attrs0[0], attrs[0]) | |
294 call assert_notequal(attrs0[5], attrs[5]) | |
295 endif | |
296 | |
297 setlocal nocursorline nowrap | |
298 normal! gg$ | |
299 let attrs0 = ScreenAttrs(1, 10)[0] | |
300 setlocal cursorline | |
301 | |
302 " underline | |
303 exe hi_ul | |
304 | |
305 " expected: | |
306 " 'aaabcd ' | |
307 " ^^^^^^ underline | |
308 " ^ 'Search' highlight with underline | |
309 " ^^^ underline | |
310 let attrs = ScreenAttrs(1, 10)[0] | |
311 call assert_equal(repeat([attrs[0]], 6), attrs[0:5]) | |
312 call assert_equal([attrs[6]] + repeat([attrs[7]], 3), attrs[6:9]) | |
313 call assert_notequal(attrs[0], attrs[6]) | |
314 call assert_notequal(attrs[6], attrs[7]) | |
315 call assert_notequal(attrs0[0], attrs[0]) | |
316 call assert_notequal(attrs0[6], attrs[6]) | |
317 | |
318 if IsColorable() | |
319 " bg-color | |
320 exe hi_bg | |
321 | |
322 " expected: | |
323 " 'aaabcd ' | |
324 " ^^^^^^ bg-color of 'CursorLine' | |
325 " ^ 'Search' highlight | |
326 " ^^^ bg-color of 'CursorLine' | |
327 let attrs = ScreenAttrs(1, 10)[0] | |
328 call assert_equal(repeat([attrs[0]], 6), attrs[0:5]) | |
329 call assert_equal(repeat([attrs[7]], 3), attrs[7:9]) | |
330 call assert_equal(attrs0[6], attrs[6]) | |
331 call assert_notequal(attrs[0], attrs[6]) | |
332 call assert_notequal(attrs[6], attrs[7]) | |
333 call assert_notequal(attrs0[0], attrs[0]) | |
334 call assert_notequal(attrs0[7], attrs[7]) | |
335 endif | |
336 | |
337 call CloseWindow() | |
338 exe hiCursorLine | |
339 endfunc | |
340 | |
341 func Test_highlight_eol_with_cursorline_sign() | |
342 if !has('signs') | |
343 return | |
344 endif | |
345 | |
346 let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine() | |
347 | |
348 call NewWindow('topleft 5', 10) | |
349 call setline(1, 'abcd') | |
350 call matchadd('Search', '\n') | |
351 | |
352 sign define Sign text=>> | |
353 exe 'sign place 1 line=1 name=Sign buffer=' . bufnr('') | |
354 let attrs0 = ScreenAttrs(1, 10)[0] | |
355 setlocal cursorline | |
356 | |
357 " underline | |
358 exe hi_ul | |
359 | |
360 " expected: | |
361 " '>>abcd ' | |
362 " ^^ sign | |
363 " ^^^^ underline | |
364 " ^ 'Search' highlight with underline | |
365 " ^^^ underline | |
366 let attrs = ScreenAttrs(1, 10)[0] | |
367 call assert_equal(repeat([attrs[2]], 4), attrs[2:5]) | |
368 call assert_equal([attrs[6]] + repeat([attrs[7]], 3), attrs[6:9]) | |
369 call assert_notequal(attrs[2], attrs[6]) | |
370 call assert_notequal(attrs[6], attrs[7]) | |
371 call assert_notequal(attrs0[2], attrs[2]) | |
372 call assert_notequal(attrs0[6], attrs[6]) | |
373 | |
374 if IsColorable() | |
375 " bg-color | |
376 exe hi_bg | |
377 | |
378 " expected: | |
379 " '>>abcd ' | |
380 " ^^ sign | |
381 " ^^^^ bg-color of 'CursorLine' | |
382 " ^ 'Search' highlight | |
383 " ^^^ bg-color of 'CursorLine' | |
384 let attrs = ScreenAttrs(1, 10)[0] | |
385 call assert_equal(repeat([attrs[2]], 4), attrs[2:5]) | |
386 call assert_equal(repeat([attrs[7]], 3), attrs[7:9]) | |
387 call assert_equal(attrs0[6], attrs[6]) | |
388 call assert_notequal(attrs[2], attrs[6]) | |
389 call assert_notequal(attrs[6], attrs[7]) | |
390 call assert_notequal(attrs0[2], attrs[2]) | |
391 call assert_notequal(attrs0[7], attrs[7]) | |
392 endif | |
393 | |
394 sign unplace 1 | |
395 call CloseWindow() | |
396 exe hiCursorLine | |
397 endfunc | |
398 | |
399 func Test_highlight_eol_with_cursorline_breakindent() | |
400 if !has('linebreak') | |
401 return | |
402 endif | |
403 | |
404 let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine() | |
405 | |
406 call NewWindow('topleft 5', 10) | |
407 setlocal breakindent breakindentopt=min:0,shift:1 showbreak=> | |
408 call setline(1, ' ' . repeat('a', 9) . 'bcd') | |
409 call matchadd('Search', '\n') | |
410 let attrs0 = ScreenAttrs(2, 10)[0] | |
411 setlocal cursorline | |
412 | |
413 " underline | |
414 exe hi_ul | |
415 | |
416 " expected: | |
417 " ' >bcd ' | |
418 " ^^^ breakindent and showbreak | |
419 " ^^^ underline | |
420 " ^ 'Search' highlight with underline | |
421 " ^^^ underline | |
422 let attrs = ScreenAttrs(2, 10)[0] | |
423 call assert_equal(repeat([attrs[0]], 2), attrs[0:1]) | |
424 call assert_equal(repeat([attrs[3]], 3), attrs[3:5]) | |
425 call assert_equal([attrs[6]] + repeat([attrs[7]], 3), attrs[6:9]) | |
426 call assert_equal(attrs0[0], attrs[0]) | |
427 call assert_notequal(attrs[0], attrs[2]) | |
428 call assert_notequal(attrs[2], attrs[3]) | |
429 call assert_notequal(attrs[3], attrs[6]) | |
430 call assert_notequal(attrs[6], attrs[7]) | |
431 call assert_notequal(attrs0[2], attrs[2]) | |
432 call assert_notequal(attrs0[3], attrs[3]) | |
433 call assert_notequal(attrs0[6], attrs[6]) | |
434 | |
435 if IsColorable() | |
436 " bg-color | |
437 exe hi_bg | |
438 | |
439 " expected: | |
440 " ' >bcd ' | |
441 " ^^^ breakindent and showbreak | |
442 " ^^^ bg-color of 'CursorLine' | |
443 " ^ 'Search' highlight | |
444 " ^^^ bg-color of 'CursorLine' | |
445 let attrs = ScreenAttrs(2, 10)[0] | |
446 call assert_equal(repeat([attrs[0]], 2), attrs[0:1]) | |
447 call assert_equal(repeat([attrs[3]], 3), attrs[3:5]) | |
448 call assert_equal(repeat([attrs[7]], 3), attrs[7:9]) | |
449 call assert_equal(attrs0[0], attrs[0]) | |
450 call assert_equal(attrs0[6], attrs[6]) | |
451 call assert_notequal(attrs[0], attrs[2]) | |
452 call assert_notequal(attrs[2], attrs[3]) | |
453 call assert_notequal(attrs[3], attrs[6]) | |
454 call assert_notequal(attrs[6], attrs[7]) | |
455 call assert_notequal(attrs0[2], attrs[2]) | |
456 call assert_notequal(attrs0[3], attrs[3]) | |
457 call assert_notequal(attrs0[7], attrs[7]) | |
458 endif | |
459 | |
460 call CloseWindow() | |
461 set showbreak= | |
462 exe hiCursorLine | |
463 endfunc | |
464 | |
465 func Test_highlight_eol_on_diff() | |
466 call setline(1, ['abcd', '']) | |
467 call matchadd('Search', '\n') | |
468 let attrs0 = ScreenAttrs(1, 10)[0] | |
469 | |
470 diffthis | |
471 botright new | |
472 diffthis | |
473 | |
474 " expected: | |
475 " ' abcd ' | |
476 " ^^ sign | |
477 " ^^^^ ^^^ 'DiffAdd' highlight | |
478 " ^ 'Search' highlight | |
479 let attrs = ScreenAttrs(1, 10)[0] | |
480 call assert_equal(repeat([attrs[0]], 2), attrs[0:1]) | |
481 call assert_equal(repeat([attrs[2]], 4), attrs[2:5]) | |
482 call assert_equal(repeat([attrs[2]], 3), attrs[7:9]) | |
483 call assert_equal(attrs0[4], attrs[6]) | |
484 call assert_notequal(attrs[0], attrs[2]) | |
485 call assert_notequal(attrs[0], attrs[6]) | |
486 call assert_notequal(attrs[2], attrs[6]) | |
487 | |
488 bwipe! | |
489 diffoff | |
490 endfunc |