1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
|
" Tests for ":highlight" and highlighting.
source view_util.vim
source screendump.vim
func Test_highlight()
" basic test if ":highlight" doesn't crash
highlight
hi Search
" test setting colors.
" test clearing one color and all doesn't generate error or warning
silent! hi NewGroup term=bold cterm=italic ctermfg=DarkBlue ctermbg=Grey gui= guifg=#00ff00 guibg=Cyan
silent! hi Group2 term= cterm=
hi Group3 term=underline cterm=bold
let res = split(execute("hi NewGroup"), "\n")[0]
" filter ctermfg and ctermbg, the numbers depend on the terminal
let res = substitute(res, 'ctermfg=\d*', 'ctermfg=2', '')
let res = substitute(res, 'ctermbg=\d*', 'ctermbg=3', '')
call assert_equal("NewGroup xxx term=bold cterm=italic ctermfg=2 ctermbg=3",
\ res)
call assert_equal("Group2 xxx cleared",
\ split(execute("hi Group2"), "\n")[0])
call assert_equal("Group3 xxx term=underline cterm=bold",
\ split(execute("hi Group3"), "\n")[0])
hi clear NewGroup
call assert_equal("NewGroup xxx cleared",
\ split(execute("hi NewGroup"), "\n")[0])
call assert_equal("Group2 xxx cleared",
\ split(execute("hi Group2"), "\n")[0])
hi Group2 NONE
call assert_equal("Group2 xxx cleared",
\ split(execute("hi Group2"), "\n")[0])
hi clear
call assert_equal("Group3 xxx cleared",
\ split(execute("hi Group3"), "\n")[0])
call assert_fails("hi Crash term='asdf", "E475:")
endfunc
func HighlightArgs(name)
return 'hi ' . substitute(split(execute('hi ' . a:name), '\n')[0], '\<xxx\>', '', '')
endfunc
func IsColorable()
return has('gui_running') || str2nr(&t_Co) >= 8
endfunc
func HiCursorLine()
let hiCursorLine = HighlightArgs('CursorLine')
if has('gui_running')
let guibg = matchstr(hiCursorLine, 'guibg=\w\+')
let hi_ul = 'hi CursorLine gui=underline guibg=NONE'
let hi_bg = 'hi CursorLine gui=NONE ' . guibg
else
let hi_ul = 'hi CursorLine cterm=underline ctermbg=NONE'
let hi_bg = 'hi CursorLine cterm=NONE ctermbg=Gray'
endif
return [hiCursorLine, hi_ul, hi_bg]
endfunc
func Check_lcs_eol_attrs(attrs, row, col)
let save_lcs = &lcs
set list
call assert_equal(a:attrs, ScreenAttrs(a:row, a:col)[0])
set nolist
let &lcs = save_lcs
endfunc
func Test_highlight_eol_with_cursorline()
let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine()
call NewWindow('topleft 5', 20)
call setline(1, 'abcd')
call matchadd('Search', '\n')
" expected:
" 'abcd '
" ^^^^ ^^^^^ no highlight
" ^ 'Search' highlight
let attrs0 = ScreenAttrs(1, 10)[0]
call assert_equal(repeat([attrs0[0]], 4), attrs0[0:3])
call assert_equal(repeat([attrs0[0]], 5), attrs0[5:9])
call assert_notequal(attrs0[0], attrs0[4])
setlocal cursorline
" underline
exe hi_ul
" expected:
" 'abcd '
" ^^^^ underline
" ^ 'Search' highlight with underline
" ^^^^^ underline
let attrs = ScreenAttrs(1, 10)[0]
call assert_equal(repeat([attrs[0]], 4), attrs[0:3])
call assert_equal([attrs[4]] + repeat([attrs[5]], 5), attrs[4:9])
call assert_notequal(attrs[0], attrs[4])
call assert_notequal(attrs[4], attrs[5])
call assert_notequal(attrs0[0], attrs[0])
call assert_notequal(attrs0[4], attrs[4])
call Check_lcs_eol_attrs(attrs, 1, 10)
if IsColorable()
" bg-color
exe hi_bg
" expected:
" 'abcd '
" ^^^^ bg-color of 'CursorLine'
" ^ 'Search' highlight
" ^^^^^ bg-color of 'CursorLine'
let attrs = ScreenAttrs(1, 10)[0]
call assert_equal(repeat([attrs[0]], 4), attrs[0:3])
call assert_equal(repeat([attrs[5]], 5), attrs[5:9])
call assert_equal(attrs0[4], attrs[4])
call assert_notequal(attrs[0], attrs[4])
call assert_notequal(attrs[4], attrs[5])
call assert_notequal(attrs0[0], attrs[0])
call assert_notequal(attrs0[5], attrs[5])
call Check_lcs_eol_attrs(attrs, 1, 10)
endif
call CloseWindow()
exe hiCursorLine
endfunc
func Test_highlight_eol_with_cursorline_vertsplit()
let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine()
call NewWindow('topleft 5', 5)
call setline(1, 'abcd')
call matchadd('Search', '\n')
let expected = "abcd |abcd "
let actual = ScreenLines(1, 15)[0]
call assert_equal(expected, actual)
" expected:
" 'abcd |abcd '
" ^^^^ ^^^^^^^^^ no highlight
" ^ 'Search' highlight
" ^ 'VertSplit' highlight
let attrs0 = ScreenAttrs(1, 15)[0]
call assert_equal(repeat([attrs0[0]], 4), attrs0[0:3])
call assert_equal(repeat([attrs0[0]], 9), attrs0[6:14])
call assert_notequal(attrs0[0], attrs0[4])
call assert_notequal(attrs0[0], attrs0[5])
call assert_notequal(attrs0[4], attrs0[5])
setlocal cursorline
" expected:
" 'abcd |abcd '
" ^^^^ underline
" ^ 'Search' highlight with underline
" ^ 'VertSplit' highlight
" ^^^^^^^^^ no highlight
" underline
exe hi_ul
let actual = ScreenLines(1, 15)[0]
call assert_equal(expected, actual)
let attrs = ScreenAttrs(1, 15)[0]
call assert_equal(repeat([attrs[0]], 4), attrs[0:3])
call assert_equal(repeat([attrs[6]], 9), attrs[6:14])
call assert_equal(attrs0[5:14], attrs[5:14])
call assert_notequal(attrs[0], attrs[4])
call assert_notequal(attrs[0], attrs[5])
call assert_notequal(attrs[0], attrs[6])
call assert_notequal(attrs[4], attrs[5])
call assert_notequal(attrs[5], attrs[6])
call assert_notequal(attrs0[0], attrs[0])
call assert_notequal(attrs0[4], attrs[4])
call Check_lcs_eol_attrs(attrs, 1, 15)
if IsColorable()
" bg-color
exe hi_bg
let actual = ScreenLines(1, 15)[0]
call assert_equal(expected, actual)
let attrs = ScreenAttrs(1, 15)[0]
call assert_equal(repeat([attrs[0]], 4), attrs[0:3])
call assert_equal(repeat([attrs[6]], 9), attrs[6:14])
call assert_equal(attrs0[5:14], attrs[5:14])
call assert_notequal(attrs[0], attrs[4])
call assert_notequal(attrs[0], attrs[5])
call assert_notequal(attrs[0], attrs[6])
call assert_notequal(attrs[4], attrs[5])
call assert_notequal(attrs[5], attrs[6])
call assert_notequal(attrs0[0], attrs[0])
call assert_equal(attrs0[4], attrs[4])
call Check_lcs_eol_attrs(attrs, 1, 15)
endif
call CloseWindow()
exe hiCursorLine
endfunc
func Test_highlight_eol_with_cursorline_rightleft()
if !has('rightleft')
return
endif
let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine()
call NewWindow('topleft 5', 10)
setlocal rightleft
call setline(1, 'abcd')
call matchadd('Search', '\n')
let attrs0 = ScreenAttrs(1, 10)[0]
setlocal cursorline
" underline
exe hi_ul
" expected:
" ' dcba'
" ^^^^ underline
" ^ 'Search' highlight with underline
" ^^^^^ underline
let attrs = ScreenAttrs(1, 10)[0]
call assert_equal(repeat([attrs[9]], 4), attrs[6:9])
call assert_equal(repeat([attrs[4]], 5) + [attrs[5]], attrs[0:5])
call assert_notequal(attrs[9], attrs[5])
call assert_notequal(attrs[4], attrs[5])
call assert_notequal(attrs0[9], attrs[9])
call assert_notequal(attrs0[5], attrs[5])
call Check_lcs_eol_attrs(attrs, 1, 10)
if IsColorable()
" bg-color
exe hi_bg
" expected:
" ' dcba'
" ^^^^ bg-color of 'CursorLine'
" ^ 'Search' highlight
" ^^^^^ bg-color of 'CursorLine'
let attrs = ScreenAttrs(1, 10)[0]
call assert_equal(repeat([attrs[9]], 4), attrs[6:9])
call assert_equal(repeat([attrs[4]], 5), attrs[0:4])
call assert_equal(attrs0[5], attrs[5])
call assert_notequal(attrs[9], attrs[5])
call assert_notequal(attrs[5], attrs[4])
call assert_notequal(attrs0[9], attrs[9])
call assert_notequal(attrs0[4], attrs[4])
call Check_lcs_eol_attrs(attrs, 1, 10)
endif
call CloseWindow()
exe hiCursorLine
endfunc
func Test_highlight_eol_with_cursorline_linewrap()
let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine()
call NewWindow('topleft 5', 10)
call setline(1, [repeat('a', 51) . 'bcd', ''])
call matchadd('Search', '\n')
setlocal wrap
normal! gg$
let attrs0 = ScreenAttrs(5, 10)[0]
setlocal cursorline
" underline
exe hi_ul
" expected:
" 'abcd '
" ^^^^ underline
" ^ 'Search' highlight with underline
" ^^^^^ underline
let attrs = ScreenAttrs(5, 10)[0]
call assert_equal(repeat([attrs[0]], 4), attrs[0:3])
call assert_equal([attrs[4]] + repeat([attrs[5]], 5), attrs[4:9])
call assert_notequal(attrs[0], attrs[4])
call assert_notequal(attrs[4], attrs[5])
call assert_notequal(attrs0[0], attrs[0])
call assert_notequal(attrs0[4], attrs[4])
call Check_lcs_eol_attrs(attrs, 5, 10)
if IsColorable()
" bg-color
exe hi_bg
" expected:
" 'abcd '
" ^^^^ bg-color of 'CursorLine'
" ^ 'Search' highlight
" ^^^^^ bg-color of 'CursorLine'
let attrs = ScreenAttrs(5, 10)[0]
call assert_equal(repeat([attrs[0]], 4), attrs[0:3])
call assert_equal(repeat([attrs[5]], 5), attrs[5:9])
call assert_equal(attrs0[4], attrs[4])
call assert_notequal(attrs[0], attrs[4])
call assert_notequal(attrs[4], attrs[5])
call assert_notequal(attrs0[0], attrs[0])
call assert_notequal(attrs0[5], attrs[5])
call Check_lcs_eol_attrs(attrs, 5, 10)
endif
setlocal nocursorline nowrap
normal! gg$
let attrs0 = ScreenAttrs(1, 10)[0]
setlocal cursorline
" underline
exe hi_ul
" expected:
" 'aaabcd '
" ^^^^^^ underline
" ^ 'Search' highlight with underline
" ^^^ underline
let attrs = ScreenAttrs(1, 10)[0]
call assert_equal(repeat([attrs[0]], 6), attrs[0:5])
call assert_equal([attrs[6]] + repeat([attrs[7]], 3), attrs[6:9])
call assert_notequal(attrs[0], attrs[6])
call assert_notequal(attrs[6], attrs[7])
call assert_notequal(attrs0[0], attrs[0])
call assert_notequal(attrs0[6], attrs[6])
call Check_lcs_eol_attrs(attrs, 1, 10)
if IsColorable()
" bg-color
exe hi_bg
" expected:
" 'aaabcd '
" ^^^^^^ bg-color of 'CursorLine'
" ^ 'Search' highlight
" ^^^ bg-color of 'CursorLine'
let attrs = ScreenAttrs(1, 10)[0]
call assert_equal(repeat([attrs[0]], 6), attrs[0:5])
call assert_equal(repeat([attrs[7]], 3), attrs[7:9])
call assert_equal(attrs0[6], attrs[6])
call assert_notequal(attrs[0], attrs[6])
call assert_notequal(attrs[6], attrs[7])
call assert_notequal(attrs0[0], attrs[0])
call assert_notequal(attrs0[7], attrs[7])
call Check_lcs_eol_attrs(attrs, 1, 10)
endif
call CloseWindow()
exe hiCursorLine
endfunc
func Test_highlight_eol_with_cursorline_sign()
if !has('signs')
return
endif
let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine()
call NewWindow('topleft 5', 10)
call setline(1, 'abcd')
call matchadd('Search', '\n')
sign define Sign text=>>
exe 'sign place 1 line=1 name=Sign buffer=' . bufnr('')
let attrs0 = ScreenAttrs(1, 10)[0]
setlocal cursorline
" underline
exe hi_ul
" expected:
" '>>abcd '
" ^^ sign
" ^^^^ underline
" ^ 'Search' highlight with underline
" ^^^ underline
let attrs = ScreenAttrs(1, 10)[0]
call assert_equal(repeat([attrs[2]], 4), attrs[2:5])
call assert_equal([attrs[6]] + repeat([attrs[7]], 3), attrs[6:9])
call assert_notequal(attrs[2], attrs[6])
call assert_notequal(attrs[6], attrs[7])
call assert_notequal(attrs0[2], attrs[2])
call assert_notequal(attrs0[6], attrs[6])
call Check_lcs_eol_attrs(attrs, 1, 10)
if IsColorable()
" bg-color
exe hi_bg
" expected:
" '>>abcd '
" ^^ sign
" ^^^^ bg-color of 'CursorLine'
" ^ 'Search' highlight
" ^^^ bg-color of 'CursorLine'
let attrs = ScreenAttrs(1, 10)[0]
call assert_equal(repeat([attrs[2]], 4), attrs[2:5])
call assert_equal(repeat([attrs[7]], 3), attrs[7:9])
call assert_equal(attrs0[6], attrs[6])
call assert_notequal(attrs[2], attrs[6])
call assert_notequal(attrs[6], attrs[7])
call assert_notequal(attrs0[2], attrs[2])
call assert_notequal(attrs0[7], attrs[7])
call Check_lcs_eol_attrs(attrs, 1, 10)
endif
sign unplace 1
call CloseWindow()
exe hiCursorLine
endfunc
func Test_highlight_eol_with_cursorline_breakindent()
if !has('linebreak')
return
endif
let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine()
call NewWindow('topleft 5', 10)
setlocal breakindent breakindentopt=min:0,shift:1 showbreak=>
call setline(1, ' ' . repeat('a', 9) . 'bcd')
call matchadd('Search', '\n')
let attrs0 = ScreenAttrs(2, 10)[0]
setlocal cursorline
" underline
exe hi_ul
" expected:
" ' >bcd '
" ^^^ breakindent and showbreak
" ^^^ underline
" ^ 'Search' highlight with underline
" ^^^ underline
let attrs = ScreenAttrs(2, 10)[0]
call assert_equal(repeat([attrs[0]], 2), attrs[0:1])
call assert_equal(repeat([attrs[3]], 3), attrs[3:5])
call assert_equal([attrs[6]] + repeat([attrs[7]], 3), attrs[6:9])
call assert_equal(attrs0[0], attrs[0])
call assert_notequal(attrs[0], attrs[2])
call assert_notequal(attrs[2], attrs[3])
call assert_notequal(attrs[3], attrs[6])
call assert_notequal(attrs[6], attrs[7])
call assert_notequal(attrs0[2], attrs[2])
call assert_notequal(attrs0[3], attrs[3])
call assert_notequal(attrs0[6], attrs[6])
call Check_lcs_eol_attrs(attrs, 2, 10)
if IsColorable()
" bg-color
exe hi_bg
" expected:
" ' >bcd '
" ^^^ breakindent and showbreak
" ^^^ bg-color of 'CursorLine'
" ^ 'Search' highlight
" ^^^ bg-color of 'CursorLine'
let attrs = ScreenAttrs(2, 10)[0]
call assert_equal(repeat([attrs[0]], 2), attrs[0:1])
call assert_equal(repeat([attrs[3]], 3), attrs[3:5])
call assert_equal(repeat([attrs[7]], 3), attrs[7:9])
call assert_equal(attrs0[0], attrs[0])
call assert_equal(attrs0[6], attrs[6])
call assert_notequal(attrs[0], attrs[2])
call assert_notequal(attrs[2], attrs[3])
call assert_notequal(attrs[3], attrs[6])
call assert_notequal(attrs[6], attrs[7])
call assert_notequal(attrs0[2], attrs[2])
call assert_notequal(attrs0[3], attrs[3])
call assert_notequal(attrs0[7], attrs[7])
call Check_lcs_eol_attrs(attrs, 2, 10)
endif
call CloseWindow()
set showbreak=
exe hiCursorLine
endfunc
func Test_highlight_eol_on_diff()
call setline(1, ['abcd', ''])
call matchadd('Search', '\n')
let attrs0 = ScreenAttrs(1, 10)[0]
diffthis
botright new
diffthis
" expected:
" ' abcd '
" ^^ sign
" ^^^^ ^^^ 'DiffAdd' highlight
" ^ 'Search' highlight
let attrs = ScreenAttrs(1, 10)[0]
call assert_equal(repeat([attrs[0]], 2), attrs[0:1])
call assert_equal(repeat([attrs[2]], 4), attrs[2:5])
call assert_equal(repeat([attrs[2]], 3), attrs[7:9])
call assert_equal(attrs0[4], attrs[6])
call assert_notequal(attrs[0], attrs[2])
call assert_notequal(attrs[0], attrs[6])
call assert_notequal(attrs[2], attrs[6])
call Check_lcs_eol_attrs(attrs, 1, 10)
bwipe!
diffoff
endfunc
func Test_termguicolors()
if !exists('+termguicolors')
return
endif
if has('vtp') && !has('vcon')
" Win32: 'guicolors' doesn't work without virtual console.
call assert_fails('set termguicolors', 'E954:')
return
endif
" Basic test that setting 'termguicolors' works with one color.
set termguicolors
redraw
set t_Co=1
redraw
set t_Co=0
redraw
endfunc
func Test_cursorline_after_yank()
if !CanRunVimInTerminal()
return
endif
call writefile([
\ 'set cul rnu',
\ 'call setline(1, ["","1","2","3",""])',
\ ], 'Xtest_cursorline_yank')
let buf = RunVimInTerminal('-S Xtest_cursorline_yank', {'rows': 8})
call term_wait(buf)
call term_sendkeys(buf, "Gy3k")
call term_wait(buf)
call term_sendkeys(buf, "jj")
call VerifyScreenDump(buf, 'Test_cursorline_yank_01', {})
" clean up
call StopVimInTerminal(buf)
call delete('Xtest_cursorline_yank')
endfunc
|