Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 1 | " Tests for ":highlight" and highlighting. |
| 2 | |
| 3 | source view_util.vim |
Bram Moolenaar | c07ff5c | 2019-01-30 21:41:14 +0100 | [diff] [blame] | 4 | source screendump.vim |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 5 | source check.vim |
Bram Moolenaar | e8df010 | 2020-09-18 19:40:45 +0200 | [diff] [blame] | 6 | source script_util.vim |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 7 | |
Bram Moolenaar | 75373f3 | 2017-08-07 22:02:30 +0200 | [diff] [blame] | 8 | func Test_highlight() |
| 9 | " basic test if ":highlight" doesn't crash |
| 10 | highlight |
| 11 | hi Search |
| 12 | |
| 13 | " test setting colors. |
| 14 | " test clearing one color and all doesn't generate error or warning |
| 15 | silent! hi NewGroup term=bold cterm=italic ctermfg=DarkBlue ctermbg=Grey gui= guifg=#00ff00 guibg=Cyan |
| 16 | silent! hi Group2 term= cterm= |
| 17 | hi Group3 term=underline cterm=bold |
| 18 | |
| 19 | let res = split(execute("hi NewGroup"), "\n")[0] |
| 20 | " filter ctermfg and ctermbg, the numbers depend on the terminal |
| 21 | let res = substitute(res, 'ctermfg=\d*', 'ctermfg=2', '') |
| 22 | let res = substitute(res, 'ctermbg=\d*', 'ctermbg=3', '') |
| 23 | call assert_equal("NewGroup xxx term=bold cterm=italic ctermfg=2 ctermbg=3", |
| 24 | \ res) |
| 25 | call assert_equal("Group2 xxx cleared", |
| 26 | \ split(execute("hi Group2"), "\n")[0]) |
| 27 | call assert_equal("Group3 xxx term=underline cterm=bold", |
| 28 | \ split(execute("hi Group3"), "\n")[0]) |
| 29 | |
| 30 | hi clear NewGroup |
| 31 | call assert_equal("NewGroup xxx cleared", |
| 32 | \ split(execute("hi NewGroup"), "\n")[0]) |
| 33 | call assert_equal("Group2 xxx cleared", |
| 34 | \ split(execute("hi Group2"), "\n")[0]) |
| 35 | hi Group2 NONE |
| 36 | call assert_equal("Group2 xxx cleared", |
| 37 | \ split(execute("hi Group2"), "\n")[0]) |
| 38 | hi clear |
| 39 | call assert_equal("Group3 xxx cleared", |
| 40 | \ split(execute("hi Group3"), "\n")[0]) |
| 41 | call assert_fails("hi Crash term='asdf", "E475:") |
| 42 | endfunc |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 43 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 44 | func HighlightArgs(name) |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 45 | return 'hi ' . substitute(split(execute('hi ' . a:name), '\n')[0], '\<xxx\>', '', '') |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 46 | endfunc |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 47 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 48 | func IsColorable() |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 49 | return has('gui_running') || str2nr(&t_Co) >= 8 |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 50 | endfunc |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 51 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 52 | func HiCursorLine() |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 53 | let hiCursorLine = HighlightArgs('CursorLine') |
| 54 | if has('gui_running') |
| 55 | let guibg = matchstr(hiCursorLine, 'guibg=\w\+') |
| 56 | let hi_ul = 'hi CursorLine gui=underline guibg=NONE' |
| 57 | let hi_bg = 'hi CursorLine gui=NONE ' . guibg |
| 58 | else |
| 59 | let hi_ul = 'hi CursorLine cterm=underline ctermbg=NONE' |
| 60 | let hi_bg = 'hi CursorLine cterm=NONE ctermbg=Gray' |
| 61 | endif |
| 62 | return [hiCursorLine, hi_ul, hi_bg] |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 63 | endfunc |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 64 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 65 | func Check_lcs_eol_attrs(attrs, row, col) |
Bram Moolenaar | 5ece3e3 | 2017-10-01 14:35:02 +0200 | [diff] [blame] | 66 | let save_lcs = &lcs |
| 67 | set list |
| 68 | |
| 69 | call assert_equal(a:attrs, ScreenAttrs(a:row, a:col)[0]) |
| 70 | |
| 71 | set nolist |
| 72 | let &lcs = save_lcs |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 73 | endfunc |
Bram Moolenaar | 5ece3e3 | 2017-10-01 14:35:02 +0200 | [diff] [blame] | 74 | |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 75 | func Test_highlight_eol_with_cursorline() |
| 76 | let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine() |
| 77 | |
| 78 | call NewWindow('topleft 5', 20) |
| 79 | call setline(1, 'abcd') |
| 80 | call matchadd('Search', '\n') |
| 81 | |
| 82 | " expected: |
| 83 | " 'abcd ' |
| 84 | " ^^^^ ^^^^^ no highlight |
| 85 | " ^ 'Search' highlight |
| 86 | let attrs0 = ScreenAttrs(1, 10)[0] |
| 87 | call assert_equal(repeat([attrs0[0]], 4), attrs0[0:3]) |
| 88 | call assert_equal(repeat([attrs0[0]], 5), attrs0[5:9]) |
| 89 | call assert_notequal(attrs0[0], attrs0[4]) |
| 90 | |
| 91 | setlocal cursorline |
| 92 | |
| 93 | " underline |
| 94 | exe hi_ul |
| 95 | |
| 96 | " expected: |
| 97 | " 'abcd ' |
| 98 | " ^^^^ underline |
Bram Moolenaar | 5ece3e3 | 2017-10-01 14:35:02 +0200 | [diff] [blame] | 99 | " ^ 'Search' highlight with underline |
| 100 | " ^^^^^ underline |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 101 | let attrs = ScreenAttrs(1, 10)[0] |
| 102 | call assert_equal(repeat([attrs[0]], 4), attrs[0:3]) |
| 103 | call assert_equal([attrs[4]] + repeat([attrs[5]], 5), attrs[4:9]) |
| 104 | call assert_notequal(attrs[0], attrs[4]) |
| 105 | call assert_notequal(attrs[4], attrs[5]) |
| 106 | call assert_notequal(attrs0[0], attrs[0]) |
| 107 | call assert_notequal(attrs0[4], attrs[4]) |
Bram Moolenaar | 5ece3e3 | 2017-10-01 14:35:02 +0200 | [diff] [blame] | 108 | call Check_lcs_eol_attrs(attrs, 1, 10) |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 109 | |
| 110 | if IsColorable() |
| 111 | " bg-color |
| 112 | exe hi_bg |
| 113 | |
| 114 | " expected: |
| 115 | " 'abcd ' |
| 116 | " ^^^^ bg-color of 'CursorLine' |
| 117 | " ^ 'Search' highlight |
| 118 | " ^^^^^ bg-color of 'CursorLine' |
| 119 | let attrs = ScreenAttrs(1, 10)[0] |
| 120 | call assert_equal(repeat([attrs[0]], 4), attrs[0:3]) |
| 121 | call assert_equal(repeat([attrs[5]], 5), attrs[5:9]) |
| 122 | call assert_equal(attrs0[4], attrs[4]) |
| 123 | call assert_notequal(attrs[0], attrs[4]) |
| 124 | call assert_notequal(attrs[4], attrs[5]) |
| 125 | call assert_notequal(attrs0[0], attrs[0]) |
| 126 | call assert_notequal(attrs0[5], attrs[5]) |
Bram Moolenaar | 5ece3e3 | 2017-10-01 14:35:02 +0200 | [diff] [blame] | 127 | call Check_lcs_eol_attrs(attrs, 1, 10) |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 128 | endif |
| 129 | |
| 130 | call CloseWindow() |
| 131 | exe hiCursorLine |
| 132 | endfunc |
| 133 | |
| 134 | func Test_highlight_eol_with_cursorline_vertsplit() |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 135 | let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine() |
| 136 | |
| 137 | call NewWindow('topleft 5', 5) |
| 138 | call setline(1, 'abcd') |
| 139 | call matchadd('Search', '\n') |
| 140 | |
| 141 | let expected = "abcd |abcd " |
| 142 | let actual = ScreenLines(1, 15)[0] |
| 143 | call assert_equal(expected, actual) |
| 144 | |
| 145 | " expected: |
| 146 | " 'abcd |abcd ' |
| 147 | " ^^^^ ^^^^^^^^^ no highlight |
| 148 | " ^ 'Search' highlight |
| 149 | " ^ 'VertSplit' highlight |
| 150 | let attrs0 = ScreenAttrs(1, 15)[0] |
| 151 | call assert_equal(repeat([attrs0[0]], 4), attrs0[0:3]) |
| 152 | call assert_equal(repeat([attrs0[0]], 9), attrs0[6:14]) |
| 153 | call assert_notequal(attrs0[0], attrs0[4]) |
| 154 | call assert_notequal(attrs0[0], attrs0[5]) |
| 155 | call assert_notequal(attrs0[4], attrs0[5]) |
| 156 | |
| 157 | setlocal cursorline |
| 158 | |
| 159 | " expected: |
| 160 | " 'abcd |abcd ' |
| 161 | " ^^^^ underline |
| 162 | " ^ 'Search' highlight with underline |
| 163 | " ^ 'VertSplit' highlight |
| 164 | " ^^^^^^^^^ no highlight |
| 165 | |
| 166 | " underline |
| 167 | exe hi_ul |
| 168 | |
| 169 | let actual = ScreenLines(1, 15)[0] |
| 170 | call assert_equal(expected, actual) |
| 171 | |
| 172 | let attrs = ScreenAttrs(1, 15)[0] |
| 173 | call assert_equal(repeat([attrs[0]], 4), attrs[0:3]) |
| 174 | call assert_equal(repeat([attrs[6]], 9), attrs[6:14]) |
| 175 | call assert_equal(attrs0[5:14], attrs[5:14]) |
| 176 | call assert_notequal(attrs[0], attrs[4]) |
| 177 | call assert_notequal(attrs[0], attrs[5]) |
| 178 | call assert_notequal(attrs[0], attrs[6]) |
| 179 | call assert_notequal(attrs[4], attrs[5]) |
| 180 | call assert_notequal(attrs[5], attrs[6]) |
| 181 | call assert_notequal(attrs0[0], attrs[0]) |
| 182 | call assert_notequal(attrs0[4], attrs[4]) |
Bram Moolenaar | 5ece3e3 | 2017-10-01 14:35:02 +0200 | [diff] [blame] | 183 | call Check_lcs_eol_attrs(attrs, 1, 15) |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 184 | |
| 185 | if IsColorable() |
| 186 | " bg-color |
| 187 | exe hi_bg |
| 188 | |
| 189 | let actual = ScreenLines(1, 15)[0] |
| 190 | call assert_equal(expected, actual) |
| 191 | |
| 192 | let attrs = ScreenAttrs(1, 15)[0] |
| 193 | call assert_equal(repeat([attrs[0]], 4), attrs[0:3]) |
| 194 | call assert_equal(repeat([attrs[6]], 9), attrs[6:14]) |
| 195 | call assert_equal(attrs0[5:14], attrs[5:14]) |
| 196 | call assert_notequal(attrs[0], attrs[4]) |
| 197 | call assert_notequal(attrs[0], attrs[5]) |
| 198 | call assert_notequal(attrs[0], attrs[6]) |
| 199 | call assert_notequal(attrs[4], attrs[5]) |
| 200 | call assert_notequal(attrs[5], attrs[6]) |
| 201 | call assert_notequal(attrs0[0], attrs[0]) |
| 202 | call assert_equal(attrs0[4], attrs[4]) |
Bram Moolenaar | 5ece3e3 | 2017-10-01 14:35:02 +0200 | [diff] [blame] | 203 | call Check_lcs_eol_attrs(attrs, 1, 15) |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 204 | endif |
| 205 | |
| 206 | call CloseWindow() |
| 207 | exe hiCursorLine |
| 208 | endfunc |
| 209 | |
| 210 | func Test_highlight_eol_with_cursorline_rightleft() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 211 | CheckFeature rightleft |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 212 | |
| 213 | let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine() |
| 214 | |
| 215 | call NewWindow('topleft 5', 10) |
| 216 | setlocal rightleft |
| 217 | call setline(1, 'abcd') |
| 218 | call matchadd('Search', '\n') |
| 219 | let attrs0 = ScreenAttrs(1, 10)[0] |
| 220 | |
| 221 | setlocal cursorline |
| 222 | |
| 223 | " underline |
| 224 | exe hi_ul |
| 225 | |
| 226 | " expected: |
| 227 | " ' dcba' |
| 228 | " ^^^^ underline |
| 229 | " ^ 'Search' highlight with underline |
| 230 | " ^^^^^ underline |
| 231 | let attrs = ScreenAttrs(1, 10)[0] |
| 232 | call assert_equal(repeat([attrs[9]], 4), attrs[6:9]) |
| 233 | call assert_equal(repeat([attrs[4]], 5) + [attrs[5]], attrs[0:5]) |
| 234 | call assert_notequal(attrs[9], attrs[5]) |
| 235 | call assert_notequal(attrs[4], attrs[5]) |
| 236 | call assert_notequal(attrs0[9], attrs[9]) |
| 237 | call assert_notequal(attrs0[5], attrs[5]) |
Bram Moolenaar | 5ece3e3 | 2017-10-01 14:35:02 +0200 | [diff] [blame] | 238 | call Check_lcs_eol_attrs(attrs, 1, 10) |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 239 | |
| 240 | if IsColorable() |
| 241 | " bg-color |
| 242 | exe hi_bg |
| 243 | |
| 244 | " expected: |
| 245 | " ' dcba' |
| 246 | " ^^^^ bg-color of 'CursorLine' |
| 247 | " ^ 'Search' highlight |
| 248 | " ^^^^^ bg-color of 'CursorLine' |
| 249 | let attrs = ScreenAttrs(1, 10)[0] |
| 250 | call assert_equal(repeat([attrs[9]], 4), attrs[6:9]) |
| 251 | call assert_equal(repeat([attrs[4]], 5), attrs[0:4]) |
| 252 | call assert_equal(attrs0[5], attrs[5]) |
| 253 | call assert_notequal(attrs[9], attrs[5]) |
| 254 | call assert_notequal(attrs[5], attrs[4]) |
| 255 | call assert_notequal(attrs0[9], attrs[9]) |
| 256 | call assert_notequal(attrs0[4], attrs[4]) |
Bram Moolenaar | 5ece3e3 | 2017-10-01 14:35:02 +0200 | [diff] [blame] | 257 | call Check_lcs_eol_attrs(attrs, 1, 10) |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 258 | endif |
| 259 | |
| 260 | call CloseWindow() |
| 261 | exe hiCursorLine |
| 262 | endfunc |
| 263 | |
| 264 | func Test_highlight_eol_with_cursorline_linewrap() |
| 265 | let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine() |
| 266 | |
| 267 | call NewWindow('topleft 5', 10) |
| 268 | call setline(1, [repeat('a', 51) . 'bcd', '']) |
| 269 | call matchadd('Search', '\n') |
| 270 | |
| 271 | setlocal wrap |
| 272 | normal! gg$ |
| 273 | let attrs0 = ScreenAttrs(5, 10)[0] |
| 274 | setlocal cursorline |
| 275 | |
| 276 | " underline |
| 277 | exe hi_ul |
| 278 | |
| 279 | " expected: |
| 280 | " 'abcd ' |
| 281 | " ^^^^ underline |
| 282 | " ^ 'Search' highlight with underline |
| 283 | " ^^^^^ underline |
| 284 | let attrs = ScreenAttrs(5, 10)[0] |
| 285 | call assert_equal(repeat([attrs[0]], 4), attrs[0:3]) |
| 286 | call assert_equal([attrs[4]] + repeat([attrs[5]], 5), attrs[4:9]) |
| 287 | call assert_notequal(attrs[0], attrs[4]) |
| 288 | call assert_notequal(attrs[4], attrs[5]) |
| 289 | call assert_notequal(attrs0[0], attrs[0]) |
| 290 | call assert_notequal(attrs0[4], attrs[4]) |
Bram Moolenaar | 5ece3e3 | 2017-10-01 14:35:02 +0200 | [diff] [blame] | 291 | call Check_lcs_eol_attrs(attrs, 5, 10) |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 292 | |
| 293 | if IsColorable() |
| 294 | " bg-color |
| 295 | exe hi_bg |
| 296 | |
| 297 | " expected: |
| 298 | " 'abcd ' |
| 299 | " ^^^^ bg-color of 'CursorLine' |
| 300 | " ^ 'Search' highlight |
| 301 | " ^^^^^ bg-color of 'CursorLine' |
| 302 | let attrs = ScreenAttrs(5, 10)[0] |
| 303 | call assert_equal(repeat([attrs[0]], 4), attrs[0:3]) |
| 304 | call assert_equal(repeat([attrs[5]], 5), attrs[5:9]) |
| 305 | call assert_equal(attrs0[4], attrs[4]) |
| 306 | call assert_notequal(attrs[0], attrs[4]) |
| 307 | call assert_notequal(attrs[4], attrs[5]) |
| 308 | call assert_notequal(attrs0[0], attrs[0]) |
| 309 | call assert_notequal(attrs0[5], attrs[5]) |
Bram Moolenaar | 5ece3e3 | 2017-10-01 14:35:02 +0200 | [diff] [blame] | 310 | call Check_lcs_eol_attrs(attrs, 5, 10) |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 311 | endif |
| 312 | |
| 313 | setlocal nocursorline nowrap |
| 314 | normal! gg$ |
| 315 | let attrs0 = ScreenAttrs(1, 10)[0] |
| 316 | setlocal cursorline |
| 317 | |
| 318 | " underline |
| 319 | exe hi_ul |
| 320 | |
| 321 | " expected: |
| 322 | " 'aaabcd ' |
| 323 | " ^^^^^^ underline |
| 324 | " ^ 'Search' highlight with underline |
| 325 | " ^^^ underline |
| 326 | let attrs = ScreenAttrs(1, 10)[0] |
| 327 | call assert_equal(repeat([attrs[0]], 6), attrs[0:5]) |
| 328 | call assert_equal([attrs[6]] + repeat([attrs[7]], 3), attrs[6:9]) |
| 329 | call assert_notequal(attrs[0], attrs[6]) |
| 330 | call assert_notequal(attrs[6], attrs[7]) |
| 331 | call assert_notequal(attrs0[0], attrs[0]) |
| 332 | call assert_notequal(attrs0[6], attrs[6]) |
Bram Moolenaar | 5ece3e3 | 2017-10-01 14:35:02 +0200 | [diff] [blame] | 333 | call Check_lcs_eol_attrs(attrs, 1, 10) |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 334 | |
| 335 | if IsColorable() |
| 336 | " bg-color |
| 337 | exe hi_bg |
| 338 | |
| 339 | " expected: |
| 340 | " 'aaabcd ' |
| 341 | " ^^^^^^ bg-color of 'CursorLine' |
| 342 | " ^ 'Search' highlight |
| 343 | " ^^^ bg-color of 'CursorLine' |
| 344 | let attrs = ScreenAttrs(1, 10)[0] |
| 345 | call assert_equal(repeat([attrs[0]], 6), attrs[0:5]) |
| 346 | call assert_equal(repeat([attrs[7]], 3), attrs[7:9]) |
| 347 | call assert_equal(attrs0[6], attrs[6]) |
| 348 | call assert_notequal(attrs[0], attrs[6]) |
| 349 | call assert_notequal(attrs[6], attrs[7]) |
| 350 | call assert_notequal(attrs0[0], attrs[0]) |
| 351 | call assert_notequal(attrs0[7], attrs[7]) |
Bram Moolenaar | 5ece3e3 | 2017-10-01 14:35:02 +0200 | [diff] [blame] | 352 | call Check_lcs_eol_attrs(attrs, 1, 10) |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 353 | endif |
| 354 | |
| 355 | call CloseWindow() |
| 356 | exe hiCursorLine |
| 357 | endfunc |
| 358 | |
| 359 | func Test_highlight_eol_with_cursorline_sign() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 360 | CheckFeature signs |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 361 | |
| 362 | let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine() |
| 363 | |
| 364 | call NewWindow('topleft 5', 10) |
| 365 | call setline(1, 'abcd') |
| 366 | call matchadd('Search', '\n') |
| 367 | |
| 368 | sign define Sign text=>> |
| 369 | exe 'sign place 1 line=1 name=Sign buffer=' . bufnr('') |
| 370 | let attrs0 = ScreenAttrs(1, 10)[0] |
| 371 | setlocal cursorline |
| 372 | |
| 373 | " underline |
| 374 | exe hi_ul |
| 375 | |
| 376 | " expected: |
| 377 | " '>>abcd ' |
| 378 | " ^^ sign |
| 379 | " ^^^^ underline |
| 380 | " ^ 'Search' highlight with underline |
| 381 | " ^^^ underline |
| 382 | let attrs = ScreenAttrs(1, 10)[0] |
| 383 | call assert_equal(repeat([attrs[2]], 4), attrs[2:5]) |
| 384 | call assert_equal([attrs[6]] + repeat([attrs[7]], 3), attrs[6:9]) |
| 385 | call assert_notequal(attrs[2], attrs[6]) |
| 386 | call assert_notequal(attrs[6], attrs[7]) |
| 387 | call assert_notequal(attrs0[2], attrs[2]) |
| 388 | call assert_notequal(attrs0[6], attrs[6]) |
Bram Moolenaar | 5ece3e3 | 2017-10-01 14:35:02 +0200 | [diff] [blame] | 389 | call Check_lcs_eol_attrs(attrs, 1, 10) |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 390 | |
| 391 | if IsColorable() |
| 392 | " bg-color |
| 393 | exe hi_bg |
| 394 | |
| 395 | " expected: |
| 396 | " '>>abcd ' |
| 397 | " ^^ sign |
| 398 | " ^^^^ bg-color of 'CursorLine' |
| 399 | " ^ 'Search' highlight |
| 400 | " ^^^ bg-color of 'CursorLine' |
| 401 | let attrs = ScreenAttrs(1, 10)[0] |
| 402 | call assert_equal(repeat([attrs[2]], 4), attrs[2:5]) |
| 403 | call assert_equal(repeat([attrs[7]], 3), attrs[7:9]) |
| 404 | call assert_equal(attrs0[6], attrs[6]) |
| 405 | call assert_notequal(attrs[2], attrs[6]) |
| 406 | call assert_notequal(attrs[6], attrs[7]) |
| 407 | call assert_notequal(attrs0[2], attrs[2]) |
| 408 | call assert_notequal(attrs0[7], attrs[7]) |
Bram Moolenaar | 5ece3e3 | 2017-10-01 14:35:02 +0200 | [diff] [blame] | 409 | call Check_lcs_eol_attrs(attrs, 1, 10) |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 410 | endif |
| 411 | |
| 412 | sign unplace 1 |
| 413 | call CloseWindow() |
| 414 | exe hiCursorLine |
| 415 | endfunc |
| 416 | |
| 417 | func Test_highlight_eol_with_cursorline_breakindent() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 418 | CheckFeature linebreak |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 419 | |
| 420 | let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine() |
| 421 | |
| 422 | call NewWindow('topleft 5', 10) |
Bram Moolenaar | ee85702 | 2019-11-09 23:26:40 +0100 | [diff] [blame] | 423 | set showbreak=xxx |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 424 | setlocal breakindent breakindentopt=min:0,shift:1 showbreak=> |
| 425 | call setline(1, ' ' . repeat('a', 9) . 'bcd') |
| 426 | call matchadd('Search', '\n') |
| 427 | let attrs0 = ScreenAttrs(2, 10)[0] |
| 428 | setlocal cursorline |
| 429 | |
| 430 | " underline |
| 431 | exe hi_ul |
| 432 | |
| 433 | " expected: |
| 434 | " ' >bcd ' |
| 435 | " ^^^ breakindent and showbreak |
| 436 | " ^^^ underline |
| 437 | " ^ 'Search' highlight with underline |
| 438 | " ^^^ underline |
| 439 | let attrs = ScreenAttrs(2, 10)[0] |
| 440 | call assert_equal(repeat([attrs[0]], 2), attrs[0:1]) |
| 441 | call assert_equal(repeat([attrs[3]], 3), attrs[3:5]) |
| 442 | call assert_equal([attrs[6]] + repeat([attrs[7]], 3), attrs[6:9]) |
| 443 | call assert_equal(attrs0[0], attrs[0]) |
| 444 | call assert_notequal(attrs[0], attrs[2]) |
| 445 | call assert_notequal(attrs[2], attrs[3]) |
| 446 | call assert_notequal(attrs[3], attrs[6]) |
| 447 | call assert_notequal(attrs[6], attrs[7]) |
| 448 | call assert_notequal(attrs0[2], attrs[2]) |
| 449 | call assert_notequal(attrs0[3], attrs[3]) |
| 450 | call assert_notequal(attrs0[6], attrs[6]) |
Bram Moolenaar | 5ece3e3 | 2017-10-01 14:35:02 +0200 | [diff] [blame] | 451 | call Check_lcs_eol_attrs(attrs, 2, 10) |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 452 | |
| 453 | if IsColorable() |
| 454 | " bg-color |
| 455 | exe hi_bg |
| 456 | |
| 457 | " expected: |
| 458 | " ' >bcd ' |
| 459 | " ^^^ breakindent and showbreak |
| 460 | " ^^^ bg-color of 'CursorLine' |
| 461 | " ^ 'Search' highlight |
| 462 | " ^^^ bg-color of 'CursorLine' |
| 463 | let attrs = ScreenAttrs(2, 10)[0] |
| 464 | call assert_equal(repeat([attrs[0]], 2), attrs[0:1]) |
| 465 | call assert_equal(repeat([attrs[3]], 3), attrs[3:5]) |
| 466 | call assert_equal(repeat([attrs[7]], 3), attrs[7:9]) |
| 467 | call assert_equal(attrs0[0], attrs[0]) |
| 468 | call assert_equal(attrs0[6], attrs[6]) |
| 469 | call assert_notequal(attrs[0], attrs[2]) |
| 470 | call assert_notequal(attrs[2], attrs[3]) |
| 471 | call assert_notequal(attrs[3], attrs[6]) |
| 472 | call assert_notequal(attrs[6], attrs[7]) |
| 473 | call assert_notequal(attrs0[2], attrs[2]) |
| 474 | call assert_notequal(attrs0[3], attrs[3]) |
| 475 | call assert_notequal(attrs0[7], attrs[7]) |
Bram Moolenaar | 5ece3e3 | 2017-10-01 14:35:02 +0200 | [diff] [blame] | 476 | call Check_lcs_eol_attrs(attrs, 2, 10) |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 477 | endif |
| 478 | |
| 479 | call CloseWindow() |
| 480 | set showbreak= |
Bram Moolenaar | ee85702 | 2019-11-09 23:26:40 +0100 | [diff] [blame] | 481 | setlocal showbreak= |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 482 | exe hiCursorLine |
| 483 | endfunc |
| 484 | |
| 485 | func Test_highlight_eol_on_diff() |
| 486 | call setline(1, ['abcd', '']) |
| 487 | call matchadd('Search', '\n') |
| 488 | let attrs0 = ScreenAttrs(1, 10)[0] |
| 489 | |
| 490 | diffthis |
| 491 | botright new |
| 492 | diffthis |
| 493 | |
| 494 | " expected: |
| 495 | " ' abcd ' |
| 496 | " ^^ sign |
| 497 | " ^^^^ ^^^ 'DiffAdd' highlight |
| 498 | " ^ 'Search' highlight |
| 499 | let attrs = ScreenAttrs(1, 10)[0] |
| 500 | call assert_equal(repeat([attrs[0]], 2), attrs[0:1]) |
| 501 | call assert_equal(repeat([attrs[2]], 4), attrs[2:5]) |
| 502 | call assert_equal(repeat([attrs[2]], 3), attrs[7:9]) |
| 503 | call assert_equal(attrs0[4], attrs[6]) |
| 504 | call assert_notequal(attrs[0], attrs[2]) |
| 505 | call assert_notequal(attrs[0], attrs[6]) |
| 506 | call assert_notequal(attrs[2], attrs[6]) |
Bram Moolenaar | 5ece3e3 | 2017-10-01 14:35:02 +0200 | [diff] [blame] | 507 | call Check_lcs_eol_attrs(attrs, 1, 10) |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 508 | |
| 509 | bwipe! |
| 510 | diffoff |
| 511 | endfunc |
Bram Moolenaar | f708ac5 | 2018-03-12 21:48:32 +0100 | [diff] [blame] | 512 | |
| 513 | func Test_termguicolors() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 514 | CheckOption termguicolors |
Bram Moolenaar | 310c32e | 2019-11-29 23:15:25 +0100 | [diff] [blame] | 515 | if has('vtp') && !has('vcon') && !has('gui_running') |
Bram Moolenaar | ff1e879 | 2018-03-12 22:16:37 +0100 | [diff] [blame] | 516 | " Win32: 'guicolors' doesn't work without virtual console. |
| 517 | call assert_fails('set termguicolors', 'E954:') |
| 518 | return |
| 519 | endif |
Bram Moolenaar | f708ac5 | 2018-03-12 21:48:32 +0100 | [diff] [blame] | 520 | |
| 521 | " Basic test that setting 'termguicolors' works with one color. |
| 522 | set termguicolors |
| 523 | redraw |
| 524 | set t_Co=1 |
| 525 | redraw |
| 526 | set t_Co=0 |
| 527 | redraw |
| 528 | endfunc |
Bram Moolenaar | c07ff5c | 2019-01-30 21:41:14 +0100 | [diff] [blame] | 529 | |
| 530 | func Test_cursorline_after_yank() |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 531 | CheckScreendump |
Bram Moolenaar | c07ff5c | 2019-01-30 21:41:14 +0100 | [diff] [blame] | 532 | |
| 533 | call writefile([ |
| 534 | \ 'set cul rnu', |
| 535 | \ 'call setline(1, ["","1","2","3",""])', |
| 536 | \ ], 'Xtest_cursorline_yank') |
| 537 | let buf = RunVimInTerminal('-S Xtest_cursorline_yank', {'rows': 8}) |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 538 | call TermWait(buf) |
Bram Moolenaar | c07ff5c | 2019-01-30 21:41:14 +0100 | [diff] [blame] | 539 | call term_sendkeys(buf, "Gy3k") |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 540 | call TermWait(buf) |
Bram Moolenaar | c07ff5c | 2019-01-30 21:41:14 +0100 | [diff] [blame] | 541 | call term_sendkeys(buf, "jj") |
| 542 | |
| 543 | call VerifyScreenDump(buf, 'Test_cursorline_yank_01', {}) |
| 544 | |
| 545 | " clean up |
| 546 | call StopVimInTerminal(buf) |
| 547 | call delete('Xtest_cursorline_yank') |
| 548 | endfunc |
Bram Moolenaar | 8156ed3 | 2019-03-09 11:46:15 +0100 | [diff] [blame] | 549 | |
Bram Moolenaar | fca068b | 2019-09-08 14:07:47 +0200 | [diff] [blame] | 550 | " test for issue #4862 |
| 551 | func Test_put_before_cursorline() |
| 552 | new |
| 553 | only! |
| 554 | call setline(1, 'A') |
| 555 | redraw |
| 556 | let std_attr = screenattr(1, 1) |
| 557 | set cursorline |
| 558 | redraw |
| 559 | let cul_attr = screenattr(1, 1) |
| 560 | normal yyP |
| 561 | redraw |
| 562 | " Line 1 has cursor so it should be highlighted with CursorLine. |
| 563 | call assert_equal(cul_attr, screenattr(1, 1)) |
| 564 | " And CursorLine highlighting from the second line should be gone. |
| 565 | call assert_equal(std_attr, screenattr(2, 1)) |
| 566 | set nocursorline |
| 567 | bwipe! |
| 568 | endfunc |
| 569 | |
Bram Moolenaar | 8156ed3 | 2019-03-09 11:46:15 +0100 | [diff] [blame] | 570 | func Test_cursorline_with_visualmode() |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 571 | CheckScreendump |
Bram Moolenaar | 8156ed3 | 2019-03-09 11:46:15 +0100 | [diff] [blame] | 572 | |
| 573 | call writefile([ |
| 574 | \ 'set cul', |
| 575 | \ 'call setline(1, repeat(["abc"], 50))', |
| 576 | \ ], 'Xtest_cursorline_with_visualmode') |
| 577 | let buf = RunVimInTerminal('-S Xtest_cursorline_with_visualmode', {'rows': 12}) |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 578 | call TermWait(buf) |
Bram Moolenaar | 8156ed3 | 2019-03-09 11:46:15 +0100 | [diff] [blame] | 579 | call term_sendkeys(buf, "V\<C-f>kkkjk") |
| 580 | |
| 581 | call VerifyScreenDump(buf, 'Test_cursorline_with_visualmode_01', {}) |
| 582 | |
| 583 | " clean up |
| 584 | call StopVimInTerminal(buf) |
| 585 | call delete('Xtest_cursorline_with_visualmode') |
| 586 | endfunc |
Bram Moolenaar | f90b6e0 | 2019-05-09 19:26:38 +0200 | [diff] [blame] | 587 | |
Bram Moolenaar | 193ffd1 | 2019-05-25 22:57:30 +0200 | [diff] [blame] | 588 | func Test_wincolor() |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 589 | CheckScreendump |
Bram Moolenaar | 3180fe6 | 2020-02-02 13:47:06 +0100 | [diff] [blame] | 590 | " make sure the width is enough for the test |
| 591 | set columns=80 |
Bram Moolenaar | 193ffd1 | 2019-05-25 22:57:30 +0200 | [diff] [blame] | 592 | |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 593 | let lines =<< trim END |
| 594 | set cursorline cursorcolumn rnu |
Bram Moolenaar | 053f712 | 2019-09-23 22:17:15 +0200 | [diff] [blame] | 595 | call setline(1, ["","1111111111","22222222222","3 here 3","","the cat is out of the bag"]) |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 596 | set wincolor=Pmenu |
Bram Moolenaar | 053f712 | 2019-09-23 22:17:15 +0200 | [diff] [blame] | 597 | hi CatLine guifg=green ctermfg=green |
| 598 | hi Reverse gui=reverse cterm=reverse |
| 599 | syn match CatLine /^the.*/ |
| 600 | call prop_type_add("foo", {"highlight": "Reverse", "combine": 1}) |
| 601 | call prop_add(6, 12, {"type": "foo", "end_col": 15}) |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 602 | /here |
| 603 | END |
| 604 | call writefile(lines, 'Xtest_wincolor') |
Bram Moolenaar | 193ffd1 | 2019-05-25 22:57:30 +0200 | [diff] [blame] | 605 | let buf = RunVimInTerminal('-S Xtest_wincolor', {'rows': 8}) |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 606 | call TermWait(buf) |
Bram Moolenaar | 193ffd1 | 2019-05-25 22:57:30 +0200 | [diff] [blame] | 607 | call term_sendkeys(buf, "2G5lvj") |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 608 | call TermWait(buf) |
Bram Moolenaar | 193ffd1 | 2019-05-25 22:57:30 +0200 | [diff] [blame] | 609 | |
| 610 | call VerifyScreenDump(buf, 'Test_wincolor_01', {}) |
| 611 | |
| 612 | " clean up |
| 613 | call term_sendkeys(buf, "\<Esc>") |
| 614 | call StopVimInTerminal(buf) |
| 615 | call delete('Xtest_wincolor') |
| 616 | endfunc |
| 617 | |
Bram Moolenaar | 42e931b | 2019-12-04 19:08:50 +0100 | [diff] [blame] | 618 | func Test_wincolor_listchars() |
| 619 | CheckScreendump |
Bram Moolenaar | 705724e | 2020-01-31 21:13:42 +0100 | [diff] [blame] | 620 | CheckFeature conceal |
Bram Moolenaar | 42e931b | 2019-12-04 19:08:50 +0100 | [diff] [blame] | 621 | |
| 622 | let lines =<< trim END |
| 623 | call setline(1, ["one","\t\tsome random text enough long to show 'extends' and 'precedes' includingnbsps, preceding tabs and trailing spaces ","three"]) |
| 624 | set wincolor=Todo |
| 625 | set nowrap cole=1 cocu+=n |
| 626 | set list lcs=eol:$,tab:>-,space:.,trail:_,extends:>,precedes:<,conceal:*,nbsp:# |
| 627 | call matchadd('Conceal', 'text') |
| 628 | normal 2G5zl |
| 629 | END |
| 630 | call writefile(lines, 'Xtest_wincolorlcs') |
| 631 | let buf = RunVimInTerminal('-S Xtest_wincolorlcs', {'rows': 8}) |
| 632 | |
| 633 | call VerifyScreenDump(buf, 'Test_wincolor_lcs', {}) |
| 634 | |
| 635 | " clean up |
| 636 | call term_sendkeys(buf, "\<Esc>") |
| 637 | call StopVimInTerminal(buf) |
| 638 | call delete('Xtest_wincolorlcs') |
| 639 | endfunc |
| 640 | |
Bram Moolenaar | 010ee96 | 2019-09-25 20:37:36 +0200 | [diff] [blame] | 641 | func Test_colorcolumn() |
| 642 | CheckScreendump |
| 643 | |
| 644 | " check that setting 'colorcolumn' when entering a buffer works |
| 645 | let lines =<< trim END |
| 646 | split |
| 647 | edit X |
| 648 | call setline(1, ["1111111111","22222222222","3333333333"]) |
| 649 | set nomodified |
| 650 | set colorcolumn=3,9 |
| 651 | set number cursorline cursorlineopt=number |
| 652 | wincmd w |
| 653 | buf X |
| 654 | END |
| 655 | call writefile(lines, 'Xtest_colorcolumn') |
| 656 | let buf = RunVimInTerminal('-S Xtest_colorcolumn', {'rows': 10}) |
| 657 | call term_sendkeys(buf, ":\<CR>") |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 658 | call TermWait(buf) |
Bram Moolenaar | 010ee96 | 2019-09-25 20:37:36 +0200 | [diff] [blame] | 659 | call VerifyScreenDump(buf, 'Test_colorcolumn_1', {}) |
| 660 | |
| 661 | " clean up |
| 662 | call StopVimInTerminal(buf) |
| 663 | call delete('Xtest_colorcolumn') |
| 664 | endfunc |
| 665 | |
Bram Moolenaar | ad5e563 | 2020-09-15 20:52:26 +0200 | [diff] [blame] | 666 | func Test_colorcolumn_bri() |
| 667 | CheckScreendump |
| 668 | |
| 669 | " check 'colorcolumn' when 'breakindent' is set |
| 670 | let lines =<< trim END |
| 671 | call setline(1, 'The quick brown fox jumped over the lazy dogs') |
| 672 | END |
| 673 | call writefile(lines, 'Xtest_colorcolumn_bri') |
| 674 | let buf = RunVimInTerminal('-S Xtest_colorcolumn_bri', {'rows': 10,'columns': 40}) |
| 675 | call term_sendkeys(buf, ":set co=40 linebreak bri briopt=shift:2 cc=40,41,43\<CR>") |
| 676 | call TermWait(buf) |
| 677 | call VerifyScreenDump(buf, 'Test_colorcolumn_2', {}) |
| 678 | |
| 679 | " clean up |
| 680 | call StopVimInTerminal(buf) |
| 681 | call delete('Xtest_colorcolumn_bri') |
| 682 | endfunc |
| 683 | |
| 684 | func Test_colorcolumn_sbr() |
| 685 | CheckScreendump |
| 686 | |
| 687 | " check 'colorcolumn' when 'showbreak' is set |
| 688 | let lines =<< trim END |
| 689 | call setline(1, 'The quick brown fox jumped over the lazy dogs') |
| 690 | END |
| 691 | call writefile(lines, 'Xtest_colorcolumn_srb') |
| 692 | let buf = RunVimInTerminal('-S Xtest_colorcolumn_srb', {'rows': 10,'columns': 40}) |
| 693 | call term_sendkeys(buf, ":set co=40 showbreak=+++>\\ cc=40,41,43\<CR>") |
| 694 | call TermWait(buf) |
| 695 | call VerifyScreenDump(buf, 'Test_colorcolumn_3', {}) |
| 696 | |
| 697 | " clean up |
| 698 | call StopVimInTerminal(buf) |
| 699 | call delete('Xtest_colorcolumn_srb') |
| 700 | endfunc |
| 701 | |
Bram Moolenaar | 6b528fa | 2019-05-09 20:07:33 +0200 | [diff] [blame] | 702 | " This test must come before the Test_cursorline test, as it appears this |
| 703 | " defines the Normal highlighting group anyway. |
Bram Moolenaar | f90b6e0 | 2019-05-09 19:26:38 +0200 | [diff] [blame] | 704 | func Test_1_highlight_Normalgroup_exists() |
Bram Moolenaar | 435f9f0 | 2019-07-03 21:40:16 +0200 | [diff] [blame] | 705 | let hlNormal = HighlightArgs('Normal') |
| 706 | if !has('gui_running') |
Bram Moolenaar | 6b528fa | 2019-05-09 20:07:33 +0200 | [diff] [blame] | 707 | call assert_match('hi Normal\s*clear', hlNormal) |
Bram Moolenaar | 435f9f0 | 2019-07-03 21:40:16 +0200 | [diff] [blame] | 708 | elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3') |
| 709 | " expect is DEFAULT_FONT of gui_gtk_x11.c |
| 710 | call assert_match('hi Normal\s*font=Monospace 10', hlNormal) |
| 711 | elseif has('gui_motif') || has('gui_athena') |
| 712 | " expect is DEFAULT_FONT of gui_x11.c |
| 713 | call assert_match('hi Normal\s*font=7x13', hlNormal) |
| 714 | elseif has('win32') |
| 715 | " expect any font |
| 716 | call assert_match('hi Normal\s*font=.*', hlNormal) |
Bram Moolenaar | 6b528fa | 2019-05-09 20:07:33 +0200 | [diff] [blame] | 717 | endif |
Bram Moolenaar | f90b6e0 | 2019-05-09 19:26:38 +0200 | [diff] [blame] | 718 | endfunc |
Bram Moolenaar | 548be7f | 2019-06-29 03:42:42 +0200 | [diff] [blame] | 719 | |
Bram Moolenaar | 3180fe6 | 2020-02-02 13:47:06 +0100 | [diff] [blame] | 720 | " Do this test last, sometimes restoring the columns doesn't work |
Bram Moolenaar | ee4e0c1 | 2020-04-06 21:35:05 +0200 | [diff] [blame] | 721 | func Test_z_no_space_before_xxx() |
Bram Moolenaar | 548be7f | 2019-06-29 03:42:42 +0200 | [diff] [blame] | 722 | let l:org_columns = &columns |
| 723 | set columns=17 |
| 724 | let l:hi_StatusLineTermNC = join(split(execute('hi StatusLineTermNC'))) |
| 725 | call assert_match('StatusLineTermNC xxx', l:hi_StatusLineTermNC) |
| 726 | let &columns = l:org_columns |
Bram Moolenaar | ee4e0c1 | 2020-04-06 21:35:05 +0200 | [diff] [blame] | 727 | endfunc |
| 728 | |
| 729 | " Test for :highlight command errors |
| 730 | func Test_highlight_cmd_errors() |
| 731 | if has('gui_running') |
| 732 | " This test doesn't fail in the MS-Windows console version. |
Bram Moolenaar | 75e1567 | 2020-06-28 13:10:22 +0200 | [diff] [blame] | 733 | call assert_fails('hi Xcomment ctermbg=fg', 'E419:') |
Bram Moolenaar | ee4e0c1 | 2020-04-06 21:35:05 +0200 | [diff] [blame] | 734 | call assert_fails('hi Xcomment ctermfg=bg', 'E420:') |
Bram Moolenaar | 75e1567 | 2020-06-28 13:10:22 +0200 | [diff] [blame] | 735 | call assert_fails('hi Xcomment ctermfg=ul', 'E453:') |
Bram Moolenaar | ee4e0c1 | 2020-04-06 21:35:05 +0200 | [diff] [blame] | 736 | endif |
| 737 | |
| 738 | " Try using a very long terminal code. Define a dummy terminal code for this |
| 739 | " test. |
| 740 | let &t_fo = "\<Esc>1;" |
| 741 | let c = repeat("t_fo,", 100) . "t_fo" |
| 742 | call assert_fails('exe "hi Xgroup1 start=" . c', 'E422:') |
| 743 | let &t_fo = "" |
| 744 | endfunc |
| 745 | |
Bram Moolenaar | 75e1567 | 2020-06-28 13:10:22 +0200 | [diff] [blame] | 746 | " Test for 'highlight' option |
| 747 | func Test_highlight_opt() |
| 748 | let save_hl = &highlight |
| 749 | call assert_fails('set highlight=j:b', 'E474:') |
| 750 | set highlight=f\ r |
| 751 | call assert_equal('f r', &highlight) |
| 752 | set highlight=fb |
| 753 | call assert_equal('fb', &highlight) |
| 754 | set highlight=fi |
| 755 | call assert_equal('fi', &highlight) |
| 756 | set highlight=f- |
| 757 | call assert_equal('f-', &highlight) |
| 758 | set highlight=fr |
| 759 | call assert_equal('fr', &highlight) |
| 760 | set highlight=fs |
| 761 | call assert_equal('fs', &highlight) |
| 762 | set highlight=fu |
| 763 | call assert_equal('fu', &highlight) |
| 764 | set highlight=fc |
| 765 | call assert_equal('fc', &highlight) |
| 766 | set highlight=ft |
| 767 | call assert_equal('ft', &highlight) |
| 768 | call assert_fails('set highlight=fr:Search', 'E474:') |
| 769 | set highlight=f:$# |
| 770 | call assert_match('W18:', v:statusmsg) |
| 771 | let &highlight = save_hl |
| 772 | endfunc |
| 773 | |
| 774 | " Test for User group highlighting used in the statusline |
| 775 | func Test_highlight_User() |
| 776 | CheckNotGui |
| 777 | hi User1 ctermfg=12 |
| 778 | redraw! |
| 779 | call assert_equal('12', synIDattr(synIDtrans(hlID('User1')), 'fg')) |
| 780 | hi clear |
| 781 | endfunc |
| 782 | |
| 783 | " Test for using RGB color values in a highlight group |
| 784 | func Test_highlight_RGB_color() |
| 785 | CheckGui |
| 786 | hi MySearch guifg=#110000 guibg=#001100 guisp=#000011 |
| 787 | call assert_equal('#110000', synIDattr(synIDtrans(hlID('MySearch')), 'fg#')) |
| 788 | call assert_equal('#001100', synIDattr(synIDtrans(hlID('MySearch')), 'bg#')) |
| 789 | call assert_equal('#000011', synIDattr(synIDtrans(hlID('MySearch')), 'sp#')) |
| 790 | hi clear |
| 791 | endfunc |
| 792 | |
Bram Moolenaar | de8f0f4 | 2020-06-30 18:45:43 +0200 | [diff] [blame] | 793 | " Test for using default highlighting group |
| 794 | func Test_highlight_default() |
| 795 | highlight MySearch ctermfg=7 |
| 796 | highlight default MySearch ctermfg=5 |
| 797 | let hlSearch = HighlightArgs('MySearch') |
| 798 | call assert_match('ctermfg=7', hlSearch) |
| 799 | |
| 800 | highlight default QFName ctermfg=3 |
| 801 | call assert_match('ctermfg=3', HighlightArgs('QFName')) |
| 802 | hi clear |
| 803 | endfunc |
| 804 | |
| 805 | " Test for 'ctermul in a highlight group |
| 806 | func Test_highlight_ctermul() |
| 807 | CheckNotGui |
| 808 | call assert_notmatch('ctermul=', HighlightArgs('Normal')) |
| 809 | highlight Normal ctermul=3 |
| 810 | call assert_match('ctermul=3', HighlightArgs('Normal')) |
Bram Moolenaar | 391c362 | 2020-09-29 20:59:17 +0200 | [diff] [blame] | 811 | call assert_equal('3', synIDattr(synIDtrans(hlID('Normal')), 'ul')) |
Bram Moolenaar | de8f0f4 | 2020-06-30 18:45:43 +0200 | [diff] [blame] | 812 | highlight Normal ctermul=NONE |
| 813 | endfunc |
| 814 | |
| 815 | " Test for specifying 'start' and 'stop' in a highlight group |
| 816 | func Test_highlight_start_stop() |
| 817 | hi HlGrp1 start=<Esc>[27h;<Esc>[<Space>r; |
| 818 | call assert_match("start=^[[27h;^[[ r;", HighlightArgs('HlGrp1')) |
| 819 | hi HlGrp1 start=NONE |
| 820 | call assert_notmatch("start=", HighlightArgs('HlGrp1')) |
| 821 | hi HlGrp2 stop=<Esc>[27h;<Esc>[<Space>r; |
| 822 | call assert_match("stop=^[[27h;^[[ r;", HighlightArgs('HlGrp2')) |
| 823 | hi HlGrp2 stop=NONE |
| 824 | call assert_notmatch("stop=", HighlightArgs('HlGrp2')) |
| 825 | hi clear |
| 826 | endfunc |
| 827 | |
| 828 | " Test for setting various 'term' attributes |
| 829 | func Test_highlight_term_attr() |
| 830 | hi HlGrp3 term=bold,underline,undercurl,strikethrough,reverse,italic,standout |
| 831 | call assert_equal('hi HlGrp3 term=bold,standout,underline,undercurl,italic,reverse,strikethrough', HighlightArgs('HlGrp3')) |
| 832 | hi HlGrp3 term=NONE |
| 833 | call assert_equal('hi HlGrp3 cleared', HighlightArgs('HlGrp3')) |
| 834 | hi clear |
| 835 | endfunc |
| 836 | |
Bram Moolenaar | 213da55 | 2020-09-17 19:59:26 +0200 | [diff] [blame] | 837 | func Test_highlight_clear_restores_links() |
| 838 | let aaa_id = hlID('aaa') |
| 839 | call assert_equal(aaa_id, 0) |
| 840 | |
| 841 | " create default link aaa --> bbb |
| 842 | hi def link aaa bbb |
| 843 | let id_aaa = hlID('aaa') |
| 844 | let hl_aaa_bbb = HighlightArgs('aaa') |
| 845 | |
| 846 | " try to redefine default link aaa --> ccc; check aaa --> bbb |
| 847 | hi def link aaa ccc |
| 848 | call assert_equal(HighlightArgs('aaa'), hl_aaa_bbb) |
| 849 | |
| 850 | " clear aaa; check aaa --> bbb |
| 851 | hi clear aaa |
| 852 | call assert_equal(HighlightArgs('aaa'), hl_aaa_bbb) |
| 853 | |
| 854 | " link aaa --> ccc; clear aaa; check aaa --> bbb |
| 855 | hi link aaa ccc |
| 856 | let id_ccc = hlID('ccc') |
| 857 | call assert_equal(synIDtrans(id_aaa), id_ccc) |
| 858 | hi clear aaa |
| 859 | call assert_equal(HighlightArgs('aaa'), hl_aaa_bbb) |
| 860 | |
| 861 | " forcibly set default link aaa --> ddd |
| 862 | hi! def link aaa ddd |
| 863 | let id_ddd = hlID('ddd') |
| 864 | let hl_aaa_ddd = HighlightArgs('aaa') |
| 865 | call assert_equal(synIDtrans(id_aaa), id_ddd) |
| 866 | |
| 867 | " link aaa --> eee; clear aaa; check aaa --> ddd |
| 868 | hi link aaa eee |
| 869 | let eee_id = hlID('eee') |
| 870 | call assert_equal(synIDtrans(id_aaa), eee_id) |
| 871 | hi clear aaa |
| 872 | call assert_equal(HighlightArgs('aaa'), hl_aaa_ddd) |
| 873 | endfunc |
| 874 | |
Bram Moolenaar | e8df010 | 2020-09-18 19:40:45 +0200 | [diff] [blame] | 875 | func Test_highlight_clear_restores_context() |
| 876 | func FuncContextDefault() |
| 877 | hi def link Context ContextDefault |
| 878 | endfun |
| 879 | |
| 880 | func FuncContextRelink() |
| 881 | " Dummy line |
| 882 | hi link Context ContextRelink |
| 883 | endfunc |
| 884 | |
| 885 | let scriptContextDefault = MakeScript("FuncContextDefault") |
| 886 | let scriptContextRelink = MakeScript("FuncContextRelink") |
| 887 | let patContextDefault = fnamemodify(scriptContextDefault, ':t') .. ' line 1' |
| 888 | let patContextRelink = fnamemodify(scriptContextRelink, ':t') .. ' line 2' |
| 889 | |
Bram Moolenaar | 2bbada8 | 2020-09-18 21:55:26 +0200 | [diff] [blame] | 890 | exec 'source ' .. scriptContextDefault |
Bram Moolenaar | e8df010 | 2020-09-18 19:40:45 +0200 | [diff] [blame] | 891 | let hlContextDefault = execute("verbose hi Context") |
| 892 | call assert_match(patContextDefault, hlContextDefault) |
| 893 | |
Bram Moolenaar | 2bbada8 | 2020-09-18 21:55:26 +0200 | [diff] [blame] | 894 | exec 'source ' .. scriptContextRelink |
Bram Moolenaar | e8df010 | 2020-09-18 19:40:45 +0200 | [diff] [blame] | 895 | let hlContextRelink = execute("verbose hi Context") |
| 896 | call assert_match(patContextRelink, hlContextRelink) |
| 897 | |
| 898 | hi clear |
| 899 | let hlContextAfterClear = execute("verbose hi Context") |
| 900 | call assert_match(patContextDefault, hlContextAfterClear) |
| 901 | |
| 902 | delfunc FuncContextDefault |
| 903 | delfunc FuncContextRelink |
| 904 | call delete(scriptContextDefault) |
| 905 | call delete(scriptContextRelink) |
| 906 | endfunc |
| 907 | |
Bram Moolenaar | 213da55 | 2020-09-17 19:59:26 +0200 | [diff] [blame] | 908 | func Test_highlight_default_colorscheme_restores_links() |
| 909 | hi link TestLink Identifier |
| 910 | hi TestHi ctermbg=red |
Bram Moolenaar | 05eb5b9 | 2020-09-16 15:43:21 +0200 | [diff] [blame] | 911 | |
| 912 | let hlTestLinkPre = HighlightArgs('TestLink') |
| 913 | let hlTestHiPre = HighlightArgs('TestHi') |
| 914 | |
| 915 | " Test colorscheme |
| 916 | hi clear |
| 917 | if exists('syntax_on') |
| 918 | syntax reset |
| 919 | endif |
| 920 | let g:colors_name = 'test' |
Bram Moolenaar | 213da55 | 2020-09-17 19:59:26 +0200 | [diff] [blame] | 921 | hi link TestLink ErrorMsg |
| 922 | hi TestHi ctermbg=green |
Bram Moolenaar | 05eb5b9 | 2020-09-16 15:43:21 +0200 | [diff] [blame] | 923 | |
| 924 | " Restore default highlighting |
| 925 | colorscheme default |
Bram Moolenaar | 05eb5b9 | 2020-09-16 15:43:21 +0200 | [diff] [blame] | 926 | " 'default' should work no matter if highlight group was cleared |
| 927 | hi def link TestLink Identifier |
| 928 | hi def TestHi ctermbg=red |
Bram Moolenaar | 05eb5b9 | 2020-09-16 15:43:21 +0200 | [diff] [blame] | 929 | let hlTestLinkPost = HighlightArgs('TestLink') |
| 930 | let hlTestHiPost = HighlightArgs('TestHi') |
Bram Moolenaar | 05eb5b9 | 2020-09-16 15:43:21 +0200 | [diff] [blame] | 931 | call assert_equal(hlTestLinkPre, hlTestLinkPost) |
| 932 | call assert_equal(hlTestHiPre, hlTestHiPost) |
| 933 | hi clear |
| 934 | endfunc |
| 935 | |
Bram Moolenaar | ee4e0c1 | 2020-04-06 21:35:05 +0200 | [diff] [blame] | 936 | " vim: shiftwidth=2 sts=2 expandtab |