aboutsummaryrefslogtreecommitdiff
path: root/test/functional/ui/highlight_spec.lua
blob: cc66345850b48e51f12f22ae57fd34b4fc122526 (plain) (blame)
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
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen')
local os = require('os')
local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert
local command, exec = helpers.command, helpers.exec
local eval = helpers.eval
local feed_command, eq = helpers.feed_command, helpers.eq
local curbufmeths = helpers.curbufmeths
local funcs = helpers.funcs
local meths = helpers.meths
local exec_lua = helpers.exec_lua

describe('colorscheme compatibility', function()
  before_each(function()
    clear()
  end)

  it('&t_Co exists and is set to 256 by default', function()
    eq(1, funcs.exists('&t_Co'))
    eq(1, funcs.exists('+t_Co'))
    eq('256', eval('&t_Co'))
  end)
end)

describe('highlight: `:syntax manual`', function()
  -- When using manual syntax highlighting, it should be preserved even when
  -- switching buffers... bug did only occur without :set hidden
  -- Ref: vim patch 7.4.1236
  local screen

  before_each(function()
    clear()
    screen = Screen.new(20,5)
    screen:attach()
    --syntax highlight for vimcscripts "echo"
    screen:set_default_attr_ids( {
      [0] = {bold=true, foreground=Screen.colors.Blue},
      [1] = {bold=true, foreground=Screen.colors.Brown}
    } )
  end)

  after_each(function()
    os.remove('Xtest-functional-ui-highlight.tmp.vim')
  end)

  it("works with buffer switch and 'hidden'", function()
    command('e tmp1.vim')
    command('e Xtest-functional-ui-highlight.tmp.vim')
    command('filetype on')
    command('syntax manual')
    command('set ft=vim')
    command('set syntax=ON')
    feed('iecho 1<esc>0')

    command('set hidden')
    command('w')
    command('bn')
    feed_command('bp')
    screen:expect([[
      {1:^echo} 1              |
      {0:~                   }|
      {0:~                   }|
      {0:~                   }|
      :bp                 |
    ]])
  end)

  it("works with buffer switch and 'nohidden'", function()
    command('e tmp1.vim')
    command('e Xtest-functional-ui-highlight.tmp.vim')
    command('filetype on')
    command('syntax manual')
    command('set filetype=vim fileformat=unix')
    command('set syntax=ON')
    feed('iecho 1<esc>0')

    command('set nohidden')
    command('w')
    command('silent bn')
    eq("tmp1.vim", eval("fnamemodify(bufname('%'), ':t')"))
    feed_command('silent bp')
    eq("Xtest-functional-ui-highlight.tmp.vim", eval("fnamemodify(bufname('%'), ':t')"))
    screen:expect([[
      {1:^echo} 1              |
      {0:~                   }|
      {0:~                   }|
      {0:~                   }|
      :silent bp          |
    ]])
  end)
end)


describe('highlight defaults', function()
  local screen

  before_each(function()
    clear()
    screen = Screen.new()
    screen:set_default_attr_ids {
      [0] = {bold=true, foreground=Screen.colors.Blue};
      [1] = {reverse = true, bold = true};
      [2] = {reverse = true};
      [3] = {bold = true};
      [4] = {bold = true, foreground = Screen.colors.SeaGreen};
      [5] = {foreground = Screen.colors.Red1, background = Screen.colors.WebGreen};
      [6] = {background = Screen.colors.Red1, foreground = Screen.colors.Grey100};
      [7] = {foreground = Screen.colors.Red};
      [8] = {foreground = Screen.colors.Blue};
      [9] = {italic = true};
    }
    screen:attach()
  end)

  it('window status bar', function()
    feed_command('sp', 'vsp', 'vsp')
    screen:expect([[
      ^                    │                │               |
      {0:~                   }│{0:~               }│{0:~              }|
      {0:~                   }│{0:~               }│{0:~              }|
      {0:~                   }│{0:~               }│{0:~              }|
      {0:~                   }│{0:~               }│{0:~              }|
      {0:~                   }│{0:~               }│{0:~              }|
      {1:[No Name]            }{2:[No Name]        [No Name]      }|
                                                           |
      {0:~                                                    }|
      {0:~                                                    }|
      {0:~                                                    }|
      {0:~                                                    }|
      {2:[No Name]                                            }|
      :vsp                                                 |
    ]])
    -- navigate to verify that the attributes are properly moved
    feed('<c-w>j')
    screen:expect([[
                          │                │               |
      {0:~                   }│{0:~               }│{0:~              }|
      {0:~                   }│{0:~               }│{0:~              }|
      {0:~                   }│{0:~               }│{0:~              }|
      {0:~                   }│{0:~               }│{0:~              }|
      {0:~                   }│{0:~               }│{0:~              }|
      {2:[No Name]            [No Name]        [No Name]      }|
      ^                                                     |
      {0:~                                                    }|
      {0:~                                                    }|
      {0:~                                                    }|
      {0:~                                                    }|
      {1:[No Name]                                            }|
      :vsp                                                 |
    ]])
    -- note that when moving to a window with small width nvim will increase
    -- the width of the new active window at the expense of a inactive window
    -- (upstream vim has the same behavior)
    feed('<c-w>k<c-w>l')
    screen:expect([[
                          │^                    │           |
      {0:~                   }│{0:~                   }│{0:~          }|
      {0:~                   }│{0:~                   }│{0:~          }|
      {0:~                   }│{0:~                   }│{0:~          }|
      {0:~                   }│{0:~                   }│{0:~          }|
      {0:~                   }│{0:~                   }│{0:~          }|
      {2:[No Name]            }{1:[No Name]            }{2:[No Name]  }|
                                                           |
      {0:~                                                    }|
      {0:~                                                    }|
      {0:~                                                    }|
      {0:~                                                    }|
      {2:[No Name]                                            }|
      :vsp                                                 |
    ]])
    feed('<c-w>l')
    screen:expect([[
                          │           │^                    |
      {0:~                   }│{0:~          }│{0:~                   }|
      {0:~                   }│{0:~          }│{0:~                   }|
      {0:~                   }│{0:~          }│{0:~                   }|
      {0:~                   }│{0:~          }│{0:~                   }|
      {0:~                   }│{0:~          }│{0:~                   }|
      {2:[No Name]            [No Name]   }{1:[No Name]           }|
                                                           |
      {0:~                                                    }|
      {0:~                                                    }|
      {0:~                                                    }|
      {0:~                                                    }|
      {2:[No Name]                                            }|
      :vsp                                                 |
    ]])
    feed('<c-w>h<c-w>h')
    screen:expect([[
      ^                    │                    │           |
      {0:~                   }│{0:~                   }│{0:~          }|
      {0:~                   }│{0:~                   }│{0:~          }|
      {0:~                   }│{0:~                   }│{0:~          }|
      {0:~                   }│{0:~                   }│{0:~          }|
      {0:~                   }│{0:~                   }│{0:~          }|
      {1:[No Name]            }{2:[No Name]            [No Name]  }|
                                                           |
      {0:~                                                    }|
      {0:~                                                    }|
      {0:~                                                    }|
      {0:~                                                    }|
      {2:[No Name]                                            }|
      :vsp                                                 |
    ]])
  end)

  it('insert mode text', function()
    feed('i')
    screen:try_resize(53, 4)
    screen:expect([[
      ^                                                     |
      {0:~                                                    }|
      {0:~                                                    }|
      {3:-- INSERT --}                                         |
    ]])
  end)

  it('end of file markers', function()
    screen:try_resize(53, 4)
    screen:expect([[
      ^                                                     |
      {0:~                                                    }|
      {0:~                                                    }|
                                                           |
    ]])
  end)

  it('"wait return" text', function()
    screen:try_resize(53, 4)
    feed(':ls<cr>')
    screen:expect([[
      {1:                                                     }|
      :ls                                                  |
        1 %a   "[No Name]"                    line 1       |
      {4:Press ENTER or type command to continue}^              |
    ]])
    feed('<cr>') --  skip the "Press ENTER..." state or tests will hang
  end)

  it('can be cleared and linked to other highlight groups', function()
    screen:try_resize(53, 4)
    feed_command('highlight clear ModeMsg')
    feed('i')
    screen:expect([[
      ^                                                     |
      {0:~                                                    }|
      {0:~                                                    }|
      -- INSERT --                                         |
    ]])
    feed('<esc>')
    feed_command('highlight CustomHLGroup guifg=red guibg=green')
    feed_command('highlight link ModeMsg CustomHLGroup')
    feed('i')
    screen:expect([[
      ^                                                     |
      {0:~                                                    }|
      {0:~                                                    }|
      {5:-- INSERT --}                                         |
    ]])
  end)

  it('can be cleared by assigning NONE', function()
    screen:try_resize(53, 4)
    feed_command('syn keyword TmpKeyword neovim')
    feed_command('hi link TmpKeyword ErrorMsg')
    insert('neovim')
    screen:expect([[
      {6:neovi^m}                                               |
      {0:~                                                    }|
      {0:~                                                    }|
                                                           |
    ]])
    feed_command("hi ErrorMsg term=NONE cterm=NONE ctermfg=NONE ctermbg=NONE"
            .. " gui=NONE guifg=NONE guibg=NONE guisp=NONE")
    screen:expect([[
      neovi^m                                               |
      {0:~                                                    }|
      {0:~                                                    }|
                                                           |
    ]])
  end)

  it('linking updates window highlight immediately #16552', function()
    screen:try_resize(53, 4)
    screen:expect([[
      ^                                                     |
      {0:~                                                    }|
      {0:~                                                    }|
                                                           |
    ]])
    feed_command("hi NonTextAlt guifg=Red")
    feed_command("hi! link NonText NonTextAlt")
    screen:expect([[
      ^                                                     |
      {0:~                                                    }|
      {0:~                                                    }|
      :hi! link NonText NonTextAlt                         |
    ]], {[0] = {foreground=Screen.colors.Red}})
  end)

  it('Cursor after `:hi clear|syntax reset` #6508', function()
    command('highlight clear|syntax reset')
    eq('guifg=bg guibg=fg', eval([[matchstr(execute('hi Cursor'), '\v(gui|cterm).*$')]]))
  end)

  it('Whitespace highlight', function()
    screen:try_resize(53, 4)
    feed_command('highlight NonText gui=NONE guifg=#FF0000')
    feed_command('set listchars=space:.,tab:>-,trail:*,eol:¬ list')
    insert('   ne \t o\tv  im  ')
    screen:expect([[
      ne{7:.>----.}o{7:>-----}v{7:..}im{7:*^*¬}                             |
      {7:~                                                    }|
      {7:~                                                    }|
                                                           |
    ]])
    feed_command('highlight Whitespace gui=NONE guifg=#0000FF')
    screen:expect([[
      ne{8:.>----.}o{8:>-----}v{8:..}im{8:*^*}{7:¬}                             |
      {7:~                                                    }|
      {7:~                                                    }|
      :highlight Whitespace gui=NONE guifg=#0000FF         |
    ]])
  end)

  it('are sent to UIs', function()
    screen:try_resize(53, 4)
    screen:expect{grid=[[
      ^                                                     |
      {0:~                                                    }|
      {0:~                                                    }|
                                                           |
    ]], hl_groups={EndOfBuffer=0, MsgSeparator=1}}

    command('highlight EndOfBuffer gui=italic')
    screen:expect{grid=[[
      ^                                                     |
      {9:~                                                    }|
      {9:~                                                    }|
                                                           |
    ]], hl_groups={EndOfBuffer=9, MsgSeparator=1}}

    command('highlight clear EndOfBuffer')
    screen:expect{grid=[[
      ^                                                     |
      {0:~                                                    }|
      {0:~                                                    }|
                                                           |
    ]], hl_groups={EndOfBuffer=0, MsgSeparator=1}}
  end)
end)

describe('highlight', function()
  before_each(clear)

  it('visual', function()
    local screen = Screen.new(20,4)
    screen:attach()
    screen:set_default_attr_ids({
      [1] = {background = Screen.colors.LightGrey},
      [2] = {bold = true, foreground = Screen.colors.Blue1},
      [3] = {bold = true},
    })
    insert([[
      line1 foo bar
    ]])

    -- Non-blinking block cursor: does NOT highlight char-at-cursor.
    command('set guicursor=a:block-blinkon0')
    feed('gg$vhhh')
    screen:expect([[
        line1 foo^ {1:bar}     |
                          |
      {2:~                   }|
      {3:-- VISUAL --}        |
    ]])

    -- Vertical cursor: highlights char-at-cursor. #8983
    command('set guicursor=a:block-blinkon175')
    screen:expect([[
        line1 foo{1:^ bar}     |
                          |
      {2:~                   }|
      {3:-- VISUAL --}        |
    ]])
  end)

  it('cterm=standout gui=standout', function()
    local screen = Screen.new(20,5)
    screen:attach()
    screen:set_default_attr_ids({
        [1] = {bold = true, foreground = Screen.colors.Blue1},
        [2] = {standout = true, bold = true, underline = true,
        background = Screen.colors.Gray90, foreground = Screen.colors.Blue1},
        [3] = {standout = true, underline = true,
        background = Screen.colors.Gray90}
    })
    feed_command('hi CursorLine cterm=standout,underline gui=standout,underline')
    feed_command('set cursorline')
    feed_command('set listchars=space:.,eol:¬,tab:>-,extends:>,precedes:<,trail:* list')
    feed('i\t abcd <cr>\t abcd <cr><esc>k')
    screen:expect([[
    {1:>-------.}abcd{1:*¬}     |
    {2:^>-------.}{3:abcd}{2:*¬}{3:     }|
    {1:¬}                   |
    {1:~                   }|
                        |
    ]])
  end)

  it('strikethrough', function()
    local screen = Screen.new(25,6)
    screen:attach()
    feed_command('syntax on')
    feed_command('syn keyword TmpKeyword foo')
    feed_command('hi! Awesome cterm=strikethrough gui=strikethrough')
    feed_command('hi link TmpKeyword Awesome')
    insert([[
      foo
      foo bar
      foobarfoobar
      ]])
    screen:expect([[
      {1:foo}                      |
      {1:foo} bar                  |
      foobarfoobar             |
      ^                         |
      {2:~                        }|
                               |
    ]], {
      [1] = {strikethrough = true},
      [2] = {bold = true, foreground = Screen.colors.Blue1},
    })
  end)

  it('nocombine', function()
    local screen = Screen.new(25,6)
    screen:set_default_attr_ids{
      [1] = {foreground = Screen.colors.SlateBlue, underline = true},
      [2] = {bold = true, foreground = Screen.colors.Blue1},
      [3] = {underline = true, reverse = true, foreground = Screen.colors.SlateBlue},
      [4] = {background = Screen.colors.Yellow, reverse = true, foreground = Screen.colors.SlateBlue},
      [5] = {foreground = Screen.colors.Red},
    }
    screen:attach()
    feed_command('syntax on')
    feed_command('hi! Underlined cterm=underline gui=underline')
    feed_command('syn keyword Underlined foobar')
    feed_command('hi Search cterm=inverse,nocombine gui=inverse,nocombine')
    insert([[
      foobar
      foobar
      ]])
    screen:expect{grid=[[
      {1:foobar}                   |
      {1:foobar}                   |
      ^                         |
      {2:~                        }|
      {2:~                        }|
                               |
    ]]}

    feed('/foo')
    screen:expect{grid=[[
      {3:foo}{1:bar}                   |
      {4:foo}{1:bar}                   |
                               |
      {2:~                        }|
      {2:~                        }|
      /foo^                     |
    ]]}
    feed('<cr>')
    screen:expect{grid=[[
      {4:^foo}{1:bar}                   |
      {4:foo}{1:bar}                   |
                               |
      {2:~                        }|
      {2:~                        }|
      {5:search hit...uing at TOP} |
    ]]}
  end)

  it('guisp (special/undercurl)', function()
    local screen = Screen.new(25,10)
    screen:attach()
    feed_command('syntax on')
    feed_command('syn keyword TmpKeyword neovim')
    feed_command('syn keyword TmpKeyword1 special')
    feed_command('syn keyword TmpKeyword2 specialwithbg')
    feed_command('syn keyword TmpKeyword3 specialwithfg')
    feed_command('hi! Awesome guifg=red guibg=yellow guisp=red')
    feed_command('hi! Awesome1 guisp=red')
    feed_command('hi! Awesome2 guibg=yellow guisp=red')
    feed_command('hi! Awesome3 guifg=red guisp=red')
    feed_command('hi link TmpKeyword Awesome')
    feed_command('hi link TmpKeyword1 Awesome1')
    feed_command('hi link TmpKeyword2 Awesome2')
    feed_command('hi link TmpKeyword3 Awesome3')
    insert([[
      neovim
      awesome neovim
      wordcontainingneovim
      special
      specialwithbg
      specialwithfg
      ]])
    feed('Go<tab>neovim tabbed')
    screen:expect([[
      {1:neovim}                   |
      awesome {1:neovim}           |
      wordcontainingneovim     |
      {2:special}                  |
      {3:specialwithbg}            |
      {4:specialwithfg}            |
                               |
              {1:neovim} tabbed^    |
      {0:~                        }|
      {5:-- INSERT --}             |
    ]], {
      [0] = {bold=true, foreground=Screen.colors.Blue},
      [1] = {background = Screen.colors.Yellow, foreground = Screen.colors.Red,
             special = Screen.colors.Red},
      [2] = {special = Screen.colors.Red},
      [3] = {special = Screen.colors.Red, background = Screen.colors.Yellow},
      [4] = {foreground = Screen.colors.Red, special = Screen.colors.Red},
      [5] = {bold=true},
    })

  end)

  it("'diff', syntax and extmark #23722", function()
    local screen = Screen.new(25,10)
    screen:attach()
    exec([[
      new
      call setline(1, ['', '01234 6789'])
      windo diffthis
      wincmd w
      syn match WarningMsg "^.*$"
      call nvim_buf_add_highlight(0, -1, 'ErrorMsg', 1, 2, 8)
    ]])
    screen:expect([[
      {1:  }^                       |
      {1:  }{2:01}{3:234 67}{2:89}{5:             }|
      {4:~                        }|
      {4:~                        }|
      {7:[No Name] [+]            }|
      {1:  }                       |
      {1:  }{6:-----------------------}|
      {4:~                        }|
      {8:[No Name]                }|
                               |
    ]], {
      [0] = {Screen.colors.WebGray, foreground = Screen.colors.DarkBlue},
      [1] = {background = Screen.colors.Grey, foreground = Screen.colors.Blue4},
      [2] = {foreground = Screen.colors.Red, background = Screen.colors.LightBlue},
      [3] = {foreground = Screen.colors.Grey100, background = Screen.colors.LightBlue},
      [4] = {bold = true, foreground = Screen.colors.Blue},
      [5] = {background = Screen.colors.LightBlue},
      [6] = {bold = true, background = Screen.colors.LightCyan, foreground = Screen.colors.Blue1},
      [7] = {reverse = true, bold = true},
      [8] = {reverse = true},
    })
  end)
end)

describe("'listchars' highlight", function()
  local screen

  before_each(function()
    clear()
    screen = Screen.new(20,5)
    screen:attach()
  end)

  it("'cursorline' and 'cursorcolumn'", function()
    screen:set_default_attr_ids({
      [0] = {bold=true, foreground=Screen.colors.Blue},
      [1] = {background=Screen.colors.Grey90}
    })
    feed_command('highlight clear ModeMsg')
    feed_command('set cursorline')
    feed('i')
    screen:expect([[
      {1:^                    }|
      {0:~                   }|
      {0:~                   }|
      {0:~                   }|
      -- INSERT --        |
    ]])
    feed('abcdefg<cr>kkasdf')
    screen:expect([[
      abcdefg             |
      {1:kkasdf^              }|
      {0:~                   }|
      {0:~                   }|
      -- INSERT --        |
    ]])
    feed('<esc>')
    screen:expect([[
      abcdefg             |
      {1:kkasd^f              }|
      {0:~                   }|
      {0:~                   }|
                          |
    ]])
    feed_command('set nocursorline')
    screen:expect([[
      abcdefg             |
      kkasd^f              |
      {0:~                   }|
      {0:~                   }|
      :set nocursorline   |
    ]])
    feed('k')
    screen:expect([[
      abcde^fg             |
      kkasdf              |
      {0:~                   }|
      {0:~                   }|
      :set nocursorline   |
    ]])
    feed('jjji<cr><cr><cr><esc>')
    screen:expect([[
      kkasd               |
                          |
                          |
      ^f                   |
                          |
    ]])
    feed_command('set cursorline')
    feed_command('set cursorcolumn')
    feed('kkiabcdefghijk<esc>hh')
    screen:expect([[
      kkasd   {1: }           |
      {1:abcdefgh^ijk         }|
              {1: }           |
      f       {1: }           |
                          |
    ]])
    feed('khh')
    screen:expect([[
      {1:kk^asd               }|
      ab{1:c}defghijk         |
        {1: }                 |
      f {1: }                 |
                          |
    ]])
  end)

  it("'cursorline' and with 'listchars' option", function()
    screen:set_default_attr_ids({
      [1] = {background=Screen.colors.Grey90},
      [2] = {
        foreground=Screen.colors.Red,
        background=Screen.colors.Grey90,
      },
      [3] = {
        background=Screen.colors.Grey90,
        foreground=Screen.colors.Blue,
        bold=true,
      },
      [4] = {
        foreground=Screen.colors.Blue,
        bold=true,
      },
      [5] = {
        foreground=Screen.colors.Red,
      },
    })
    feed_command('highlight clear ModeMsg')
    feed_command('highlight Whitespace guifg=#FF0000')
    feed_command('set cursorline')
    feed_command('set tabstop=8')
    feed_command('set listchars=space:.,eol:¬,tab:>-,extends:>,precedes:<,trail:* list')
    feed('i\t abcd <cr>\t abcd <cr><esc>k')
    screen:expect([[
      {5:>-------.}abcd{5:*}{4:¬}     |
      {2:^>-------.}{1:abcd}{2:*}{3:¬}{1:     }|
      {4:¬}                   |
      {4:~                   }|
                          |
    ]])
    feed('k')
    screen:expect([[
      {2:^>-------.}{1:abcd}{2:*}{3:¬}{1:     }|
      {5:>-------.}abcd{5:*}{4:¬}     |
      {4:¬}                   |
      {4:~                   }|
                          |
    ]])
    feed_command('set nocursorline')
    screen:expect([[
      {5:^>-------.}abcd{5:*}{4:¬}     |
      {5:>-------.}abcd{5:*}{4:¬}     |
      {4:¬}                   |
      {4:~                   }|
      :set nocursorline   |
    ]])
    feed_command('set nowrap')
    feed('ALorem ipsum dolor sit amet<ESC>0')
    screen:expect([[
      {5:^>-------.}abcd{5:.}Lorem{4:>}|
      {5:>-------.}abcd{5:*}{4:¬}     |
      {4:¬}                   |
      {4:~                   }|
                          |
    ]])
    feed_command('set cursorline')
    screen:expect([[
      {2:^>-------.}{1:abcd}{2:.}{1:Lorem}{3:>}|
      {5:>-------.}abcd{5:*}{4:¬}     |
      {4:¬}                   |
      {4:~                   }|
      :set cursorline     |
    ]])
    feed('$')
    screen:expect([[
      {3:<}{1:r}{2:.}{1:sit}{2:.}{1:ame^t}{3:¬}{1:        }|
      {4:<}                   |
      {4:<}                   |
      {4:~                   }|
      :set cursorline     |
    ]])
    feed('G')
    screen:expect([[
      {5:>-------.}abcd{5:.}Lorem{4:>}|
      {5:>-------.}abcd{5:*}{4:¬}     |
      {3:^¬}{1:                   }|
      {4:~                   }|
      :set cursorline     |
    ]])
  end)

  it("'listchar' with wrap", function()
    screen:set_default_attr_ids({
      [0] = {bold=true, foreground=Screen.colors.Blue},
    })
    feed_command('set wrap')
    feed_command('set listchars=eol:¬,precedes:< list')
    feed('90ia<esc>')
    screen:expect([[
      {0:<}aaaaaaaaaaaaaaaaaaa|
      aaaaaaaaaaaaaaaaaaaa|
      aaaaaaaaaaaaaaaaaaaa|
      aaaaaaaaa^a{0:¬}         |
                          |
    ]])
    feed('0')
    screen:expect([[
      ^aaaaaaaaaaaaaaaaaaaa|
      aaaaaaaaaaaaaaaaaaaa|
      aaaaaaaaaaaaaaaaaaaa|
      aaaaaaaaaaaaaaaaaaaa|
                          |
    ]])
  end)

  it("'listchar' in visual mode", function()
    screen:set_default_attr_ids({
      [1] = {background=Screen.colors.Grey90},
      [2] = {
        foreground=Screen.colors.Red,
        background=Screen.colors.Grey90,
      },
      [3] = {
        background=Screen.colors.Grey90,
        foreground=Screen.colors.Blue,
        bold=true,
      },
      [4] = {
        foreground=Screen.colors.Blue,
        bold=true,
      },
      [5] = {
        foreground=Screen.colors.Red,
      },
      [6] = {
        background=Screen.colors.LightGrey,
      },
      [7] = {
        background=Screen.colors.LightGrey,
        foreground=Screen.colors.Red,
      },
      [8] = {
        background=Screen.colors.LightGrey,
        foreground=Screen.colors.Blue,
        bold=true,
      },
    })
    feed_command('highlight clear ModeMsg')
    feed_command('highlight Whitespace guifg=#FF0000')
    feed_command('set cursorline')
    feed_command('set tabstop=8')
    feed_command('set nowrap')
    feed_command('set listchars=space:.,eol:¬,tab:>-,extends:>,precedes:<,trail:* list')
    feed('i\t abcd <cr>\t abcd Lorem ipsum dolor sit amet<cr><esc>kkk0')
    screen:expect([[
      {2:^>-------.}{1:abcd}{2:*}{3:¬}{1:     }|
      {5:>-------.}abcd{5:.}Lorem{4:>}|
      {4:¬}                   |
      {4:~                   }|
                          |
    ]])
    feed('lllvj')
    screen:expect([[
      {5:>-------.}a{6:bcd}{7:*}{8:¬}     |
      {7:>-------.}{6:a}^bcd{5:.}Lorem{4:>}|
      {4:¬}                   |
      {4:~                   }|
      -- VISUAL --        |
    ]])
    feed('<esc>V')
    screen:expect([[
      {5:>-------.}abcd{5:*}{4:¬}     |
      {7:>-------.}{6:a}^b{6:cd}{7:.}{6:Lorem}{4:>}|
      {4:¬}                   |
      {4:~                   }|
      -- VISUAL LINE --   |
    ]])
    feed('<esc>$')
    screen:expect([[
      {4:<}                   |
      {3:<}{1:r}{2:.}{1:sit}{2:.}{1:ame^t}{3:¬}{1:        }|
      {4:<}                   |
      {4:~                   }|
                          |
    ]])
  end)

  it("'cursorline' with :match", function()
    screen:set_default_attr_ids({
      [0] = {bold=true, foreground=Screen.colors.Blue},
      [1] = {background=Screen.colors.Grey90},
      [2] = {foreground=Screen.colors.Red},
      [3] = {foreground=Screen.colors.X11Green, background=Screen.colors.Red1},
    })
    feed_command('highlight clear ModeMsg')
    feed_command('highlight Whitespace guifg=#FF0000')
    feed_command('highlight Error guifg=#00FF00')
    feed_command('set nowrap')
    feed('ia \t bc \t  <esc>')
    screen:expect([[
      a        bc      ^   |
      {0:~                   }|
      {0:~                   }|
      {0:~                   }|
                          |
    ]])
    feed_command('set listchars=space:.,eol:¬,tab:>-,extends:>,precedes:<,trail:* list')
    screen:expect([[
      a{2:.>-----.}bc{2:*>---*^*}{0:¬} |
      {0:~                   }|
      {0:~                   }|
      {0:~                   }|
                          |
    ]])
    feed_command('match Error /\\s\\+$/')
    screen:expect([[
      a{2:.>-----.}bc{3:*>---*^*}{0:¬} |
      {0:~                   }|
      {0:~                   }|
      {0:~                   }|
                          |
    ]])
  end)
end)

describe('CursorLine and CursorLineNr highlights', function()
  before_each(clear)

  it('overridden by Error, ColorColumn if fg not set', function()
    local screen = Screen.new(50,5)
    screen:set_default_attr_ids({
      [1] = {foreground = Screen.colors.SlateBlue},
      [2] = {bold = true, foreground = Screen.colors.Brown},
      [3] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red},
      [4] = {foreground = Screen.colors.SlateBlue, background = Screen.colors.Gray90},
      [5] = {background = Screen.colors.Gray90},
      [6] = {bold = true, foreground = Screen.colors.Blue1},
      [7] = {background = Screen.colors.LightRed},
    })
    screen:attach()

    command('filetype on')
    command('syntax on')
    command('set cursorline ft=json')
    feed('i{<cr>"a" : abc // 10;<cr>}<cr><esc>')
    screen:expect([[
      {1:{}                                                 |
      "{2:a}" : {3:abc} {3:// 10;}                                  |
      {1:}}                                                 |
      {5:^                                                  }|
                                                        |
    ]])

    command('set fillchars=colorcol:.')
    command('set colorcolumn=3')
    feed('i  <esc>')
    screen:expect([[
      {1:{} {7:.}                                               |
      "{2:a}{7:"} : {3:abc} {3:// 10;}                                  |
      {1:}} {7:.}                                               |
      {5: ^ }{7:.}{5:                                               }|
                                                        |
    ]])
  end)

  it("overridden by NonText in 'showbreak' characters", function()
    local screen = Screen.new(20,5)
    screen:set_default_attr_ids({
      [1] = {foreground = Screen.colors.Yellow, background = Screen.colors.Blue};
      [2] = {foreground = Screen.colors.Black, background = Screen.colors.White};
      [3] = {foreground = Screen.colors.Yellow, background = Screen.colors.White};
      [4] = {foreground = Screen.colors.Yellow};
    })
    screen:attach()

    feed_command('set wrap cursorline')
    feed_command('set showbreak=>>>')
    feed_command('highlight clear NonText')
    feed_command('highlight clear CursorLine')
    feed_command('highlight NonText guifg=Yellow guibg=Blue gui=NONE')
    feed_command('highlight CursorLine guifg=Black guibg=White gui=NONE')

    feed('30iø<esc>o<esc>30ia<esc>')
    screen:expect([[
      øøøøøøøøøøøøøøøøøøøø|
      {1:>>>}øøøøøøøøøø       |
      {2:aaaaaaaaaaaaaaaaaaaa}|
      {1:>>>}{2:aaaaaaaaa^a       }|
                          |
    ]])
    feed('k')
    screen:expect([[
      {2:øøøøøøøøøøøøøøøøøøøø}|
      {1:>>>}{2:øøøøøøøøø^ø       }|
      aaaaaaaaaaaaaaaaaaaa|
      {1:>>>}aaaaaaaaaa       |
                          |
    ]])
    feed_command('highlight NonText guibg=NONE')
    screen:expect([[
      {2:øøøøøøøøøøøøøøøøøøøø}|
      {3:>>>}{2:øøøøøøøøø^ø       }|
      aaaaaaaaaaaaaaaaaaaa|
      {4:>>>}aaaaaaaaaa       |
                          |
    ]])
    feed_command('set nocursorline')
    screen:expect([[
      øøøøøøøøøøøøøøøøøøøø|
      {4:>>>}øøøøøøøøø^ø       |
      aaaaaaaaaaaaaaaaaaaa|
      {4:>>>}aaaaaaaaaa       |
      :set nocursorline   |
    ]])
  end)

  it("'cursorlineopt' screenline", function()
    local screen = Screen.new(20,5)
    screen:set_default_attr_ids({
      [1] = {foreground = Screen.colors.Black, background = Screen.colors.White};
      [2] = {foreground = Screen.colors.Yellow};
      [3] = {foreground = Screen.colors.Red, background = Screen.colors.Green};
      [4] = {foreground = Screen.colors.Green, background = Screen.colors.Red};
      [5] = {bold = true},  -- ModeMsg
    })
    screen:attach()

    command('set wrap cursorline cursorlineopt=screenline')
    command('set showbreak=>>>')
    command('highlight clear NonText')
    command('highlight clear CursorLine')
    command('highlight NonText guifg=Yellow gui=NONE')
    command('highlight LineNr guifg=Red guibg=Green gui=NONE')
    command('highlight CursorLine guifg=Black guibg=White gui=NONE')
    command('highlight CursorLineNr guifg=Green guibg=Red gui=NONE')

    feed('30iø<esc>o<esc>30ia<esc>')

    -- CursorLine should not apply to 'showbreak' when 'cursorlineopt' contains "screenline"
    screen:expect([[
      øøøøøøøøøøøøøøøøøøøø|
      {2:>>>}øøøøøøøøøø       |
      aaaaaaaaaaaaaaaaaaaa|
      {2:>>>}{1:aaaaaaaaa^a       }|
                          |
    ]])
    feed('gk')
    screen:expect([[
      øøøøøøøøøøøøøøøøøøøø|
      {2:>>>}øøøøøøøøøø       |
      {1:aaaaaaaaaaaa^aaaaaaaa}|
      {2:>>>}aaaaaaaaaa       |
                          |
    ]])
    feed('k')
    screen:expect([[
      {1:øøøøøøøøøøøø^øøøøøøøø}|
      {2:>>>}øøøøøøøøøø       |
      aaaaaaaaaaaaaaaaaaaa|
      {2:>>>}aaaaaaaaaa       |
                          |
    ]])

    -- CursorLineNr should not apply to line number when 'cursorlineopt' does not contain "number"
    command('set relativenumber numberwidth=2')
    screen:expect([[
      {3:0 }{1:øøøøøøøøøøøø^øøøøøø}|
      {3:  }{2:>>>}øøøøøøøøøøøø   |
      {3:1 }aaaaaaaaaaaaaaaaaa|
      {3:  }{2:>>>}aaaaaaaaaaaa   |
                          |
    ]])

    -- CursorLineNr should apply to line number when 'cursorlineopt' contains "number"
    command('set cursorlineopt+=number')
    screen:expect([[
      {4:0 }{1:øøøøøøøøøøøø^øøøøøø}|
      {3:  }{2:>>>}øøøøøøøøøøøø   |
      {3:1 }aaaaaaaaaaaaaaaaaa|
      {3:  }{2:>>>}aaaaaaaaaaaa   |
                          |
    ]])
    feed('gj')
    screen:expect([[
      {4:0 }øøøøøøøøøøøøøøøøøø|
      {3:  }{2:>>>}{1:øøøøøøøøø^øøø   }|
      {3:1 }aaaaaaaaaaaaaaaaaa|
      {3:  }{2:>>>}aaaaaaaaaaaa   |
                          |
    ]])
    feed('gj')
    screen:expect([[
      {3:1 }øøøøøøøøøøøøøøøøøø|
      {3:  }{2:>>>}øøøøøøøøøøøø   |
      {4:0 }{1:aaaaaaaaaaaa^aaaaaa}|
      {3:  }{2:>>>}aaaaaaaaaaaa   |
                          |
    ]])
    feed('gj')
    screen:expect([[
      {3:1 }øøøøøøøøøøøøøøøøøø|
      {3:  }{2:>>>}øøøøøøøøøøøø   |
      {4:0 }aaaaaaaaaaaaaaaaaa|
      {3:  }{2:>>>}{1:aaaaaaaaa^aaa   }|
                          |
    ]])

    -- updated in Insert mode
    feed('I')
    screen:expect([[
      {3:1 }øøøøøøøøøøøøøøøøøø|
      {3:  }{2:>>>}øøøøøøøøøøøø   |
      {4:0 }{1:^aaaaaaaaaaaaaaaaaa}|
      {3:  }{2:>>>}aaaaaaaaaaaa   |
      {5:-- INSERT --}        |
    ]])

    feed('<Esc>gg')
    screen:expect([[
      {4:0 }{1:^øøøøøøøøøøøøøøøøøø}|
      {3:  }{2:>>>}øøøøøøøøøøøø   |
      {3:1 }aaaaaaaaaaaaaaaaaa|
      {3:  }{2:>>>}aaaaaaaaaaaa   |
                          |
    ]])

    command('inoremap <F2> <Cmd>call cursor(1, 1)<CR>')
    feed('A')
    screen:expect([[
      {4:0 }øøøøøøøøøøøøøøøøøø|
      {3:  }{2:>>>}{1:øøøøøøøøøøøø^   }|
      {3:1 }aaaaaaaaaaaaaaaaaa|
      {3:  }{2:>>>}aaaaaaaaaaaa   |
      {5:-- INSERT --}        |
    ]])

    feed('<F2>')
    screen:expect([[
      {4:0 }{1:^øøøøøøøøøøøøøøøøøø}|
      {3:  }{2:>>>}øøøøøøøøøøøø   |
      {3:1 }aaaaaaaaaaaaaaaaaa|
      {3:  }{2:>>>}aaaaaaaaaaaa   |
      {5:-- INSERT --}        |
    ]])
  end)

  -- oldtest: Test_cursorline_after_yank()
  it('always updated. vim-patch:8.1.0849', function()
    local screen = Screen.new(50,5)
    screen:set_default_attr_ids({
      [1] = {foreground = Screen.colors.SlateBlue},
      [2] = {bold = true, foreground = Screen.colors.Brown},
      [3] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red},
      [4] = {foreground = Screen.colors.SlateBlue, background = Screen.colors.Gray90},
      [5] = {background = Screen.colors.Gray90},
      [6] = {bold = true, foreground = Screen.colors.Blue1},
      [7] = {background = Screen.colors.LightRed},
      [8] = {foreground = Screen.colors.Brown},
    })
    screen:attach()
    command('set cursorline relativenumber')
    command('call setline(1, ["","1","2","3",""])')
    feed('Gy3k')
    screen:expect([[
      {2:  0 }{5:^1                                             }|
      {8:  1 }2                                             |
      {8:  2 }3                                             |
      {8:  3 }                                              |
      4 lines yanked                                    |
    ]])
    feed('jj')
    screen:expect([[
      {8:  2 }1                                             |
      {8:  1 }2                                             |
      {2:  0 }{5:^3                                             }|
      {8:  1 }                                              |
      4 lines yanked                                    |
    ]])
  end)

  -- oldtest: Test_cursorline_with_visualmode()
  it('with visual area. vim-patch:8.1.1001', function()
    local screen = Screen.new(50,5)
    screen:set_default_attr_ids({
      [1] = {foreground = Screen.colors.SlateBlue},
      [2] = {bold = true, foreground = Screen.colors.Brown},
      [3] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red},
      [4] = {foreground = Screen.colors.SlateBlue, background = Screen.colors.Gray90},
      [5] = {background = Screen.colors.Gray90},
      [6] = {bold = true, foreground = Screen.colors.Blue1},
      [7] = {background = Screen.colors.LightRed},
      [8] = {foreground = Screen.colors.Brown},
      [9] = {background = Screen.colors.LightGrey},
      [10] = {bold = true},
    })
    screen:attach()
    command('set cursorline')
    command('call setline(1, repeat(["abc"], 50))')
    feed('V<C-f>zbkkjk')
    screen:expect([[
      {9:abc}                                               |
      ^a{9:bc}                                               |
      abc                                               |
      abc                                               |
      {10:-- VISUAL LINE --}                                 |
    ]])
  end)

  -- oldtest: Test_cursorline_callback()
  it('is updated if cursor is moved up from timer vim-patch:8.2.4591', function()
    local screen = Screen.new(50, 8)
    screen:set_default_attr_ids({
      [1] = {background = Screen.colors.Gray90},  -- CursorLine
      [2] = {bold = true, foreground = Screen.colors.Blue1},  -- NonText
    })
    screen:attach()
    exec([[
      call setline(1, ['aaaaa', 'bbbbb', 'ccccc', 'ddddd'])
      set cursorline
      call cursor(4, 1)

      func Func(timer)
        call cursor(2, 1)
      endfunc

      call timer_start(300, 'Func')
    ]])
    screen:expect({grid = [[
      aaaaa                                             |
      bbbbb                                             |
      ccccc                                             |
      {1:^ddddd                                             }|
      {2:~                                                 }|
      {2:~                                                 }|
      {2:~                                                 }|
                                                        |
    ]], timeout = 100})
    screen:expect({grid = [[
      aaaaa                                             |
      {1:^bbbbb                                             }|
      ccccc                                             |
      ddddd                                             |
      {2:~                                                 }|
      {2:~                                                 }|
      {2:~                                                 }|
                                                        |
    ]]})
  end)

  it('with split windows in diff mode', function()
    local screen = Screen.new(50,12)
    screen:set_default_attr_ids({
      [1] = {foreground = Screen.colors.DarkBlue, background = Screen.colors.WebGray},
      [2] = {bold = true, background = Screen.colors.Red},
      [3] = {background = Screen.colors.LightMagenta},
      [4] = {reverse = true},
      [5] = {background = Screen.colors.LightBlue},
      [6] = {background = Screen.colors.LightCyan1, bold = true, foreground = Screen.colors.Blue1},
      [7] = {background = Screen.colors.Red, foreground = Screen.colors.White},
      [8] = {bold = true, foreground = Screen.colors.Blue1},
      [9] = {bold = true, reverse = true},
    })
    screen:attach()

    command('hi CursorLine ctermbg=red ctermfg=white guibg=red guifg=white')
    command('set cursorline')
    feed('iline 1 some text<cr>line 2 more text<cr>extra line!<cr>extra line!<cr>last line ...<cr>')
    feed('<esc>gg')
    command('vsplit')
    command('enew')
    feed('iline 1 some text<cr>line 2 moRe text!<cr>extra line!<cr>extra line!<cr>extra line!<cr>last line ...<cr>')
    feed('<esc>gg')
    command('windo diffthis')
    screen:expect([[
      {1:  }{7:line 1 some text       }│{1:  }{7:^line 1 some text      }|
      {1:  }{3:line 2 mo}{2:Re text!}{3:      }│{1:  }{3:line 2 mo}{2:re text}{3:      }|
      {1:  }{5:extra line!            }│{1:  }{6:----------------------}|
      {1:  }extra line!            │{1:  }extra line!           |
      {1:  }extra line!            │{1:  }extra line!           |
      {1:  }last line ...          │{1:  }last line ...         |
      {1:  }                       │{1:  }                      |
      {8:~                        }│{8:~                       }|
      {8:~                        }│{8:~                       }|
      {8:~                        }│{8:~                       }|
      {4:[No Name] [+]             }{9:[No Name] [+]           }|
                                                        |
    ]])
    feed('jjjjj')
    screen:expect([[
      {1:  }line 1 some text       │{1:  }line 1 some text      |
      {1:  }{3:line 2 mo}{2:Re text!}{3:      }│{1:  }{3:line 2 mo}{2:re text}{3:      }|
      {1:  }{5:extra line!            }│{1:  }{6:----------------------}|
      {1:  }extra line!            │{1:  }extra line!           |
      {1:  }extra line!            │{1:  }extra line!           |
      {1:  }last line ...          │{1:  }last line ...         |
      {1:  }{7:                       }│{1:  }{7:^                      }|
      {8:~                        }│{8:~                       }|
      {8:~                        }│{8:~                       }|
      {8:~                        }│{8:~                       }|
      {4:[No Name] [+]             }{9:[No Name] [+]           }|
                                                        |
    ]])

    -- CursorLine with fg=NONE is "low-priority".
    -- Rendered as underline in a diff-line. #9028
    command('hi CursorLine ctermbg=red ctermfg=NONE guibg=red guifg=NONE')
    feed('kkkk')
    screen:expect([[
      {1:  }line 1 some text       │{1:  }line 1 some text      |
      {1:  }{11:line 2 mo}{12:Re text!}{11:      }│{1:  }{11:^line 2 mo}{12:re text}{11:      }|
      {1:  }{5:extra line!            }│{1:  }{6:----------------------}|
      {1:  }extra line!            │{1:  }extra line!           |
      {1:  }extra line!            │{1:  }extra line!           |
      {1:  }last line ...          │{1:  }last line ...         |
      {1:  }                       │{1:  }                      |
      {8:~                        }│{8:~                       }|
      {8:~                        }│{8:~                       }|
      {8:~                        }│{8:~                       }|
      {4:[No Name] [+]             }{9:[No Name] [+]           }|
                                                        |
    ]], {
      [1] = {foreground = Screen.colors.DarkBlue, background = Screen.colors.WebGray},
      [2] = {bold = true, background = Screen.colors.Red},
      [3] = {background = Screen.colors.LightMagenta},
      [4] = {reverse = true},
      [5] = {background = Screen.colors.LightBlue},
      [6] = {background = Screen.colors.LightCyan1, bold = true, foreground = Screen.colors.Blue1},
      [7] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red},
      [8] = {bold = true, foreground = Screen.colors.Blue1},
      [9] = {bold = true, reverse = true},
      [10] = {bold = true},
      [11] = {underline = true,
              background = Screen.colors.LightMagenta},
      [12] = {bold = true, underline = true,
              background = Screen.colors.Red},
    })
  end)

  -- oldtest: Test_diff_with_cursorline_number()
  it('CursorLineNr shows correctly just below filler lines', function()
    local screen = Screen.new(50,12)
    screen:set_default_attr_ids({
      [1] = {foreground = Screen.colors.DarkBlue, background = Screen.colors.WebGray},
      [2] = {background = Screen.colors.LightCyan1, bold = true, foreground = Screen.colors.Blue1},
      [3] = {reverse = true},
      [4] = {background = Screen.colors.LightBlue},
      [5] = {background = Screen.colors.Red, foreground = Screen.colors.White},
      [6] = {background = Screen.colors.White, bold = true, foreground = Screen.colors.Black},
      [7] = {bold = true, foreground = Screen.colors.Blue1},
      [8] = {bold = true, reverse = true},
      [9] = {foreground = Screen.colors.Brown},
    })
    screen:attach()

    command('hi CursorLine guibg=red guifg=white')
    command('hi CursorLineNr guibg=white guifg=black gui=bold')
    command('set cursorline number')
    command('call setline(1, ["baz", "foo", "foo", "bar"])')
    feed('2gg0')
    command('vnew')
    command('call setline(1, ["foo", "foo", "bar"])')
    command('windo diffthis')
    command('1wincmd w')
    screen:expect([[
      {1:  }{9:    }{2:-------------------}│{1:  }{9:  1 }{4:baz               }|
      {1:  }{6:  1 }{5:^foo                }│{1:  }{6:  2 }{5:foo               }|
      {1:  }{9:  2 }foo                │{1:  }{9:  3 }foo               |
      {1:  }{9:  3 }bar                │{1:  }{9:  4 }bar               |
      {7:~                        }│{7:~                       }|
      {7:~                        }│{7:~                       }|
      {7:~                        }│{7:~                       }|
      {7:~                        }│{7:~                       }|
      {7:~                        }│{7:~                       }|
      {7:~                        }│{7:~                       }|
      {8:[No Name] [+]             }{3:[No Name] [+]           }|
                                                        |
    ]])
    command('set cursorlineopt=number')
    screen:expect([[
      {1:  }{9:    }{2:-------------------}│{1:  }{9:  1 }{4:baz               }|
      {1:  }{6:  1 }^foo                │{1:  }{6:  2 }{5:foo               }|
      {1:  }{9:  2 }foo                │{1:  }{9:  3 }foo               |
      {1:  }{9:  3 }bar                │{1:  }{9:  4 }bar               |
      {7:~                        }│{7:~                       }|
      {7:~                        }│{7:~                       }|
      {7:~                        }│{7:~                       }|
      {7:~                        }│{7:~                       }|
      {7:~                        }│{7:~                       }|
      {7:~                        }│{7:~                       }|
      {8:[No Name] [+]             }{3:[No Name] [+]           }|
                                                        |
    ]])
  end)
end)

describe('CursorColumn highlight', function()
  local screen
  before_each(function()
    clear()
    screen = Screen.new(50, 8)
    screen:set_default_attr_ids({
      [1] = {background = Screen.colors.Gray90},  -- CursorColumn
      [2] = {bold = true, foreground = Screen.colors.Blue1},  -- NonText
      [3] = {bold = true},  -- ModeMsg
    })
    screen:attach()
  end)

  it('is updated when pressing "i" on a TAB character', function()
    exec([[
      call setline(1, ['123456789', "a\tb"])
      set cursorcolumn
      call cursor(2, 2)
    ]])
    screen:expect([[
      1234567{1:8}9                                         |
      a      ^ b                                         |
      {2:~                                                 }|
      {2:~                                                 }|
      {2:~                                                 }|
      {2:~                                                 }|
      {2:~                                                 }|
                                                        |
    ]])
    feed('i')
    screen:expect([[
      1{1:2}3456789                                         |
      a^       b                                         |
      {2:~                                                 }|
      {2:~                                                 }|
      {2:~                                                 }|
      {2:~                                                 }|
      {2:~                                                 }|
      {3:-- INSERT --}                                      |
    ]])
    feed('<C-O>')
    screen:expect([[
      1234567{1:8}9                                         |
      a      ^ b                                         |
      {2:~                                                 }|
      {2:~                                                 }|
      {2:~                                                 }|
      {2:~                                                 }|
      {2:~                                                 }|
      {3:-- (insert) --}                                    |
    ]])
    feed('i')
    screen:expect([[
      1{1:2}3456789                                         |
      a^       b                                         |
      {2:~                                                 }|
      {2:~                                                 }|
      {2:~                                                 }|
      {2:~                                                 }|
      {2:~                                                 }|
      {3:-- INSERT --}                                      |
    ]])
  end)

  -- oldtest: Test_cursorcolumn_callback()
  it('is updated if cursor is moved from timer', function()
    exec([[
      call setline(1, ['aaaaa', 'bbbbb', 'ccccc', 'ddddd'])
      set cursorcolumn
      call cursor(4, 5)

      func Func(timer)
        call cursor(1, 1)
      endfunc

      call timer_start(300, 'Func')
    ]])
    screen:expect({grid = [[
      aaaa{1:a}                                             |
      bbbb{1:b}                                             |
      cccc{1:c}                                             |
      dddd^d                                             |
      {2:~                                                 }|
      {2:~                                                 }|
      {2:~                                                 }|
                                                        |
    ]], timeout = 100})
    screen:expect({grid = [[
      ^aaaaa                                             |
      {1:b}bbbb                                             |
      {1:c}cccc                                             |
      {1:d}dddd                                             |
      {2:~                                                 }|
      {2:~                                                 }|
      {2:~                                                 }|
                                                        |
    ]]})
  end)
end)

describe('ColorColumn highlight', function()
  local screen

  before_each(function()
    clear()
    screen = Screen.new(40, 15)
    screen:set_default_attr_ids({
      [1] = {background = Screen.colors.LightRed},  -- ColorColumn
      [2] = {background = Screen.colors.Grey90},  -- CursorLine
      [3] = {foreground = Screen.colors.Brown},  -- LineNr
      [4] = {foreground = Screen.colors.Brown, bold = true},  -- CursorLineNr
      [5] = {foreground = Screen.colors.Blue, bold = true},  -- NonText
      [6] = {foreground = Screen.colors.Blue, background = Screen.colors.LightRed, bold = true},
      [7] = {reverse = true, bold = true},  -- StatusLine
      [8] = {reverse = true},  -- StatusLineNC
      [9] = {background = Screen.colors.Grey90, foreground = Screen.colors.Red},
    })
    screen:attach()
  end)

  -- oldtest: Test_colorcolumn()
  it('when entering a buffer vim-patch:8.1.2073', function()
    exec([[
      set nohidden
      split
      edit X
      call setline(1, ["1111111111","22222222222","3333333333"])
      set nomodified
      set colorcolumn=3,9
      set number cursorline cursorlineopt=number
      wincmd w
      buf X
    ]])
    screen:expect([[
      {4:  1 }11{1:1}11111{1:1}1                          |
      {3:  2 }22{1:2}22222{1:2}22                         |
      {3:  3 }33{1:3}33333{1:3}3                          |
      {5:~                                       }|
      {5:~                                       }|
      {5:~                                       }|
      {8:X                                       }|
      {4:  1 }^11{1:1}11111{1:1}1                          |
      {3:  2 }22{1:2}22222{1:2}22                         |
      {3:  3 }33{1:3}33333{1:3}3                          |
      {5:~                                       }|
      {5:~                                       }|
      {5:~                                       }|
      {7:X                                       }|
                                              |
    ]])
  end)

  -- oldtest: Test_colorcolumn_bri()
  it("in 'breakindent' vim-patch:8.2.1689", function()
    exec([[
      call setline(1, 'The quick brown fox jumped over the lazy dogs')
      set co=40 linebreak bri briopt=shift:2 cc=40,41,43
    ]])
    screen:expect([[
      ^The quick brown fox jumped over the    {1: }|
      {1: } {1:l}azy dogs                             |
      {5:~                                       }|
      {5:~                                       }|
      {5:~                                       }|
      {5:~                                       }|
      {5:~                                       }|
      {5:~                                       }|
      {5:~                                       }|
      {5:~                                       }|
      {5:~                                       }|
      {5:~                                       }|
      {5:~                                       }|
      {5:~                                       }|
                                              |
    ]])
  end)

  -- oldtest: Test_colorcolumn_sbr()
  it("in 'showbreak' vim-patch:8.2.1689", function()
    exec([[
      call setline(1, 'The quick brown fox jumped over the lazy dogs')
      set co=40 showbreak=+++>\\  cc=40,41,43
    ]])
    screen:expect([[
      ^The quick brown fox jumped over the laz{1:y}|
      {6:+}{5:+}{6:+}{5:>\} dogs                              |
      {5:~                                       }|
      {5:~                                       }|
      {5:~                                       }|
      {5:~                                       }|
      {5:~                                       }|
      {5:~                                       }|
      {5:~                                       }|
      {5:~                                       }|
      {5:~                                       }|
      {5:~                                       }|
      {5:~                                       }|
      {5:~                                       }|
                                              |
    ]])
  end)

  it('is combined with low-priority CursorLine highlight #23016', function()
    screen:try_resize(40, 2)
    command('set colorcolumn=30 cursorline')
    screen:expect([[
      {2:^                             }{1: }{2:          }|
                                              |
    ]])
    command('hi clear ColorColumn')
    screen:expect([[
      {2:^                                        }|
                                              |
    ]])
    command('hi ColorColumn guifg=Red')
    screen:expect([[
      {2:^                             }{9: }{2:          }|
                                              |
    ]])
  end)
end)

describe("MsgSeparator highlight and msgsep fillchar", function()
  local screen
  before_each(function()
    clear()
    screen = Screen.new(50,5)
    screen:set_default_attr_ids({
      [1] = {bold=true, foreground=Screen.colors.Blue},
      [2] = {bold=true, reverse=true},
      [3] = {bold = true, foreground = Screen.colors.SeaGreen4},
      [4] = {background = Screen.colors.Cyan, bold = true, reverse = true},
      [5] = {bold = true, background = Screen.colors.Magenta},
      [6] = {background = Screen.colors.WebGray},
      [7] = {background = Screen.colors.WebGray, bold = true, foreground = Screen.colors.SeaGreen4},
      [8] = {foreground = Screen.colors.Grey0, background = Screen.colors.Gray60},
      [9] = {foreground = Screen.colors.Grey40, background = Screen.colors.Gray60},
      [10] = {foreground = tonumber('0x000019'), background = Screen.colors.Gray60},
      [11] = {background = Screen.colors.Gray60, bold = true, foreground = tonumber('0x666699')},
      [12] = {background = Screen.colors.Gray60, bold = true, foreground = tonumber('0x297d4e')},
      [13] = {background = tonumber('0xff4cff'), bold = true, foreground = tonumber('0xb200ff')},
    })
    screen:attach()
  end)

  it("works", function()

    -- defaults
    feed_command("ls")
    screen:expect([[
                                                        |
      {2:                                                  }|
      :ls                                               |
        1 %a   "[No Name]"                    line 1    |
      {3:Press ENTER or type command to continue}^           |
    ]])
    feed('<cr>')

    feed_command("set fillchars+=msgsep:-")
    feed_command("ls")
    screen:expect([[
                                                        |
      {2:--------------------------------------------------}|
      :ls                                               |
        1 %a   "[No Name]"                    line 1    |
      {3:Press ENTER or type command to continue}^           |
    ]])

    -- linked to StatusLine per default
    feed_command("hi StatusLine guibg=Cyan")
    feed_command("ls")
    screen:expect([[
                                                        |
      {4:--------------------------------------------------}|
      :ls                                               |
        1 %a   "[No Name]"                    line 1    |
      {3:Press ENTER or type command to continue}^           |
    ]])

    -- but can be unlinked
    feed_command("hi clear MsgSeparator")
    feed_command("hi MsgSeparator guibg=Magenta gui=bold")
    feed_command("ls")
    screen:expect([[
                                                        |
      {5:--------------------------------------------------}|
      :ls                                               |
        1 %a   "[No Name]"                    line 1    |
      {3:Press ENTER or type command to continue}^           |
    ]])
  end)

  it("and MsgArea", function()
    feed_command("hi MsgArea guibg=Gray")
    screen:expect{grid=[[
      ^                                                  |
      {1:~                                                 }|
      {1:~                                                 }|
      {1:~                                                 }|
      {6:                                                  }|
    ]]}
    feed(":ls")
    screen:expect{grid=[[
                                                        |
      {1:~                                                 }|
      {1:~                                                 }|
      {1:~                                                 }|
      {6::ls^                                               }|
    ]]}
    feed(":<cr>")
    screen:expect{grid=[[
                                                        |
      {2:                                                  }|
      {6::ls:                                              }|
      {6:  1 %a   "[No Name]"                    line 1    }|
      {7:Press ENTER or type command to continue}{6:^           }|
    ]]}

    -- support madness^Wblending of message "overlay"
    feed_command("hi MsgArea blend=20")
    feed_command("hi clear MsgSeparator")
    feed_command("hi MsgSeparator blend=30 guibg=Magenta")
    screen:expect{grid=[[
      ^                                                  |
      {1:~                                                 }|
      {1:~                                                 }|
      {1:~                                                 }|
      {8::hi}{9: }{8:MsgSeparator}{9: }{8:blend=30}{9: }{8:guibg=Magenta}{9:           }|
    ]]}
    feed(":ls")
    screen:expect{grid=[[
                                                        |
      {1:~                                                 }|
      {1:~                                                 }|
      {1:~                                                 }|
      {8::ls}{9:^                                               }|
    ]]}
    feed("<cr>")
    screen:expect{grid=[[
                                                        |
      {13:~                                                 }|
      {10::ls}{11:                                               }|
      {11:~ }{10:1}{11: }{10:%a}{11:   }{10:"[No}{11: }{10:Name]"}{11:                    }{10:line}{11: }{10:1}{11:    }|
      {12:Press}{9: }{12:ENTER}{9: }{12:or}{9: }{12:type}{9: }{12:command}{9: }{12:to}{9: }{12:continue}{9:^           }|
    ]]}
  end)
end)

describe("'number' and 'relativenumber' highlight", function()
  before_each(clear)

  it('LineNr, LineNrAbove and LineNrBelow', function()
    local screen = Screen.new(20,10)
    screen:set_default_attr_ids({
      [1] = {foreground = Screen.colors.Red},
      [2] = {foreground = Screen.colors.Blue},
      [3] = {foreground = Screen.colors.Green},
    })
    screen:attach()
    command('set number relativenumber')
    command('call setline(1, range(50))')
    command('highlight LineNr guifg=Red')
    feed('4j')
    screen:expect([[
      {1:  4 }0               |
      {1:  3 }1               |
      {1:  2 }2               |
      {1:  1 }3               |
      {1:5   }^4               |
      {1:  1 }5               |
      {1:  2 }6               |
      {1:  3 }7               |
      {1:  4 }8               |
                          |
    ]])
    command('highlight LineNrAbove guifg=Blue')
    screen:expect([[
      {2:  4 }0               |
      {2:  3 }1               |
      {2:  2 }2               |
      {2:  1 }3               |
      {1:5   }^4               |
      {1:  1 }5               |
      {1:  2 }6               |
      {1:  3 }7               |
      {1:  4 }8               |
                          |
    ]])
    command('highlight LineNrBelow guifg=Green')
    screen:expect([[
      {2:  4 }0               |
      {2:  3 }1               |
      {2:  2 }2               |
      {2:  1 }3               |
      {1:5   }^4               |
      {3:  1 }5               |
      {3:  2 }6               |
      {3:  3 }7               |
      {3:  4 }8               |
                          |
    ]])
    feed('3j')
    screen:expect([[
      {2:  7 }0               |
      {2:  6 }1               |
      {2:  5 }2               |
      {2:  4 }3               |
      {2:  3 }4               |
      {2:  2 }5               |
      {2:  1 }6               |
      {1:8   }^7               |
      {3:  1 }8               |
                          |
    ]])
  end)

  -- oldtest: Test_relativenumber_callback()
  it('relative number highlight is updated if cursor is moved from timer', function()
    local screen = Screen.new(50, 8)
    screen:set_default_attr_ids({
      [1] = {foreground = Screen.colors.Brown},  -- LineNr
      [2] = {bold = true, foreground = Screen.colors.Blue1},  -- NonText
    })
    screen:attach()
    exec([[
      call setline(1, ['aaaaa', 'bbbbb', 'ccccc', 'ddddd'])
      set relativenumber
      call cursor(4, 1)

      func Func(timer)
        call cursor(1, 1)
      endfunc

      call timer_start(300, 'Func')
    ]])
    screen:expect({grid = [[
      {1:  3 }aaaaa                                         |
      {1:  2 }bbbbb                                         |
      {1:  1 }ccccc                                         |
      {1:  0 }^ddddd                                         |
      {2:~                                                 }|
      {2:~                                                 }|
      {2:~                                                 }|
                                                        |
    ]], timeout = 100})
    screen:expect({grid = [[
      {1:  0 }^aaaaa                                         |
      {1:  1 }bbbbb                                         |
      {1:  2 }ccccc                                         |
      {1:  3 }ddddd                                         |
      {2:~                                                 }|
      {2:~                                                 }|
      {2:~                                                 }|
                                                        |
    ]]})
  end)
end)

describe("'winhighlight' highlight", function()
  local screen

  before_each(function()
    clear()
    screen = Screen.new(20,8)
    screen:attach()
    screen:set_default_attr_ids {
      [0] = {bold=true, foreground=Screen.colors.Blue};
      [1] = {background = Screen.colors.DarkBlue};
      [2] = {background = Screen.colors.DarkBlue, bold = true, foreground = Screen.colors.Blue1};
      [3] = {bold = true, reverse = true};
      [4] = {reverse = true};
      [5] = {background = Screen.colors.DarkGreen};
      [6] = {background = Screen.colors.DarkGreen, bold = true, foreground = Screen.colors.Blue1};
      [7] = {background = Screen.colors.DarkMagenta};
      [8] = {background = Screen.colors.DarkMagenta, bold = true, foreground = Screen.colors.Blue1};
      [9] = {foreground = Screen.colors.Brown};
      [10] = {foreground = Screen.colors.Brown, background = Screen.colors.DarkBlue};
      [11] = {background = Screen.colors.DarkBlue, bold = true, reverse = true};
      [12] = {background = Screen.colors.DarkGreen, reverse = true};
      [13] = {background = Screen.colors.Magenta4, reverse = true};
      [14] = {background = Screen.colors.DarkBlue, reverse = true};
      [15] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red};
      [16] = {foreground = Screen.colors.Blue1};
      [17] = {background = Screen.colors.LightRed};
      [18] = {background = Screen.colors.Gray90};
      [19] = {foreground = Screen.colors.LightGrey, background = Screen.colors.DarkGray};
      [20] = {background = Screen.colors.LightGrey, underline = true};
      [21] = {bold = true};
      [22] = {bold = true, foreground = Screen.colors.SeaGreen4};
      [23] = {background = Screen.colors.LightMagenta};
      [24] = {background = Screen.colors.WebGray};
      [25] = {bold = true, foreground = Screen.colors.Green1};
      [26] = {background = Screen.colors.Red};
      [27] = {background = Screen.colors.DarkBlue, bold = true, foreground = Screen.colors.Green1};
      [28] = {bold = true, foreground = Screen.colors.Brown};
      [29] = {foreground = Screen.colors.Blue1, background = Screen.colors.Red, bold = true};
      [30] = {background = tonumber('0xff8800')};
      [31] = {background = tonumber('0xff8800'), bold = true, foreground = Screen.colors.Blue};
    }
    command("hi Background1 guibg=DarkBlue")
    command("hi Background2 guibg=DarkGreen")
  end)

  it('works for background color', function()
    insert("aa")
    command("split")
    command("set winhl=Normal:Background1")
    screen:expect([[
      {1:a^a                  }|
      {2:~                   }|
      {2:~                   }|
      {3:[No Name] [+]       }|
      aa                  |
      {0:~                   }|
      {4:[No Name] [+]       }|
                          |
    ]])

    command("enew")
    screen:expect([[
      {1:^                    }|
      {2:~                   }|
      {2:~                   }|
      {3:[No Name]           }|
      aa                  |
      {0:~                   }|
      {4:[No Name] [+]       }|
                          |
    ]])
  end)

  it('works for background color in rightleft window #22640', function()
    -- Use a wide screen to also check that this doesn't overflow linebuf_attr.
    screen:try_resize(80, 6)
    insert('aa')
    command('setlocal rightleft')
    command('setlocal winhl=Normal:Background1')
    screen:expect([[
      {1:                                                                              ^aa}|
      {2:                                                                               ~}|
      {2:                                                                               ~}|
      {2:                                                                               ~}|
      {2:                                                                               ~}|
                                                                                      |
    ]])
    command('botright vsplit')
    screen:expect([[
      {1:                                     aa│                                      ^aa}|
      {2:                                      ~}{1:│}{2:                                       ~}|
      {2:                                      ~}{1:│}{2:                                       ~}|
      {2:                                      ~}{1:│}{2:                                       ~}|
      {4:[No Name] [+]                           }{3:[No Name] [+]                           }|
                                                                                      |
    ]])
  end)

  it('handles undefined groups', function()
    command("set winhl=Normal:Background1")
    screen:expect([[
      {1:^                    }|
      {2:~                   }|
      {2:~                   }|
      {2:~                   }|
      {2:~                   }|
      {2:~                   }|
      {2:~                   }|
                          |
    ]])

    command("set winhl=xxx:yyy")
    eq('xxx:yyy', eval('&winhl'))
    screen:expect{grid=[[
      ^                    |
      {0:~                   }|
      {0:~                   }|
      {0:~                   }|
      {0:~                   }|
      {0:~                   }|
      {0:~                   }|
                          |
    ]]}
  end)

  it('can be changed to define different groups', function()
    command("set winhl=EndOfBuffer:Background1")
    screen:expect{grid=[[
      ^                    |
      {1:~                   }|
      {1:~                   }|
      {1:~                   }|
      {1:~                   }|
      {1:~                   }|
      {1:~                   }|
                          |
    ]]}

    command("set winhl=Normal:ErrorMsg")
    screen:expect{grid=[[
      {15:^                    }|
      {29:~                   }|
      {29:~                   }|
      {29:~                   }|
      {29:~                   }|
      {29:~                   }|
      {29:~                   }|
                          |
    ]]}
  end)

  it('works local to the window', function()
    insert("aa")
    command("split")
    command("setlocal winhl=Normal:Background1")
    screen:expect([[
      {1:a^a                  }|
      {2:~                   }|
      {2:~                   }|
      {3:[No Name] [+]       }|
      aa                  |
      {0:~                   }|
      {4:[No Name] [+]       }|
                          |
    ]])

    command("enew")
    screen:expect([[
      ^                    |
      {0:~                   }|
      {0:~                   }|
      {3:[No Name]           }|
      aa                  |
      {0:~                   }|
      {4:[No Name] [+]       }|
                          |
    ]])

    command("bnext")
    screen:expect([[
      {1:^aa                  }|
      {2:~                   }|
      {2:~                   }|
      {3:[No Name] [+]       }|
      aa                  |
      {0:~                   }|
      {4:[No Name] [+]       }|
                          |
    ]])
  end)

  it('for inactive window background works', function()
    command("set winhl=Normal:Background1,NormalNC:Background2")
    -- tests global value is copied across split
    command("split")
    screen:expect([[
      {1:^                    }|
      {2:~                   }|
      {2:~                   }|
      {3:[No Name]           }|
      {5:                    }|
      {6:~                   }|
      {4:[No Name]           }|
                          |
    ]])

    feed("<c-w><c-w>")
    screen:expect([[
      {5:                    }|
      {6:~                   }|
      {6:~                   }|
      {4:[No Name]           }|
      {1:^                    }|
      {2:~                   }|
      {3:[No Name]           }|
                          |
    ]])

    feed("<c-w><c-w>")
    screen:expect([[
      {1:^                    }|
      {2:~                   }|
      {2:~                   }|
      {3:[No Name]           }|
      {5:                    }|
      {6:~                   }|
      {4:[No Name]           }|
                          |
    ]])
  end)

  it('works with NormalNC', function()
    command("hi NormalNC guibg=DarkMagenta")
    -- tests global value is copied across split
    command("split")
    screen:expect([[
      ^                    |
      {0:~                   }|
      {0:~                   }|
      {3:[No Name]           }|
      {7:                    }|
      {8:~                   }|
      {4:[No Name]           }|
                          |
    ]])

    command("wincmd w")
    screen:expect([[
      {7:                    }|
      {8:~                   }|
      {8:~                   }|
      {4:[No Name]           }|
      ^                    |
      {0:~                   }|
      {3:[No Name]           }|
                          |
    ]])


    -- winbg=Normal:... overrides global NormalNC
    command("set winhl=Normal:Background1")
    screen:expect([[
      {7:                    }|
      {8:~                   }|
      {8:~                   }|
      {4:[No Name]           }|
      {1:^                    }|
      {2:~                   }|
      {3:[No Name]           }|
                          |
    ]])

    command("wincmd w")
    screen:expect([[
      ^                    |
      {0:~                   }|
      {0:~                   }|
      {3:[No Name]           }|
      {1:                    }|
      {2:~                   }|
      {4:[No Name]           }|
                          |
    ]])

    command("wincmd w")
    command("set winhl=Normal:Background1,NormalNC:Background2")
    screen:expect([[
      {7:                    }|
      {8:~                   }|
      {8:~                   }|
      {4:[No Name]           }|
      {1:^                    }|
      {2:~                   }|
      {3:[No Name]           }|
                          |
    ]])

    command("wincmd w")
    screen:expect([[
      ^                    |
      {0:~                   }|
      {0:~                   }|
      {3:[No Name]           }|
      {5:                    }|
      {6:~                   }|
      {4:[No Name]           }|
                          |
    ]])
  end)

  it('updates background to changed linked group', function()
    command("split")
    command("setlocal winhl=Normal:FancyGroup") -- does not yet exist
    screen:expect{grid=[[
      ^                    |
      {0:~                   }|
      {0:~                   }|
      {3:[No Name]           }|
                          |
      {0:~                   }|
      {4:[No Name]           }|
                          |
    ]]}

    command("hi FancyGroup guibg=#FF8800") -- nice orange
    screen:expect{grid=[[
      {30:^                    }|
      {31:~                   }|
      {31:~                   }|
      {3:[No Name]           }|
                          |
      {0:~                   }|
      {4:[No Name]           }|
                          |
    ]]}
  end)

  it('background applies also to non-text', function()
    command('set sidescroll=0')
    insert('Lorem ipsum dolor sit amet ')
    command('set shiftwidth=2')
    feed('>>')
    command('set number')
    command('set breakindent')
    command('set briopt=shift:5,min:0')
    command('set list')
    command('set showbreak=↪')
    screen:expect([[
      {9:  1 }  ^Lorem ipsum do|
      {9:    }       {0:↪}lor sit |
      {9:    }       {0:↪}amet{0:-}   |
      {0:~                   }|
      {0:~                   }|
      {0:~                   }|
      {0:~                   }|
                          |
    ]])

    command('set winhl=Normal:Background1')
    screen:expect([[
      {10:  1 }{1:  ^Lorem ipsum do}|
      {10:    }{1:       }{2:↪}{1:lor sit }|
      {10:    }{1:       }{2:↪}{1:amet}{2:-}{1:   }|
      {2:~                   }|
      {2:~                   }|
      {2:~                   }|
      {2:~                   }|
                          |
    ]])

    command('set nowrap')
    command('set listchars+=extends:❯,precedes:❮')
    feed('3w')
    screen:expect([[
      {10:  1 }{2:❮}{1: dolor ^sit ame}{2:❯}|
      {2:~                   }|
      {2:~                   }|
      {2:~                   }|
      {2:~                   }|
      {2:~                   }|
      {2:~                   }|
                          |
    ]])
  end)

  it("background doesn't override syntax background", function()
    command('syntax on')
    command('syntax keyword Foobar foobar')
    command('syntax keyword Article the')
    command('hi Foobar guibg=#FF0000')
    command('hi Article guifg=#00FF00 gui=bold')
    insert('the foobar was foobar')
    screen:expect([[
      {25:the} {26:foobar} was {26:fooba}|
      {26:^r}                   |
      {0:~                   }|
      {0:~                   }|
      {0:~                   }|
      {0:~                   }|
      {0:~                   }|
                          |
    ]])

    -- winhl=Normal:Group with background doesn't override syntax background,
    -- but does combine with syntax foreground.
    command('set winhl=Normal:Background1')
    screen:expect([[
      {27:the}{1: }{26:foobar}{1: was }{26:fooba}|
      {26:^r}{1:                   }|
      {2:~                   }|
      {2:~                   }|
      {2:~                   }|
      {2:~                   }|
      {2:~                   }|
                          |
    ]])
  end)

  it('can override NonText, Conceal and EndOfBuffer', function()
    curbufmeths.set_lines(0,-1,true, {"raa\000"})
    command('call matchaddpos("Conceal", [[1,2]], 0, -1, {"conceal": "#"})')
    command('set cole=2 cocu=nvic')
    command('split')
    command('call matchaddpos("Conceal", [[1,2]], 0, -1, {"conceal": "#"})')
    command('set winhl=SpecialKey:ErrorMsg,EndOfBuffer:Background1,'
            ..'Conceal:Background2')

    screen:expect([[
      ^r{5:#}a{15:^@}               |
      {1:~                   }|
      {1:~                   }|
      {3:[No Name] [+]       }|
      r{19:#}a{16:^@}               |
      {0:~                   }|
      {4:[No Name] [+]       }|
                          |
    ]])
  end)

  it('can override LineNr, CursorColumn and ColorColumn', function()
    insert('very text\nmore text')
    command('set number')
    command('set colorcolumn=2')
    command('set cursorcolumn')
    feed('k')

    command('split')
    command('set winhl=LineNr:Background1,CursorColumn:Background2,'
            ..'ColorColumn:ErrorMsg')
    screen:expect([[
      {1:  1 }v{15:e}ry tex^t       |
      {1:  2 }m{15:o}re tex{5:t}       |
      {0:~                   }|
      {3:[No Name] [+]       }|
      {9:  1 }v{17:e}ry text       |
      {9:  2 }m{17:o}re tex{18:t}       |
      {4:[No Name] [+]       }|
                          |
    ]])
  end)

  it('can override Tabline', function()
    command('tabnew')
    command('set winhl=TabLine:Background1,TabLineSel:ErrorMsg')

    screen:expect([[
      {20: No Name] }{15: No Name]}{20:X}|
      ^                    |
      {0:~                   }|
      {0:~                   }|
      {0:~                   }|
      {0:~                   }|
      {0:~                   }|
                          |
    ]])
    command("tabnext")
    screen:expect([[
      {21: No Name] }{1: No Name]}{20:X}|
      ^                    |
      {0:~                   }|
      {0:~                   }|
      {0:~                   }|
      {0:~                   }|
      {0:~                   }|
                          |
    ]])
  end)

  it('can override popupmenu', function()
    insert('word wording wordy')
    command('split')
    command('set winhl=Pmenu:Background1,PmenuSel:Background2,'
            ..'PmenuSbar:ErrorMsg,PmenuThumb:Normal')
    screen:expect([[
      word wording word^y  |
      {0:~                   }|
      {0:~                   }|
      {3:[No Name] [+]       }|
      word wording wordy  |
      {0:~                   }|
      {4:[No Name] [+]       }|
                          |
    ]])

    feed('oword<c-x><c-p>')
    screen:expect([[
      word wording wordy  |
      wordy^               |
      {1:word           }{0:     }|
      {1:wording        }{3:     }|
      {5:wordy          }rdy  |
      wordy               |
      {4:[No Name] [+]       }|
      {21:-- }{22:match 1 of 3}     |
    ]])

    feed('<esc>u<c-w><c-w>oword<c-x><c-p>')
    screen:expect([[
      word wording wordy  |
      wordy               |
      {23:word           }{0:     }|
      {23:wording        }{4:     }|
      {24:wordy          }rdy  |
      wordy^               |
      {3:[No Name] [+]       }|
      {21:-- }{22:match 1 of 3}     |
    ]])
  end)

  it('can override CursorLine and CursorLineNr', function()
    -- CursorLine used to be parsed as CursorLineNr, because strncmp
    command('set cursorline number')
    command('split')
    command('set winhl=CursorLine:Background1')
    screen:expect{grid=[[
      {28:  1 }{1:^                }|
      {0:~                   }|
      {0:~                   }|
      {3:[No Name]           }|
      {28:  1 }{18:                }|
      {0:~                   }|
      {4:[No Name]           }|
                          |
    ]]}

    command('set winhl=CursorLineNr:Background2,CursorLine:Background1')
    screen:expect{grid=[[
      {5:  1 }{1:^                }|
      {0:~                   }|
      {0:~                   }|
      {3:[No Name]           }|
      {28:  1 }{18:                }|
      {0:~                   }|
      {4:[No Name]           }|
                          |
    ]]}

    feed('<c-w>w')
    screen:expect{grid=[[
      {5:  1 }{1:                }|
      {0:~                   }|
      {0:~                   }|
      {4:[No Name]           }|
      {28:  1 }{18:^                }|
      {0:~                   }|
      {3:[No Name]           }|
                          |
    ]]}
  end)

  it('can override StatusLine and StatusLineNC', function()
    command('set winhighlight=StatusLine:Background1,StatusLineNC:Background2')
    command('split')
    screen:expect([[
      ^                    |
      {0:~                   }|
      {0:~                   }|
      {1:[No Name]           }|
                          |
      {0:~                   }|
      {5:[No Name]           }|
                          |
    ]])
  end)

  it('can override WinBar and WinBarNC #19345', function()
    command('setlocal winbar=foobar')
    command('set winhighlight=WinBar:Background1,WinBarNC:Background2')
    command('split')
    screen:expect([[
      {1:foobar              }|
      ^                    |
      {0:~                   }|
      {3:[No Name]           }|
      {5:foobar              }|
                          |
      {4:[No Name]           }|
                          |
    ]])
  end)


  it("can override syntax groups", function()
    command('syntax on')
    command('syntax keyword Foobar foobar')
    command('syntax keyword Article the')
    command('hi Foobar guibg=#FF0000')
    command('hi Article guifg=#00FF00 gui=bold')
    insert('the foobar was foobar')
    screen:expect([[
      {25:the} {26:foobar} was {26:fooba}|
      {26:^r}                   |
      {0:~                   }|
      {0:~                   }|
      {0:~                   }|
      {0:~                   }|
      {0:~                   }|
                          |
    ]])

    command('split')
    command('set winhl=Foobar:Background1,Article:ErrorMsg')
    screen:expect{grid=[[
      {15:the} {1:foobar} was {1:fooba}|
      {1:^r}                   |
      {0:~                   }|
      {3:[No Name] [+]       }|
      {25:the} {26:foobar} was {26:fooba}|
      {26:r}                   |
      {4:[No Name] [+]       }|
                          |
    ]]}
  end)

  it('can be disabled in newly opened window #19823', function()
    command('split | set winhl=Normal:ErrorMsg | set winhl=')
    screen:expect{grid=[[
      ^                    |
      {0:~                   }|
      {0:~                   }|
      {3:[No Name]           }|
                          |
      {0:~                   }|
      {4:[No Name]           }|
                          |
    ]]}

    helpers.assert_alive()
  end)

  it('can redraw statusline on cursor movement', function()
    screen:try_resize(40, 8)
    exec [[
      set statusline=%f%=%#Background1#%l,%c%V\ %P
      split
    ]]
    insert [[
      some text
      more text]]
    screen:expect{grid=[[
      some text                               |
      more tex^t                               |
      {0:~                                       }|
      {3:[No Name]                        }{1:2,9 All}|
      some text                               |
      more text                               |
      {4:[No Name]                        }{1:1,1 All}|
                                              |
    ]]}

    command 'set winhl=Background1:Background2'
    screen:expect{grid=[[
      some text                               |
      more tex^t                               |
      {0:~                                       }|
      {3:[No Name]                        }{5:2,9 All}|
      some text                               |
      more text                               |
      {4:[No Name]                        }{1:1,1 All}|
                                              |
    ]]}

    feed 'k'
    screen:expect{grid=[[
      some tex^t                               |
      more text                               |
      {0:~                                       }|
      {3:[No Name]                        }{5:1,9 All}|
      some text                               |
      more text                               |
      {4:[No Name]                        }{1:1,1 All}|
                                              |
    ]]}
  end)

  it('can link to empty highlight group', function()
    command 'hi NormalNC guibg=Red' -- czerwone time
    command 'set winhl=NormalNC:Normal'
    command 'split'

    screen:expect{grid=[[
      ^                    |
      {0:~                   }|
      {0:~                   }|
      {3:[No Name]           }|
                          |
      {0:~                   }|
      {4:[No Name]           }|
                          |
    ]]}
  end)
end)

describe('highlight namespaces', function()
  local screen
  local ns1, ns2

  before_each(function()
    clear()
    screen = Screen.new(25,10)
    screen:attach()
    screen:set_default_attr_ids {
      [1] = {foreground = Screen.colors.Blue, bold = true};
      [2] = {background = Screen.colors.DarkGrey};
      [3] = {italic = true, foreground = Screen.colors.DarkCyan, background = Screen.colors.DarkOrange4};
      [4] = {background = Screen.colors.Magenta4};
      [5] = {background = Screen.colors.Magenta4, foreground = Screen.colors.Crimson};
      [6] = {bold = true, reverse = true};
      [7] = {reverse = true};
      [8] = {foreground = Screen.colors.Gray20};
      [9] = {foreground = Screen.colors.Blue};
      [10] = {bold = true, foreground = Screen.colors.SeaGreen};
    }

    ns1 = meths.create_namespace 'grungy'
    ns2 = meths.create_namespace 'ultrared'

    meths.set_hl(ns1, 'Normal', {bg='DarkGrey'})
    meths.set_hl(ns1, 'NonText', {bg='DarkOrange4', fg='DarkCyan', italic=true})
    meths.set_hl(ns2, 'Normal', {bg='DarkMagenta'})
    meths.set_hl(ns2, 'NonText', {fg='Crimson'})
  end)

  it('can be used globally', function()
    screen:expect{grid=[[
      ^                         |
      {1:~                        }|
      {1:~                        }|
      {1:~                        }|
      {1:~                        }|
      {1:~                        }|
      {1:~                        }|
      {1:~                        }|
      {1:~                        }|
                               |
    ]]}

    meths.set_hl_ns(ns1)
    screen:expect{grid=[[
      {2:^                         }|
      {3:~                        }|
      {3:~                        }|
      {3:~                        }|
      {3:~                        }|
      {3:~                        }|
      {3:~                        }|
      {3:~                        }|
      {3:~                        }|
                               |
    ]]}

    meths.set_hl_ns(ns2)
    screen:expect{grid=[[
      {4:^                         }|
      {5:~                        }|
      {5:~                        }|
      {5:~                        }|
      {5:~                        }|
      {5:~                        }|
      {5:~                        }|
      {5:~                        }|
      {5:~                        }|
                               |
    ]]}

    meths.set_hl_ns(0)
    screen:expect{grid=[[
      ^                         |
      {1:~                        }|
      {1:~                        }|
      {1:~                        }|
      {1:~                        }|
      {1:~                        }|
      {1:~                        }|
      {1:~                        }|
      {1:~                        }|
                               |
    ]]}
  end)

  it('can be used per window', function()
    local win1 = meths.get_current_win()
    command 'split'
    local win2 = meths.get_current_win()
    command 'split'

    meths.win_set_hl_ns(win1, ns1)
    meths.win_set_hl_ns(win2, ns2)

    screen:expect{grid=[[
      ^                         |
      {1:~                        }|
      {6:[No Name]                }|
      {4:                         }|
      {5:~                        }|
      {7:[No Name]                }|
      {2:                         }|
      {3:~                        }|
      {7:[No Name]                }|
                               |
    ]]}
  end)

  it('redraws correctly when ns=0', function()
    screen:expect{grid=[[
      ^                         |
      {1:~                        }|
      {1:~                        }|
      {1:~                        }|
      {1:~                        }|
      {1:~                        }|
      {1:~                        }|
      {1:~                        }|
      {1:~                        }|
                               |
    ]]}

    meths.set_hl(0, 'EndOfBuffer', {fg='#333333'})
    screen:expect{grid=[[
      ^                         |
      {8:~                        }|
      {8:~                        }|
      {8:~                        }|
      {8:~                        }|
      {8:~                        }|
      {8:~                        }|
      {8:~                        }|
      {8:~                        }|
                               |
    ]]}
  end)

  it('winhl does not accept invalid value #24586', function()
    local res = exec_lua([[
      local curwin = vim.api.nvim_get_current_win()
      vim.api.nvim_command("set winhl=Normal:Visual")
      local _, msg = pcall(vim.api.nvim_command,"set winhl='Normal:Wrong'")
      return { msg, vim.wo[curwin].winhl }
    ]])
    eq({
     "Vim(set):E5248: Invalid character in group name",
     "Normal:Visual",
    },res)
  end)

  it('Normal in set_hl #25474', function()
    meths.set_hl(0, 'Normal', {bg='#333333'})
    command('highlight Ignore')
    screen:expect{grid=[[
                               |
      {1:~                        }|
      {1:~                        }|
      {6:                         }|
                               |
      Ignore         {8:xxx} {9:ctermf}|
      {9:g=}15               {9:guifg=}|
      bg                       |
      {10:Press ENTER or type comma}|
      {10:nd to continue}^           |
    ]]}
  end)
end)