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 |
Yegappan Lakshmanan | d1a8d65 | 2021-11-03 21:56:45 +0000 | [diff] [blame] | 7 | source vim9.vim |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 8 | |
Drew Vogel | a0fca17 | 2021-11-13 10:50:01 +0000 | [diff] [blame] | 9 | func ClearDict(d) |
| 10 | for k in keys(a:d) |
| 11 | call remove(a:d, k) |
| 12 | endfor |
| 13 | endfunc |
| 14 | |
Bram Moolenaar | 75373f3 | 2017-08-07 22:02:30 +0200 | [diff] [blame] | 15 | func Test_highlight() |
| 16 | " basic test if ":highlight" doesn't crash |
| 17 | highlight |
| 18 | hi Search |
| 19 | |
| 20 | " test setting colors. |
| 21 | " test clearing one color and all doesn't generate error or warning |
| 22 | silent! hi NewGroup term=bold cterm=italic ctermfg=DarkBlue ctermbg=Grey gui= guifg=#00ff00 guibg=Cyan |
| 23 | silent! hi Group2 term= cterm= |
| 24 | hi Group3 term=underline cterm=bold |
| 25 | |
| 26 | let res = split(execute("hi NewGroup"), "\n")[0] |
| 27 | " filter ctermfg and ctermbg, the numbers depend on the terminal |
| 28 | let res = substitute(res, 'ctermfg=\d*', 'ctermfg=2', '') |
| 29 | let res = substitute(res, 'ctermbg=\d*', 'ctermbg=3', '') |
| 30 | call assert_equal("NewGroup xxx term=bold cterm=italic ctermfg=2 ctermbg=3", |
| 31 | \ res) |
| 32 | call assert_equal("Group2 xxx cleared", |
| 33 | \ split(execute("hi Group2"), "\n")[0]) |
| 34 | call assert_equal("Group3 xxx term=underline cterm=bold", |
| 35 | \ split(execute("hi Group3"), "\n")[0]) |
| 36 | |
| 37 | hi clear NewGroup |
| 38 | call assert_equal("NewGroup xxx cleared", |
| 39 | \ split(execute("hi NewGroup"), "\n")[0]) |
| 40 | call assert_equal("Group2 xxx cleared", |
| 41 | \ split(execute("hi Group2"), "\n")[0]) |
| 42 | hi Group2 NONE |
| 43 | call assert_equal("Group2 xxx cleared", |
| 44 | \ split(execute("hi Group2"), "\n")[0]) |
| 45 | hi clear |
| 46 | call assert_equal("Group3 xxx cleared", |
| 47 | \ split(execute("hi Group3"), "\n")[0]) |
| 48 | call assert_fails("hi Crash term='asdf", "E475:") |
| 49 | endfunc |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 50 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 51 | func HighlightArgs(name) |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 52 | return 'hi ' . substitute(split(execute('hi ' . a:name), '\n')[0], '\<xxx\>', '', '') |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 53 | endfunc |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 54 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 55 | func IsColorable() |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 56 | return has('gui_running') || str2nr(&t_Co) >= 8 |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 57 | endfunc |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 58 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 59 | func HiCursorLine() |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 60 | let hiCursorLine = HighlightArgs('CursorLine') |
| 61 | if has('gui_running') |
| 62 | let guibg = matchstr(hiCursorLine, 'guibg=\w\+') |
| 63 | let hi_ul = 'hi CursorLine gui=underline guibg=NONE' |
| 64 | let hi_bg = 'hi CursorLine gui=NONE ' . guibg |
| 65 | else |
| 66 | let hi_ul = 'hi CursorLine cterm=underline ctermbg=NONE' |
| 67 | let hi_bg = 'hi CursorLine cterm=NONE ctermbg=Gray' |
| 68 | endif |
| 69 | return [hiCursorLine, hi_ul, hi_bg] |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 70 | endfunc |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 71 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 72 | func Check_lcs_eol_attrs(attrs, row, col) |
Bram Moolenaar | 5ece3e3 | 2017-10-01 14:35:02 +0200 | [diff] [blame] | 73 | let save_lcs = &lcs |
| 74 | set list |
| 75 | |
| 76 | call assert_equal(a:attrs, ScreenAttrs(a:row, a:col)[0]) |
| 77 | |
| 78 | set nolist |
| 79 | let &lcs = save_lcs |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 80 | endfunc |
Bram Moolenaar | 5ece3e3 | 2017-10-01 14:35:02 +0200 | [diff] [blame] | 81 | |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 82 | func Test_highlight_eol_with_cursorline() |
| 83 | let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine() |
| 84 | |
| 85 | call NewWindow('topleft 5', 20) |
| 86 | call setline(1, 'abcd') |
| 87 | call matchadd('Search', '\n') |
| 88 | |
| 89 | " expected: |
| 90 | " 'abcd ' |
| 91 | " ^^^^ ^^^^^ no highlight |
| 92 | " ^ 'Search' highlight |
| 93 | let attrs0 = ScreenAttrs(1, 10)[0] |
| 94 | call assert_equal(repeat([attrs0[0]], 4), attrs0[0:3]) |
| 95 | call assert_equal(repeat([attrs0[0]], 5), attrs0[5:9]) |
| 96 | call assert_notequal(attrs0[0], attrs0[4]) |
| 97 | |
| 98 | setlocal cursorline |
| 99 | |
| 100 | " underline |
| 101 | exe hi_ul |
| 102 | |
| 103 | " expected: |
| 104 | " 'abcd ' |
| 105 | " ^^^^ underline |
Bram Moolenaar | 5ece3e3 | 2017-10-01 14:35:02 +0200 | [diff] [blame] | 106 | " ^ 'Search' highlight with underline |
| 107 | " ^^^^^ underline |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 108 | let attrs = ScreenAttrs(1, 10)[0] |
| 109 | call assert_equal(repeat([attrs[0]], 4), attrs[0:3]) |
| 110 | call assert_equal([attrs[4]] + repeat([attrs[5]], 5), attrs[4:9]) |
| 111 | call assert_notequal(attrs[0], attrs[4]) |
| 112 | call assert_notequal(attrs[4], attrs[5]) |
| 113 | call assert_notequal(attrs0[0], attrs[0]) |
| 114 | call assert_notequal(attrs0[4], attrs[4]) |
Bram Moolenaar | 5ece3e3 | 2017-10-01 14:35:02 +0200 | [diff] [blame] | 115 | call Check_lcs_eol_attrs(attrs, 1, 10) |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 116 | |
| 117 | if IsColorable() |
| 118 | " bg-color |
| 119 | exe hi_bg |
| 120 | |
| 121 | " expected: |
| 122 | " 'abcd ' |
| 123 | " ^^^^ bg-color of 'CursorLine' |
| 124 | " ^ 'Search' highlight |
| 125 | " ^^^^^ bg-color of 'CursorLine' |
| 126 | let attrs = ScreenAttrs(1, 10)[0] |
| 127 | call assert_equal(repeat([attrs[0]], 4), attrs[0:3]) |
| 128 | call assert_equal(repeat([attrs[5]], 5), attrs[5:9]) |
| 129 | call assert_equal(attrs0[4], attrs[4]) |
| 130 | call assert_notequal(attrs[0], attrs[4]) |
| 131 | call assert_notequal(attrs[4], attrs[5]) |
| 132 | call assert_notequal(attrs0[0], attrs[0]) |
| 133 | call assert_notequal(attrs0[5], attrs[5]) |
Bram Moolenaar | 5ece3e3 | 2017-10-01 14:35:02 +0200 | [diff] [blame] | 134 | call Check_lcs_eol_attrs(attrs, 1, 10) |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 135 | endif |
| 136 | |
| 137 | call CloseWindow() |
| 138 | exe hiCursorLine |
| 139 | endfunc |
| 140 | |
| 141 | func Test_highlight_eol_with_cursorline_vertsplit() |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 142 | let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine() |
| 143 | |
| 144 | call NewWindow('topleft 5', 5) |
| 145 | call setline(1, 'abcd') |
| 146 | call matchadd('Search', '\n') |
| 147 | |
| 148 | let expected = "abcd |abcd " |
| 149 | let actual = ScreenLines(1, 15)[0] |
| 150 | call assert_equal(expected, actual) |
| 151 | |
| 152 | " expected: |
| 153 | " 'abcd |abcd ' |
| 154 | " ^^^^ ^^^^^^^^^ no highlight |
| 155 | " ^ 'Search' highlight |
| 156 | " ^ 'VertSplit' highlight |
| 157 | let attrs0 = ScreenAttrs(1, 15)[0] |
| 158 | call assert_equal(repeat([attrs0[0]], 4), attrs0[0:3]) |
| 159 | call assert_equal(repeat([attrs0[0]], 9), attrs0[6:14]) |
| 160 | call assert_notequal(attrs0[0], attrs0[4]) |
| 161 | call assert_notequal(attrs0[0], attrs0[5]) |
| 162 | call assert_notequal(attrs0[4], attrs0[5]) |
| 163 | |
| 164 | setlocal cursorline |
| 165 | |
| 166 | " expected: |
| 167 | " 'abcd |abcd ' |
| 168 | " ^^^^ underline |
| 169 | " ^ 'Search' highlight with underline |
| 170 | " ^ 'VertSplit' highlight |
| 171 | " ^^^^^^^^^ no highlight |
| 172 | |
| 173 | " underline |
| 174 | exe hi_ul |
| 175 | |
| 176 | let actual = ScreenLines(1, 15)[0] |
| 177 | call assert_equal(expected, actual) |
| 178 | |
| 179 | let attrs = ScreenAttrs(1, 15)[0] |
| 180 | call assert_equal(repeat([attrs[0]], 4), attrs[0:3]) |
| 181 | call assert_equal(repeat([attrs[6]], 9), attrs[6:14]) |
| 182 | call assert_equal(attrs0[5:14], attrs[5:14]) |
| 183 | call assert_notequal(attrs[0], attrs[4]) |
| 184 | call assert_notequal(attrs[0], attrs[5]) |
| 185 | call assert_notequal(attrs[0], attrs[6]) |
| 186 | call assert_notequal(attrs[4], attrs[5]) |
| 187 | call assert_notequal(attrs[5], attrs[6]) |
| 188 | call assert_notequal(attrs0[0], attrs[0]) |
| 189 | call assert_notequal(attrs0[4], attrs[4]) |
Bram Moolenaar | 5ece3e3 | 2017-10-01 14:35:02 +0200 | [diff] [blame] | 190 | call Check_lcs_eol_attrs(attrs, 1, 15) |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 191 | |
| 192 | if IsColorable() |
| 193 | " bg-color |
| 194 | exe hi_bg |
| 195 | |
| 196 | let actual = ScreenLines(1, 15)[0] |
| 197 | call assert_equal(expected, actual) |
| 198 | |
| 199 | let attrs = ScreenAttrs(1, 15)[0] |
| 200 | call assert_equal(repeat([attrs[0]], 4), attrs[0:3]) |
| 201 | call assert_equal(repeat([attrs[6]], 9), attrs[6:14]) |
| 202 | call assert_equal(attrs0[5:14], attrs[5:14]) |
| 203 | call assert_notequal(attrs[0], attrs[4]) |
| 204 | call assert_notequal(attrs[0], attrs[5]) |
| 205 | call assert_notequal(attrs[0], attrs[6]) |
| 206 | call assert_notequal(attrs[4], attrs[5]) |
| 207 | call assert_notequal(attrs[5], attrs[6]) |
| 208 | call assert_notequal(attrs0[0], attrs[0]) |
| 209 | call assert_equal(attrs0[4], attrs[4]) |
Bram Moolenaar | 5ece3e3 | 2017-10-01 14:35:02 +0200 | [diff] [blame] | 210 | call Check_lcs_eol_attrs(attrs, 1, 15) |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 211 | endif |
| 212 | |
| 213 | call CloseWindow() |
| 214 | exe hiCursorLine |
| 215 | endfunc |
| 216 | |
| 217 | func Test_highlight_eol_with_cursorline_rightleft() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 218 | CheckFeature rightleft |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 219 | |
| 220 | let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine() |
| 221 | |
| 222 | call NewWindow('topleft 5', 10) |
| 223 | setlocal rightleft |
| 224 | call setline(1, 'abcd') |
| 225 | call matchadd('Search', '\n') |
| 226 | let attrs0 = ScreenAttrs(1, 10)[0] |
| 227 | |
| 228 | setlocal cursorline |
| 229 | |
| 230 | " underline |
| 231 | exe hi_ul |
| 232 | |
| 233 | " expected: |
| 234 | " ' dcba' |
| 235 | " ^^^^ underline |
| 236 | " ^ 'Search' highlight with underline |
| 237 | " ^^^^^ underline |
| 238 | let attrs = ScreenAttrs(1, 10)[0] |
| 239 | call assert_equal(repeat([attrs[9]], 4), attrs[6:9]) |
| 240 | call assert_equal(repeat([attrs[4]], 5) + [attrs[5]], attrs[0:5]) |
| 241 | call assert_notequal(attrs[9], attrs[5]) |
| 242 | call assert_notequal(attrs[4], attrs[5]) |
| 243 | call assert_notequal(attrs0[9], attrs[9]) |
| 244 | call assert_notequal(attrs0[5], attrs[5]) |
Bram Moolenaar | 5ece3e3 | 2017-10-01 14:35:02 +0200 | [diff] [blame] | 245 | call Check_lcs_eol_attrs(attrs, 1, 10) |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 246 | |
| 247 | if IsColorable() |
| 248 | " bg-color |
| 249 | exe hi_bg |
| 250 | |
| 251 | " expected: |
| 252 | " ' dcba' |
| 253 | " ^^^^ bg-color of 'CursorLine' |
| 254 | " ^ 'Search' highlight |
| 255 | " ^^^^^ bg-color of 'CursorLine' |
| 256 | let attrs = ScreenAttrs(1, 10)[0] |
| 257 | call assert_equal(repeat([attrs[9]], 4), attrs[6:9]) |
| 258 | call assert_equal(repeat([attrs[4]], 5), attrs[0:4]) |
| 259 | call assert_equal(attrs0[5], attrs[5]) |
| 260 | call assert_notequal(attrs[9], attrs[5]) |
| 261 | call assert_notequal(attrs[5], attrs[4]) |
| 262 | call assert_notequal(attrs0[9], attrs[9]) |
| 263 | call assert_notequal(attrs0[4], attrs[4]) |
Bram Moolenaar | 5ece3e3 | 2017-10-01 14:35:02 +0200 | [diff] [blame] | 264 | call Check_lcs_eol_attrs(attrs, 1, 10) |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 265 | endif |
| 266 | |
| 267 | call CloseWindow() |
| 268 | exe hiCursorLine |
| 269 | endfunc |
| 270 | |
| 271 | func Test_highlight_eol_with_cursorline_linewrap() |
| 272 | let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine() |
| 273 | |
| 274 | call NewWindow('topleft 5', 10) |
| 275 | call setline(1, [repeat('a', 51) . 'bcd', '']) |
| 276 | call matchadd('Search', '\n') |
| 277 | |
| 278 | setlocal wrap |
| 279 | normal! gg$ |
| 280 | let attrs0 = ScreenAttrs(5, 10)[0] |
| 281 | setlocal cursorline |
| 282 | |
| 283 | " underline |
| 284 | exe hi_ul |
| 285 | |
| 286 | " expected: |
| 287 | " 'abcd ' |
| 288 | " ^^^^ underline |
| 289 | " ^ 'Search' highlight with underline |
| 290 | " ^^^^^ underline |
| 291 | let attrs = ScreenAttrs(5, 10)[0] |
| 292 | call assert_equal(repeat([attrs[0]], 4), attrs[0:3]) |
| 293 | call assert_equal([attrs[4]] + repeat([attrs[5]], 5), attrs[4:9]) |
| 294 | call assert_notequal(attrs[0], attrs[4]) |
| 295 | call assert_notequal(attrs[4], attrs[5]) |
| 296 | call assert_notequal(attrs0[0], attrs[0]) |
| 297 | call assert_notequal(attrs0[4], attrs[4]) |
Bram Moolenaar | 5ece3e3 | 2017-10-01 14:35:02 +0200 | [diff] [blame] | 298 | call Check_lcs_eol_attrs(attrs, 5, 10) |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 299 | |
| 300 | if IsColorable() |
| 301 | " bg-color |
| 302 | exe hi_bg |
| 303 | |
| 304 | " expected: |
| 305 | " 'abcd ' |
| 306 | " ^^^^ bg-color of 'CursorLine' |
| 307 | " ^ 'Search' highlight |
| 308 | " ^^^^^ bg-color of 'CursorLine' |
| 309 | let attrs = ScreenAttrs(5, 10)[0] |
| 310 | call assert_equal(repeat([attrs[0]], 4), attrs[0:3]) |
| 311 | call assert_equal(repeat([attrs[5]], 5), attrs[5:9]) |
| 312 | call assert_equal(attrs0[4], attrs[4]) |
| 313 | call assert_notequal(attrs[0], attrs[4]) |
| 314 | call assert_notequal(attrs[4], attrs[5]) |
| 315 | call assert_notequal(attrs0[0], attrs[0]) |
| 316 | call assert_notequal(attrs0[5], attrs[5]) |
Bram Moolenaar | 5ece3e3 | 2017-10-01 14:35:02 +0200 | [diff] [blame] | 317 | call Check_lcs_eol_attrs(attrs, 5, 10) |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 318 | endif |
| 319 | |
| 320 | setlocal nocursorline nowrap |
| 321 | normal! gg$ |
| 322 | let attrs0 = ScreenAttrs(1, 10)[0] |
| 323 | setlocal cursorline |
| 324 | |
| 325 | " underline |
| 326 | exe hi_ul |
| 327 | |
| 328 | " expected: |
| 329 | " 'aaabcd ' |
| 330 | " ^^^^^^ underline |
| 331 | " ^ 'Search' highlight with underline |
| 332 | " ^^^ underline |
| 333 | let attrs = ScreenAttrs(1, 10)[0] |
| 334 | call assert_equal(repeat([attrs[0]], 6), attrs[0:5]) |
| 335 | call assert_equal([attrs[6]] + repeat([attrs[7]], 3), attrs[6:9]) |
| 336 | call assert_notequal(attrs[0], attrs[6]) |
| 337 | call assert_notequal(attrs[6], attrs[7]) |
| 338 | call assert_notequal(attrs0[0], attrs[0]) |
| 339 | call assert_notequal(attrs0[6], attrs[6]) |
Bram Moolenaar | 5ece3e3 | 2017-10-01 14:35:02 +0200 | [diff] [blame] | 340 | call Check_lcs_eol_attrs(attrs, 1, 10) |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 341 | |
| 342 | if IsColorable() |
| 343 | " bg-color |
| 344 | exe hi_bg |
| 345 | |
| 346 | " expected: |
| 347 | " 'aaabcd ' |
| 348 | " ^^^^^^ bg-color of 'CursorLine' |
| 349 | " ^ 'Search' highlight |
| 350 | " ^^^ bg-color of 'CursorLine' |
| 351 | let attrs = ScreenAttrs(1, 10)[0] |
| 352 | call assert_equal(repeat([attrs[0]], 6), attrs[0:5]) |
| 353 | call assert_equal(repeat([attrs[7]], 3), attrs[7:9]) |
| 354 | call assert_equal(attrs0[6], attrs[6]) |
| 355 | call assert_notequal(attrs[0], attrs[6]) |
| 356 | call assert_notequal(attrs[6], attrs[7]) |
| 357 | call assert_notequal(attrs0[0], attrs[0]) |
| 358 | call assert_notequal(attrs0[7], attrs[7]) |
Bram Moolenaar | 5ece3e3 | 2017-10-01 14:35:02 +0200 | [diff] [blame] | 359 | call Check_lcs_eol_attrs(attrs, 1, 10) |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 360 | endif |
| 361 | |
| 362 | call CloseWindow() |
| 363 | exe hiCursorLine |
| 364 | endfunc |
| 365 | |
| 366 | func Test_highlight_eol_with_cursorline_sign() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 367 | CheckFeature signs |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 368 | |
| 369 | let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine() |
| 370 | |
| 371 | call NewWindow('topleft 5', 10) |
| 372 | call setline(1, 'abcd') |
| 373 | call matchadd('Search', '\n') |
| 374 | |
| 375 | sign define Sign text=>> |
| 376 | exe 'sign place 1 line=1 name=Sign buffer=' . bufnr('') |
| 377 | let attrs0 = ScreenAttrs(1, 10)[0] |
| 378 | setlocal cursorline |
| 379 | |
| 380 | " underline |
| 381 | exe hi_ul |
| 382 | |
| 383 | " expected: |
| 384 | " '>>abcd ' |
| 385 | " ^^ sign |
| 386 | " ^^^^ underline |
| 387 | " ^ 'Search' highlight with underline |
| 388 | " ^^^ underline |
| 389 | let attrs = ScreenAttrs(1, 10)[0] |
| 390 | call assert_equal(repeat([attrs[2]], 4), attrs[2:5]) |
| 391 | call assert_equal([attrs[6]] + repeat([attrs[7]], 3), attrs[6:9]) |
| 392 | call assert_notequal(attrs[2], attrs[6]) |
| 393 | call assert_notequal(attrs[6], attrs[7]) |
| 394 | call assert_notequal(attrs0[2], attrs[2]) |
| 395 | call assert_notequal(attrs0[6], attrs[6]) |
Bram Moolenaar | 5ece3e3 | 2017-10-01 14:35:02 +0200 | [diff] [blame] | 396 | call Check_lcs_eol_attrs(attrs, 1, 10) |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 397 | |
| 398 | if IsColorable() |
| 399 | " bg-color |
| 400 | exe hi_bg |
| 401 | |
| 402 | " expected: |
| 403 | " '>>abcd ' |
| 404 | " ^^ sign |
| 405 | " ^^^^ bg-color of 'CursorLine' |
| 406 | " ^ 'Search' highlight |
| 407 | " ^^^ bg-color of 'CursorLine' |
| 408 | let attrs = ScreenAttrs(1, 10)[0] |
| 409 | call assert_equal(repeat([attrs[2]], 4), attrs[2:5]) |
| 410 | call assert_equal(repeat([attrs[7]], 3), attrs[7:9]) |
| 411 | call assert_equal(attrs0[6], attrs[6]) |
| 412 | call assert_notequal(attrs[2], attrs[6]) |
| 413 | call assert_notequal(attrs[6], attrs[7]) |
| 414 | call assert_notequal(attrs0[2], attrs[2]) |
| 415 | call assert_notequal(attrs0[7], attrs[7]) |
Bram Moolenaar | 5ece3e3 | 2017-10-01 14:35:02 +0200 | [diff] [blame] | 416 | call Check_lcs_eol_attrs(attrs, 1, 10) |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 417 | endif |
| 418 | |
| 419 | sign unplace 1 |
| 420 | call CloseWindow() |
| 421 | exe hiCursorLine |
| 422 | endfunc |
| 423 | |
| 424 | func Test_highlight_eol_with_cursorline_breakindent() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 425 | CheckFeature linebreak |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 426 | |
| 427 | let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine() |
| 428 | |
| 429 | call NewWindow('topleft 5', 10) |
Bram Moolenaar | ee85702 | 2019-11-09 23:26:40 +0100 | [diff] [blame] | 430 | set showbreak=xxx |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 431 | setlocal breakindent breakindentopt=min:0,shift:1 showbreak=> |
| 432 | call setline(1, ' ' . repeat('a', 9) . 'bcd') |
| 433 | call matchadd('Search', '\n') |
| 434 | let attrs0 = ScreenAttrs(2, 10)[0] |
| 435 | setlocal cursorline |
| 436 | |
| 437 | " underline |
| 438 | exe hi_ul |
| 439 | |
| 440 | " expected: |
| 441 | " ' >bcd ' |
| 442 | " ^^^ breakindent and showbreak |
| 443 | " ^^^ underline |
| 444 | " ^ 'Search' highlight with underline |
| 445 | " ^^^ underline |
| 446 | let attrs = ScreenAttrs(2, 10)[0] |
| 447 | call assert_equal(repeat([attrs[0]], 2), attrs[0:1]) |
| 448 | call assert_equal(repeat([attrs[3]], 3), attrs[3:5]) |
| 449 | call assert_equal([attrs[6]] + repeat([attrs[7]], 3), attrs[6:9]) |
| 450 | call assert_equal(attrs0[0], attrs[0]) |
| 451 | call assert_notequal(attrs[0], attrs[2]) |
| 452 | call assert_notequal(attrs[2], attrs[3]) |
| 453 | call assert_notequal(attrs[3], attrs[6]) |
| 454 | call assert_notequal(attrs[6], attrs[7]) |
| 455 | call assert_notequal(attrs0[2], attrs[2]) |
| 456 | call assert_notequal(attrs0[3], attrs[3]) |
| 457 | call assert_notequal(attrs0[6], attrs[6]) |
Bram Moolenaar | 5ece3e3 | 2017-10-01 14:35:02 +0200 | [diff] [blame] | 458 | call Check_lcs_eol_attrs(attrs, 2, 10) |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 459 | |
| 460 | if IsColorable() |
| 461 | " bg-color |
| 462 | exe hi_bg |
| 463 | |
| 464 | " expected: |
| 465 | " ' >bcd ' |
| 466 | " ^^^ breakindent and showbreak |
| 467 | " ^^^ bg-color of 'CursorLine' |
| 468 | " ^ 'Search' highlight |
| 469 | " ^^^ bg-color of 'CursorLine' |
| 470 | let attrs = ScreenAttrs(2, 10)[0] |
| 471 | call assert_equal(repeat([attrs[0]], 2), attrs[0:1]) |
| 472 | call assert_equal(repeat([attrs[3]], 3), attrs[3:5]) |
| 473 | call assert_equal(repeat([attrs[7]], 3), attrs[7:9]) |
| 474 | call assert_equal(attrs0[0], attrs[0]) |
| 475 | call assert_equal(attrs0[6], attrs[6]) |
| 476 | call assert_notequal(attrs[0], attrs[2]) |
| 477 | call assert_notequal(attrs[2], attrs[3]) |
| 478 | call assert_notequal(attrs[3], attrs[6]) |
| 479 | call assert_notequal(attrs[6], attrs[7]) |
| 480 | call assert_notequal(attrs0[2], attrs[2]) |
| 481 | call assert_notequal(attrs0[3], attrs[3]) |
| 482 | call assert_notequal(attrs0[7], attrs[7]) |
Bram Moolenaar | 5ece3e3 | 2017-10-01 14:35:02 +0200 | [diff] [blame] | 483 | call Check_lcs_eol_attrs(attrs, 2, 10) |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 484 | endif |
| 485 | |
| 486 | call CloseWindow() |
| 487 | set showbreak= |
Bram Moolenaar | ee85702 | 2019-11-09 23:26:40 +0100 | [diff] [blame] | 488 | setlocal showbreak= |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 489 | exe hiCursorLine |
| 490 | endfunc |
| 491 | |
| 492 | func Test_highlight_eol_on_diff() |
| 493 | call setline(1, ['abcd', '']) |
| 494 | call matchadd('Search', '\n') |
| 495 | let attrs0 = ScreenAttrs(1, 10)[0] |
| 496 | |
| 497 | diffthis |
| 498 | botright new |
| 499 | diffthis |
| 500 | |
| 501 | " expected: |
| 502 | " ' abcd ' |
| 503 | " ^^ sign |
| 504 | " ^^^^ ^^^ 'DiffAdd' highlight |
| 505 | " ^ 'Search' highlight |
| 506 | let attrs = ScreenAttrs(1, 10)[0] |
| 507 | call assert_equal(repeat([attrs[0]], 2), attrs[0:1]) |
| 508 | call assert_equal(repeat([attrs[2]], 4), attrs[2:5]) |
| 509 | call assert_equal(repeat([attrs[2]], 3), attrs[7:9]) |
| 510 | call assert_equal(attrs0[4], attrs[6]) |
| 511 | call assert_notequal(attrs[0], attrs[2]) |
| 512 | call assert_notequal(attrs[0], attrs[6]) |
| 513 | call assert_notequal(attrs[2], attrs[6]) |
Bram Moolenaar | 5ece3e3 | 2017-10-01 14:35:02 +0200 | [diff] [blame] | 514 | call Check_lcs_eol_attrs(attrs, 1, 10) |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 515 | |
| 516 | bwipe! |
| 517 | diffoff |
| 518 | endfunc |
Bram Moolenaar | f708ac5 | 2018-03-12 21:48:32 +0100 | [diff] [blame] | 519 | |
| 520 | func Test_termguicolors() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 521 | CheckOption termguicolors |
Bram Moolenaar | 310c32e | 2019-11-29 23:15:25 +0100 | [diff] [blame] | 522 | if has('vtp') && !has('vcon') && !has('gui_running') |
Bram Moolenaar | ff1e879 | 2018-03-12 22:16:37 +0100 | [diff] [blame] | 523 | " Win32: 'guicolors' doesn't work without virtual console. |
| 524 | call assert_fails('set termguicolors', 'E954:') |
| 525 | return |
| 526 | endif |
Bram Moolenaar | f708ac5 | 2018-03-12 21:48:32 +0100 | [diff] [blame] | 527 | |
| 528 | " Basic test that setting 'termguicolors' works with one color. |
| 529 | set termguicolors |
| 530 | redraw |
| 531 | set t_Co=1 |
| 532 | redraw |
| 533 | set t_Co=0 |
| 534 | redraw |
| 535 | endfunc |
Bram Moolenaar | c07ff5c | 2019-01-30 21:41:14 +0100 | [diff] [blame] | 536 | |
| 537 | func Test_cursorline_after_yank() |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 538 | CheckScreendump |
Bram Moolenaar | c07ff5c | 2019-01-30 21:41:14 +0100 | [diff] [blame] | 539 | |
| 540 | call writefile([ |
| 541 | \ 'set cul rnu', |
| 542 | \ 'call setline(1, ["","1","2","3",""])', |
| 543 | \ ], 'Xtest_cursorline_yank') |
| 544 | let buf = RunVimInTerminal('-S Xtest_cursorline_yank', {'rows': 8}) |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 545 | call TermWait(buf) |
Bram Moolenaar | c07ff5c | 2019-01-30 21:41:14 +0100 | [diff] [blame] | 546 | call term_sendkeys(buf, "Gy3k") |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 547 | call TermWait(buf) |
Bram Moolenaar | c07ff5c | 2019-01-30 21:41:14 +0100 | [diff] [blame] | 548 | call term_sendkeys(buf, "jj") |
| 549 | |
| 550 | call VerifyScreenDump(buf, 'Test_cursorline_yank_01', {}) |
| 551 | |
| 552 | " clean up |
| 553 | call StopVimInTerminal(buf) |
| 554 | call delete('Xtest_cursorline_yank') |
| 555 | endfunc |
Bram Moolenaar | 8156ed3 | 2019-03-09 11:46:15 +0100 | [diff] [blame] | 556 | |
Bram Moolenaar | fca068b | 2019-09-08 14:07:47 +0200 | [diff] [blame] | 557 | " test for issue #4862 |
| 558 | func Test_put_before_cursorline() |
| 559 | new |
| 560 | only! |
| 561 | call setline(1, 'A') |
| 562 | redraw |
| 563 | let std_attr = screenattr(1, 1) |
| 564 | set cursorline |
| 565 | redraw |
| 566 | let cul_attr = screenattr(1, 1) |
| 567 | normal yyP |
| 568 | redraw |
| 569 | " Line 1 has cursor so it should be highlighted with CursorLine. |
| 570 | call assert_equal(cul_attr, screenattr(1, 1)) |
| 571 | " And CursorLine highlighting from the second line should be gone. |
| 572 | call assert_equal(std_attr, screenattr(2, 1)) |
| 573 | set nocursorline |
| 574 | bwipe! |
| 575 | endfunc |
| 576 | |
Bram Moolenaar | 8156ed3 | 2019-03-09 11:46:15 +0100 | [diff] [blame] | 577 | func Test_cursorline_with_visualmode() |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 578 | CheckScreendump |
Bram Moolenaar | 8156ed3 | 2019-03-09 11:46:15 +0100 | [diff] [blame] | 579 | |
| 580 | call writefile([ |
| 581 | \ 'set cul', |
| 582 | \ 'call setline(1, repeat(["abc"], 50))', |
| 583 | \ ], 'Xtest_cursorline_with_visualmode') |
| 584 | let buf = RunVimInTerminal('-S Xtest_cursorline_with_visualmode', {'rows': 12}) |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 585 | call TermWait(buf) |
Bram Moolenaar | 8156ed3 | 2019-03-09 11:46:15 +0100 | [diff] [blame] | 586 | call term_sendkeys(buf, "V\<C-f>kkkjk") |
| 587 | |
| 588 | call VerifyScreenDump(buf, 'Test_cursorline_with_visualmode_01', {}) |
| 589 | |
| 590 | " clean up |
| 591 | call StopVimInTerminal(buf) |
| 592 | call delete('Xtest_cursorline_with_visualmode') |
| 593 | endfunc |
Bram Moolenaar | f90b6e0 | 2019-05-09 19:26:38 +0200 | [diff] [blame] | 594 | |
Bram Moolenaar | 193ffd1 | 2019-05-25 22:57:30 +0200 | [diff] [blame] | 595 | func Test_wincolor() |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 596 | CheckScreendump |
Bram Moolenaar | 3180fe6 | 2020-02-02 13:47:06 +0100 | [diff] [blame] | 597 | " make sure the width is enough for the test |
| 598 | set columns=80 |
Bram Moolenaar | 193ffd1 | 2019-05-25 22:57:30 +0200 | [diff] [blame] | 599 | |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 600 | let lines =<< trim END |
| 601 | set cursorline cursorcolumn rnu |
Bram Moolenaar | 053f712 | 2019-09-23 22:17:15 +0200 | [diff] [blame] | 602 | 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] | 603 | set wincolor=Pmenu |
Bram Moolenaar | 053f712 | 2019-09-23 22:17:15 +0200 | [diff] [blame] | 604 | hi CatLine guifg=green ctermfg=green |
| 605 | hi Reverse gui=reverse cterm=reverse |
| 606 | syn match CatLine /^the.*/ |
| 607 | call prop_type_add("foo", {"highlight": "Reverse", "combine": 1}) |
| 608 | call prop_add(6, 12, {"type": "foo", "end_col": 15}) |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 609 | /here |
| 610 | END |
| 611 | call writefile(lines, 'Xtest_wincolor') |
Bram Moolenaar | 193ffd1 | 2019-05-25 22:57:30 +0200 | [diff] [blame] | 612 | let buf = RunVimInTerminal('-S Xtest_wincolor', {'rows': 8}) |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 613 | call TermWait(buf) |
Bram Moolenaar | 193ffd1 | 2019-05-25 22:57:30 +0200 | [diff] [blame] | 614 | call term_sendkeys(buf, "2G5lvj") |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 615 | call TermWait(buf) |
Bram Moolenaar | 193ffd1 | 2019-05-25 22:57:30 +0200 | [diff] [blame] | 616 | |
| 617 | call VerifyScreenDump(buf, 'Test_wincolor_01', {}) |
| 618 | |
| 619 | " clean up |
| 620 | call term_sendkeys(buf, "\<Esc>") |
| 621 | call StopVimInTerminal(buf) |
| 622 | call delete('Xtest_wincolor') |
| 623 | endfunc |
| 624 | |
Bram Moolenaar | 42e931b | 2019-12-04 19:08:50 +0100 | [diff] [blame] | 625 | func Test_wincolor_listchars() |
| 626 | CheckScreendump |
Bram Moolenaar | 705724e | 2020-01-31 21:13:42 +0100 | [diff] [blame] | 627 | CheckFeature conceal |
Bram Moolenaar | 42e931b | 2019-12-04 19:08:50 +0100 | [diff] [blame] | 628 | |
| 629 | let lines =<< trim END |
| 630 | call setline(1, ["one","\t\tsome random text enough long to show 'extends' and 'precedes' includingnbsps, preceding tabs and trailing spaces ","three"]) |
| 631 | set wincolor=Todo |
| 632 | set nowrap cole=1 cocu+=n |
| 633 | set list lcs=eol:$,tab:>-,space:.,trail:_,extends:>,precedes:<,conceal:*,nbsp:# |
| 634 | call matchadd('Conceal', 'text') |
| 635 | normal 2G5zl |
| 636 | END |
| 637 | call writefile(lines, 'Xtest_wincolorlcs') |
| 638 | let buf = RunVimInTerminal('-S Xtest_wincolorlcs', {'rows': 8}) |
| 639 | |
| 640 | call VerifyScreenDump(buf, 'Test_wincolor_lcs', {}) |
| 641 | |
| 642 | " clean up |
| 643 | call term_sendkeys(buf, "\<Esc>") |
| 644 | call StopVimInTerminal(buf) |
| 645 | call delete('Xtest_wincolorlcs') |
| 646 | endfunc |
| 647 | |
Bram Moolenaar | 010ee96 | 2019-09-25 20:37:36 +0200 | [diff] [blame] | 648 | func Test_colorcolumn() |
| 649 | CheckScreendump |
| 650 | |
| 651 | " check that setting 'colorcolumn' when entering a buffer works |
| 652 | let lines =<< trim END |
| 653 | split |
| 654 | edit X |
| 655 | call setline(1, ["1111111111","22222222222","3333333333"]) |
| 656 | set nomodified |
| 657 | set colorcolumn=3,9 |
| 658 | set number cursorline cursorlineopt=number |
| 659 | wincmd w |
| 660 | buf X |
| 661 | END |
| 662 | call writefile(lines, 'Xtest_colorcolumn') |
| 663 | let buf = RunVimInTerminal('-S Xtest_colorcolumn', {'rows': 10}) |
| 664 | call term_sendkeys(buf, ":\<CR>") |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 665 | call TermWait(buf) |
Bram Moolenaar | 010ee96 | 2019-09-25 20:37:36 +0200 | [diff] [blame] | 666 | call VerifyScreenDump(buf, 'Test_colorcolumn_1', {}) |
| 667 | |
| 668 | " clean up |
| 669 | call StopVimInTerminal(buf) |
| 670 | call delete('Xtest_colorcolumn') |
| 671 | endfunc |
| 672 | |
Bram Moolenaar | ad5e563 | 2020-09-15 20:52:26 +0200 | [diff] [blame] | 673 | func Test_colorcolumn_bri() |
| 674 | CheckScreendump |
| 675 | |
| 676 | " check 'colorcolumn' when 'breakindent' is set |
| 677 | let lines =<< trim END |
| 678 | call setline(1, 'The quick brown fox jumped over the lazy dogs') |
| 679 | END |
| 680 | call writefile(lines, 'Xtest_colorcolumn_bri') |
| 681 | let buf = RunVimInTerminal('-S Xtest_colorcolumn_bri', {'rows': 10,'columns': 40}) |
| 682 | call term_sendkeys(buf, ":set co=40 linebreak bri briopt=shift:2 cc=40,41,43\<CR>") |
| 683 | call TermWait(buf) |
| 684 | call VerifyScreenDump(buf, 'Test_colorcolumn_2', {}) |
| 685 | |
| 686 | " clean up |
| 687 | call StopVimInTerminal(buf) |
| 688 | call delete('Xtest_colorcolumn_bri') |
| 689 | endfunc |
| 690 | |
| 691 | func Test_colorcolumn_sbr() |
| 692 | CheckScreendump |
| 693 | |
| 694 | " check 'colorcolumn' when 'showbreak' is set |
| 695 | let lines =<< trim END |
| 696 | call setline(1, 'The quick brown fox jumped over the lazy dogs') |
| 697 | END |
| 698 | call writefile(lines, 'Xtest_colorcolumn_srb') |
| 699 | let buf = RunVimInTerminal('-S Xtest_colorcolumn_srb', {'rows': 10,'columns': 40}) |
| 700 | call term_sendkeys(buf, ":set co=40 showbreak=+++>\\ cc=40,41,43\<CR>") |
| 701 | call TermWait(buf) |
| 702 | call VerifyScreenDump(buf, 'Test_colorcolumn_3', {}) |
| 703 | |
| 704 | " clean up |
| 705 | call StopVimInTerminal(buf) |
| 706 | call delete('Xtest_colorcolumn_srb') |
| 707 | endfunc |
| 708 | |
Bram Moolenaar | 6b528fa | 2019-05-09 20:07:33 +0200 | [diff] [blame] | 709 | " This test must come before the Test_cursorline test, as it appears this |
| 710 | " defines the Normal highlighting group anyway. |
Bram Moolenaar | f90b6e0 | 2019-05-09 19:26:38 +0200 | [diff] [blame] | 711 | func Test_1_highlight_Normalgroup_exists() |
Bram Moolenaar | 435f9f0 | 2019-07-03 21:40:16 +0200 | [diff] [blame] | 712 | let hlNormal = HighlightArgs('Normal') |
| 713 | if !has('gui_running') |
Bram Moolenaar | 6b528fa | 2019-05-09 20:07:33 +0200 | [diff] [blame] | 714 | call assert_match('hi Normal\s*clear', hlNormal) |
Bram Moolenaar | 435f9f0 | 2019-07-03 21:40:16 +0200 | [diff] [blame] | 715 | elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3') |
| 716 | " expect is DEFAULT_FONT of gui_gtk_x11.c |
| 717 | call assert_match('hi Normal\s*font=Monospace 10', hlNormal) |
| 718 | elseif has('gui_motif') || has('gui_athena') |
| 719 | " expect is DEFAULT_FONT of gui_x11.c |
| 720 | call assert_match('hi Normal\s*font=7x13', hlNormal) |
| 721 | elseif has('win32') |
| 722 | " expect any font |
| 723 | call assert_match('hi Normal\s*font=.*', hlNormal) |
Bram Moolenaar | 6b528fa | 2019-05-09 20:07:33 +0200 | [diff] [blame] | 724 | endif |
Bram Moolenaar | f90b6e0 | 2019-05-09 19:26:38 +0200 | [diff] [blame] | 725 | endfunc |
Bram Moolenaar | 548be7f | 2019-06-29 03:42:42 +0200 | [diff] [blame] | 726 | |
Bram Moolenaar | 3180fe6 | 2020-02-02 13:47:06 +0100 | [diff] [blame] | 727 | " Do this test last, sometimes restoring the columns doesn't work |
Bram Moolenaar | ee4e0c1 | 2020-04-06 21:35:05 +0200 | [diff] [blame] | 728 | func Test_z_no_space_before_xxx() |
Bram Moolenaar | 548be7f | 2019-06-29 03:42:42 +0200 | [diff] [blame] | 729 | let l:org_columns = &columns |
| 730 | set columns=17 |
| 731 | let l:hi_StatusLineTermNC = join(split(execute('hi StatusLineTermNC'))) |
| 732 | call assert_match('StatusLineTermNC xxx', l:hi_StatusLineTermNC) |
| 733 | let &columns = l:org_columns |
Bram Moolenaar | ee4e0c1 | 2020-04-06 21:35:05 +0200 | [diff] [blame] | 734 | endfunc |
| 735 | |
| 736 | " Test for :highlight command errors |
| 737 | func Test_highlight_cmd_errors() |
| 738 | if has('gui_running') |
| 739 | " This test doesn't fail in the MS-Windows console version. |
Bram Moolenaar | 75e1567 | 2020-06-28 13:10:22 +0200 | [diff] [blame] | 740 | call assert_fails('hi Xcomment ctermbg=fg', 'E419:') |
Bram Moolenaar | ee4e0c1 | 2020-04-06 21:35:05 +0200 | [diff] [blame] | 741 | call assert_fails('hi Xcomment ctermfg=bg', 'E420:') |
Bram Moolenaar | 75e1567 | 2020-06-28 13:10:22 +0200 | [diff] [blame] | 742 | call assert_fails('hi Xcomment ctermfg=ul', 'E453:') |
Bram Moolenaar | ee4e0c1 | 2020-04-06 21:35:05 +0200 | [diff] [blame] | 743 | endif |
| 744 | |
| 745 | " Try using a very long terminal code. Define a dummy terminal code for this |
| 746 | " test. |
| 747 | let &t_fo = "\<Esc>1;" |
| 748 | let c = repeat("t_fo,", 100) . "t_fo" |
| 749 | call assert_fails('exe "hi Xgroup1 start=" . c', 'E422:') |
| 750 | let &t_fo = "" |
| 751 | endfunc |
| 752 | |
Bram Moolenaar | 75e1567 | 2020-06-28 13:10:22 +0200 | [diff] [blame] | 753 | " Test for 'highlight' option |
| 754 | func Test_highlight_opt() |
| 755 | let save_hl = &highlight |
| 756 | call assert_fails('set highlight=j:b', 'E474:') |
| 757 | set highlight=f\ r |
| 758 | call assert_equal('f r', &highlight) |
| 759 | set highlight=fb |
| 760 | call assert_equal('fb', &highlight) |
| 761 | set highlight=fi |
| 762 | call assert_equal('fi', &highlight) |
| 763 | set highlight=f- |
| 764 | call assert_equal('f-', &highlight) |
| 765 | set highlight=fr |
| 766 | call assert_equal('fr', &highlight) |
| 767 | set highlight=fs |
| 768 | call assert_equal('fs', &highlight) |
| 769 | set highlight=fu |
| 770 | call assert_equal('fu', &highlight) |
| 771 | set highlight=fc |
| 772 | call assert_equal('fc', &highlight) |
| 773 | set highlight=ft |
| 774 | call assert_equal('ft', &highlight) |
| 775 | call assert_fails('set highlight=fr:Search', 'E474:') |
| 776 | set highlight=f:$# |
| 777 | call assert_match('W18:', v:statusmsg) |
| 778 | let &highlight = save_hl |
| 779 | endfunc |
| 780 | |
| 781 | " Test for User group highlighting used in the statusline |
| 782 | func Test_highlight_User() |
| 783 | CheckNotGui |
| 784 | hi User1 ctermfg=12 |
| 785 | redraw! |
| 786 | call assert_equal('12', synIDattr(synIDtrans(hlID('User1')), 'fg')) |
| 787 | hi clear |
| 788 | endfunc |
| 789 | |
| 790 | " Test for using RGB color values in a highlight group |
Bram Moolenaar | 09fbedc | 2021-01-19 17:22:58 +0100 | [diff] [blame] | 791 | func Test_xxlast_highlight_RGB_color() |
| 792 | CheckCanRunGui |
| 793 | gui -f |
Bram Moolenaar | 75e1567 | 2020-06-28 13:10:22 +0200 | [diff] [blame] | 794 | hi MySearch guifg=#110000 guibg=#001100 guisp=#000011 |
| 795 | call assert_equal('#110000', synIDattr(synIDtrans(hlID('MySearch')), 'fg#')) |
| 796 | call assert_equal('#001100', synIDattr(synIDtrans(hlID('MySearch')), 'bg#')) |
| 797 | call assert_equal('#000011', synIDattr(synIDtrans(hlID('MySearch')), 'sp#')) |
| 798 | hi clear |
| 799 | endfunc |
| 800 | |
Bram Moolenaar | de8f0f4 | 2020-06-30 18:45:43 +0200 | [diff] [blame] | 801 | " Test for using default highlighting group |
| 802 | func Test_highlight_default() |
| 803 | highlight MySearch ctermfg=7 |
| 804 | highlight default MySearch ctermfg=5 |
| 805 | let hlSearch = HighlightArgs('MySearch') |
| 806 | call assert_match('ctermfg=7', hlSearch) |
| 807 | |
| 808 | highlight default QFName ctermfg=3 |
| 809 | call assert_match('ctermfg=3', HighlightArgs('QFName')) |
| 810 | hi clear |
| 811 | endfunc |
| 812 | |
| 813 | " Test for 'ctermul in a highlight group |
| 814 | func Test_highlight_ctermul() |
| 815 | CheckNotGui |
| 816 | call assert_notmatch('ctermul=', HighlightArgs('Normal')) |
| 817 | highlight Normal ctermul=3 |
| 818 | call assert_match('ctermul=3', HighlightArgs('Normal')) |
Bram Moolenaar | 391c362 | 2020-09-29 20:59:17 +0200 | [diff] [blame] | 819 | call assert_equal('3', synIDattr(synIDtrans(hlID('Normal')), 'ul')) |
Bram Moolenaar | de8f0f4 | 2020-06-30 18:45:43 +0200 | [diff] [blame] | 820 | highlight Normal ctermul=NONE |
| 821 | endfunc |
| 822 | |
| 823 | " Test for specifying 'start' and 'stop' in a highlight group |
| 824 | func Test_highlight_start_stop() |
| 825 | hi HlGrp1 start=<Esc>[27h;<Esc>[<Space>r; |
| 826 | call assert_match("start=^[[27h;^[[ r;", HighlightArgs('HlGrp1')) |
| 827 | hi HlGrp1 start=NONE |
| 828 | call assert_notmatch("start=", HighlightArgs('HlGrp1')) |
| 829 | hi HlGrp2 stop=<Esc>[27h;<Esc>[<Space>r; |
| 830 | call assert_match("stop=^[[27h;^[[ r;", HighlightArgs('HlGrp2')) |
| 831 | hi HlGrp2 stop=NONE |
| 832 | call assert_notmatch("stop=", HighlightArgs('HlGrp2')) |
| 833 | hi clear |
| 834 | endfunc |
| 835 | |
| 836 | " Test for setting various 'term' attributes |
| 837 | func Test_highlight_term_attr() |
| 838 | hi HlGrp3 term=bold,underline,undercurl,strikethrough,reverse,italic,standout |
| 839 | call assert_equal('hi HlGrp3 term=bold,standout,underline,undercurl,italic,reverse,strikethrough', HighlightArgs('HlGrp3')) |
| 840 | hi HlGrp3 term=NONE |
| 841 | call assert_equal('hi HlGrp3 cleared', HighlightArgs('HlGrp3')) |
| 842 | hi clear |
| 843 | endfunc |
| 844 | |
Bram Moolenaar | 213da55 | 2020-09-17 19:59:26 +0200 | [diff] [blame] | 845 | func Test_highlight_clear_restores_links() |
| 846 | let aaa_id = hlID('aaa') |
| 847 | call assert_equal(aaa_id, 0) |
| 848 | |
| 849 | " create default link aaa --> bbb |
| 850 | hi def link aaa bbb |
| 851 | let id_aaa = hlID('aaa') |
| 852 | let hl_aaa_bbb = HighlightArgs('aaa') |
| 853 | |
| 854 | " try to redefine default link aaa --> ccc; check aaa --> bbb |
| 855 | hi def link aaa ccc |
| 856 | call assert_equal(HighlightArgs('aaa'), hl_aaa_bbb) |
| 857 | |
| 858 | " clear aaa; check aaa --> bbb |
| 859 | hi clear aaa |
| 860 | call assert_equal(HighlightArgs('aaa'), hl_aaa_bbb) |
| 861 | |
| 862 | " link aaa --> ccc; clear aaa; check aaa --> bbb |
| 863 | hi link aaa ccc |
| 864 | let id_ccc = hlID('ccc') |
| 865 | call assert_equal(synIDtrans(id_aaa), id_ccc) |
| 866 | hi clear aaa |
| 867 | call assert_equal(HighlightArgs('aaa'), hl_aaa_bbb) |
| 868 | |
| 869 | " forcibly set default link aaa --> ddd |
| 870 | hi! def link aaa ddd |
| 871 | let id_ddd = hlID('ddd') |
| 872 | let hl_aaa_ddd = HighlightArgs('aaa') |
| 873 | call assert_equal(synIDtrans(id_aaa), id_ddd) |
| 874 | |
| 875 | " link aaa --> eee; clear aaa; check aaa --> ddd |
| 876 | hi link aaa eee |
| 877 | let eee_id = hlID('eee') |
| 878 | call assert_equal(synIDtrans(id_aaa), eee_id) |
| 879 | hi clear aaa |
| 880 | call assert_equal(HighlightArgs('aaa'), hl_aaa_ddd) |
| 881 | endfunc |
| 882 | |
Bram Moolenaar | e8df010 | 2020-09-18 19:40:45 +0200 | [diff] [blame] | 883 | func Test_highlight_clear_restores_context() |
| 884 | func FuncContextDefault() |
| 885 | hi def link Context ContextDefault |
| 886 | endfun |
| 887 | |
| 888 | func FuncContextRelink() |
| 889 | " Dummy line |
| 890 | hi link Context ContextRelink |
| 891 | endfunc |
| 892 | |
| 893 | let scriptContextDefault = MakeScript("FuncContextDefault") |
| 894 | let scriptContextRelink = MakeScript("FuncContextRelink") |
| 895 | let patContextDefault = fnamemodify(scriptContextDefault, ':t') .. ' line 1' |
| 896 | let patContextRelink = fnamemodify(scriptContextRelink, ':t') .. ' line 2' |
| 897 | |
Bram Moolenaar | 2bbada8 | 2020-09-18 21:55:26 +0200 | [diff] [blame] | 898 | exec 'source ' .. scriptContextDefault |
Bram Moolenaar | e8df010 | 2020-09-18 19:40:45 +0200 | [diff] [blame] | 899 | let hlContextDefault = execute("verbose hi Context") |
| 900 | call assert_match(patContextDefault, hlContextDefault) |
| 901 | |
Bram Moolenaar | 2bbada8 | 2020-09-18 21:55:26 +0200 | [diff] [blame] | 902 | exec 'source ' .. scriptContextRelink |
Bram Moolenaar | e8df010 | 2020-09-18 19:40:45 +0200 | [diff] [blame] | 903 | let hlContextRelink = execute("verbose hi Context") |
| 904 | call assert_match(patContextRelink, hlContextRelink) |
| 905 | |
| 906 | hi clear |
| 907 | let hlContextAfterClear = execute("verbose hi Context") |
| 908 | call assert_match(patContextDefault, hlContextAfterClear) |
| 909 | |
| 910 | delfunc FuncContextDefault |
| 911 | delfunc FuncContextRelink |
| 912 | call delete(scriptContextDefault) |
| 913 | call delete(scriptContextRelink) |
| 914 | endfunc |
| 915 | |
Bram Moolenaar | 213da55 | 2020-09-17 19:59:26 +0200 | [diff] [blame] | 916 | func Test_highlight_default_colorscheme_restores_links() |
| 917 | hi link TestLink Identifier |
| 918 | hi TestHi ctermbg=red |
Bram Moolenaar | 05eb5b9 | 2020-09-16 15:43:21 +0200 | [diff] [blame] | 919 | |
| 920 | let hlTestLinkPre = HighlightArgs('TestLink') |
| 921 | let hlTestHiPre = HighlightArgs('TestHi') |
| 922 | |
| 923 | " Test colorscheme |
| 924 | hi clear |
| 925 | if exists('syntax_on') |
| 926 | syntax reset |
| 927 | endif |
| 928 | let g:colors_name = 'test' |
Bram Moolenaar | 213da55 | 2020-09-17 19:59:26 +0200 | [diff] [blame] | 929 | hi link TestLink ErrorMsg |
| 930 | hi TestHi ctermbg=green |
Bram Moolenaar | 05eb5b9 | 2020-09-16 15:43:21 +0200 | [diff] [blame] | 931 | |
| 932 | " Restore default highlighting |
| 933 | colorscheme default |
Bram Moolenaar | 05eb5b9 | 2020-09-16 15:43:21 +0200 | [diff] [blame] | 934 | " 'default' should work no matter if highlight group was cleared |
| 935 | hi def link TestLink Identifier |
| 936 | hi def TestHi ctermbg=red |
Bram Moolenaar | 05eb5b9 | 2020-09-16 15:43:21 +0200 | [diff] [blame] | 937 | let hlTestLinkPost = HighlightArgs('TestLink') |
| 938 | let hlTestHiPost = HighlightArgs('TestHi') |
Bram Moolenaar | 05eb5b9 | 2020-09-16 15:43:21 +0200 | [diff] [blame] | 939 | call assert_equal(hlTestLinkPre, hlTestLinkPost) |
| 940 | call assert_equal(hlTestHiPre, hlTestHiPost) |
| 941 | hi clear |
| 942 | endfunc |
| 943 | |
Drew Vogel | e30d102 | 2021-10-24 20:35:07 +0100 | [diff] [blame] | 944 | func Test_colornames_assignment_and_lookup() |
Drew Vogel | a0fca17 | 2021-11-13 10:50:01 +0000 | [diff] [blame] | 945 | CheckAnyOf Feature:gui_running Feature:termguicolors |
| 946 | |
Drew Vogel | e30d102 | 2021-10-24 20:35:07 +0100 | [diff] [blame] | 947 | " Ensure highlight command can find custom color. |
| 948 | let v:colornames['a redish white'] = '#ffeedd' |
| 949 | highlight Normal guifg='a redish white' |
| 950 | highlight clear |
Drew Vogel | a0fca17 | 2021-11-13 10:50:01 +0000 | [diff] [blame] | 951 | call ClearDict(v:colornames) |
Drew Vogel | e30d102 | 2021-10-24 20:35:07 +0100 | [diff] [blame] | 952 | endfunc |
| 953 | |
| 954 | func Test_colornames_default_list() |
Drew Vogel | a0fca17 | 2021-11-13 10:50:01 +0000 | [diff] [blame] | 955 | CheckAnyOf Feature:gui_running Feature:termguicolors |
| 956 | |
Drew Vogel | e30d102 | 2021-10-24 20:35:07 +0100 | [diff] [blame] | 957 | " Ensure default lists are loaded automatically and can be used for all gui fields. |
Drew Vogel | a0fca17 | 2021-11-13 10:50:01 +0000 | [diff] [blame] | 958 | call assert_equal(0, len(v:colornames)) |
Drew Vogel | e30d102 | 2021-10-24 20:35:07 +0100 | [diff] [blame] | 959 | highlight Normal guifg='rebecca purple' guibg='rebecca purple' guisp='rebecca purple' |
Drew Vogel | a0fca17 | 2021-11-13 10:50:01 +0000 | [diff] [blame] | 960 | call assert_notequal(0, len(v:colornames)) |
| 961 | echo v:colornames['rebecca purple'] |
Drew Vogel | e30d102 | 2021-10-24 20:35:07 +0100 | [diff] [blame] | 962 | highlight clear |
Drew Vogel | a0fca17 | 2021-11-13 10:50:01 +0000 | [diff] [blame] | 963 | call ClearDict(v:colornames) |
Drew Vogel | e30d102 | 2021-10-24 20:35:07 +0100 | [diff] [blame] | 964 | endfunc |
| 965 | |
| 966 | func Test_colornames_overwrite_default() |
Drew Vogel | a0fca17 | 2021-11-13 10:50:01 +0000 | [diff] [blame] | 967 | CheckAnyOf Feature:gui_running Feature:termguicolors |
| 968 | |
Drew Vogel | e30d102 | 2021-10-24 20:35:07 +0100 | [diff] [blame] | 969 | " Ensure entries in v:colornames can be overwritten. |
| 970 | " Load default color scheme to trigger default color list loading. |
| 971 | colorscheme default |
| 972 | let old_rebecca_purple = v:colornames['rebecca purple'] |
| 973 | highlight Normal guifg='rebecca purple' guibg='rebecca purple' |
| 974 | let v:colornames['rebecca purple'] = '#550099' |
| 975 | highlight Normal guifg='rebecca purple' guibg='rebecca purple' |
| 976 | let v:colornames['rebecca purple'] = old_rebecca_purple |
| 977 | highlight clear |
| 978 | endfunc |
| 979 | |
| 980 | func Test_colornames_assignment_and_unassignment() |
Drew Vogel | a0fca17 | 2021-11-13 10:50:01 +0000 | [diff] [blame] | 981 | " No feature check is needed for this test because the v:colornames dict |
| 982 | " always exists with +eval. The feature checks are only required for |
| 983 | " commands that do color lookup. |
| 984 | |
Drew Vogel | e30d102 | 2021-10-24 20:35:07 +0100 | [diff] [blame] | 985 | " Ensure we cannot overwrite the v:colornames dict. |
| 986 | call assert_fails("let v:colornames = {}", 'E46:') |
| 987 | |
| 988 | " Ensure we can delete entries from the v:colornames dict. |
| 989 | let v:colornames['x1'] = '#111111' |
| 990 | call assert_equal(v:colornames['x1'], '#111111') |
| 991 | unlet v:colornames['x1'] |
| 992 | call assert_fails("echo v:colornames['x1']") |
| 993 | endfunc |
| 994 | |
Yegappan Lakshmanan | d1a8d65 | 2021-11-03 21:56:45 +0000 | [diff] [blame] | 995 | " Test for the hlget() function |
| 996 | func Test_hlget() |
| 997 | let lines =<< trim END |
| 998 | call assert_notequal([], filter(hlget(), 'v:val.name == "Visual"')) |
| 999 | call assert_equal([], hlget('SomeHLGroup')) |
| 1000 | highlight MyHLGroup term=standout cterm=reverse ctermfg=10 ctermbg=Black |
| 1001 | call assert_equal([{'id': hlID('MyHLGroup'), 'ctermfg': '10', 'name': 'MyHLGroup', 'term': {'standout': v:true}, 'ctermbg': '0', 'cterm': {'reverse': v:true}}], hlget('MyHLGroup')) |
| 1002 | highlight clear MyHLGroup |
| 1003 | call assert_equal(v:true, hlget('MyHLGroup')[0].cleared) |
| 1004 | highlight link MyHLGroup IncSearch |
| 1005 | call assert_equal('IncSearch', hlget('MyHLGroup')[0].linksto) |
| 1006 | highlight clear MyHLGroup |
| 1007 | call assert_equal([], hlget(test_null_string())) |
| 1008 | call assert_equal([], hlget("")) |
| 1009 | END |
| 1010 | call CheckLegacyAndVim9Success(lines) |
| 1011 | |
| 1012 | " Test for resolving highlight group links |
| 1013 | let lines =<< trim END |
| 1014 | highlight hlgA term=bold |
| 1015 | VAR hlgAid = hlID('hlgA') |
| 1016 | highlight link hlgB hlgA |
| 1017 | VAR hlgBid = hlID('hlgB') |
| 1018 | highlight link hlgC hlgB |
| 1019 | VAR hlgCid = hlID('hlgC') |
| 1020 | call assert_equal('hlgA', hlget('hlgB')[0].linksto) |
| 1021 | call assert_equal('hlgB', hlget('hlgC')[0].linksto) |
| 1022 | call assert_equal([{'id': hlgAid, 'name': 'hlgA', |
| 1023 | \ 'term': {'bold': v:true}}], hlget('hlgA')) |
| 1024 | call assert_equal([{'id': hlgBid, 'name': 'hlgB', |
| 1025 | \ 'linksto': 'hlgA'}], hlget('hlgB')) |
| 1026 | call assert_equal([{'id': hlgCid, 'name': 'hlgC', |
| 1027 | \ 'linksto': 'hlgB'}], hlget('hlgC')) |
| 1028 | call assert_equal([{'id': hlgAid, 'name': 'hlgA', |
| 1029 | \ 'term': {'bold': v:true}}], hlget('hlgA', v:false)) |
| 1030 | call assert_equal([{'id': hlgBid, 'name': 'hlgB', |
| 1031 | \ 'linksto': 'hlgA'}], hlget('hlgB', 0)) |
| 1032 | call assert_equal([{'id': hlgCid, 'name': 'hlgC', |
| 1033 | \ 'linksto': 'hlgB'}], hlget('hlgC', v:false)) |
| 1034 | call assert_equal([{'id': hlgAid, 'name': 'hlgA', |
| 1035 | \ 'term': {'bold': v:true}}], hlget('hlgA', v:true)) |
| 1036 | call assert_equal([{'id': hlgBid, 'name': 'hlgB', |
| 1037 | \ 'term': {'bold': v:true}}], hlget('hlgB', 1)) |
| 1038 | call assert_equal([{'id': hlgCid, 'name': 'hlgC', |
| 1039 | \ 'term': {'bold': v:true}}], hlget('hlgC', v:true)) |
| 1040 | END |
| 1041 | call CheckLegacyAndVim9Success(lines) |
| 1042 | |
| 1043 | call assert_fails('call hlget([])', 'E1174:') |
| 1044 | call assert_fails('call hlget("abc", "xyz")', 'E1212:') |
| 1045 | endfunc |
| 1046 | |
| 1047 | " Test for the hlset() function |
| 1048 | func Test_hlset() |
| 1049 | let lines =<< trim END |
| 1050 | call assert_equal(0, hlset(test_null_list())) |
| 1051 | call assert_equal(0, hlset([])) |
| 1052 | call assert_fails('call hlset(["Search"])', 'E715:') |
| 1053 | call hlset(hlget()) |
| 1054 | call hlset([{'name': 'NewHLGroup', 'cterm': {'reverse': v:true}, 'ctermfg': '10'}]) |
| 1055 | call assert_equal({'reverse': v:true}, hlget('NewHLGroup')[0].cterm) |
| 1056 | call hlset([{'name': 'NewHLGroup', 'cterm': {'bold': v:true}}]) |
| 1057 | call assert_equal({'bold': v:true}, hlget('NewHLGroup')[0].cterm) |
| 1058 | call hlset([{'name': 'NewHLGroup', 'cleared': v:true}]) |
| 1059 | call assert_equal(v:true, hlget('NewHLGroup')[0].cleared) |
| 1060 | call hlset([{'name': 'NewHLGroup', 'linksto': 'Search'}]) |
| 1061 | call assert_false(has_key(hlget('NewHLGroup')[0], 'cleared')) |
| 1062 | call assert_equal('Search', hlget('NewHLGroup')[0].linksto) |
| 1063 | call assert_fails("call hlset([{'name': [], 'ctermfg': '10'}])", 'E928:') |
| 1064 | call assert_fails("call hlset([{'name': 'NewHLGroup', 'cleared': []}])", |
| 1065 | \ 'E745:') |
| 1066 | call assert_fails("call hlset([{'name': 'NewHLGroup', 'cterm': 'Blue'}])", |
| 1067 | \ 'E715:') |
| 1068 | call assert_fails("call hlset([{'name': 'NewHLGroup', 'ctermbg': []}])", |
| 1069 | \ 'E928:') |
| 1070 | call assert_fails("call hlset([{'name': 'NewHLGroup', 'ctermfg': []}])", |
| 1071 | \ 'E928:') |
| 1072 | call assert_fails("call hlset([{'name': 'NewHLGroup', 'ctermul': []}])", |
| 1073 | \ 'E928:') |
| 1074 | if has('gui') |
| 1075 | call assert_fails("call hlset([{'name': 'NewHLGroup', 'font': []}])", |
| 1076 | \ 'E928:') |
| 1077 | endif |
| 1078 | call assert_fails("call hlset([{'name': 'NewHLGroup', 'gui': 'Cyan'}])", |
| 1079 | \ 'E715:') |
| 1080 | call assert_fails("call hlset([{'name': 'NewHLGroup', 'guibg': []}])", |
| 1081 | \ 'E928:') |
| 1082 | call assert_fails("call hlset([{'name': 'NewHLGroup', 'guifg': []}])", |
| 1083 | \ 'E928:') |
| 1084 | call assert_fails("call hlset([{'name': 'NewHLGroup', 'guisp': []}])", |
| 1085 | \ 'E928:') |
| 1086 | call assert_fails("call hlset([{'name': 'NewHLGroup', 'linksto': []}])", |
| 1087 | \ 'E928:') |
| 1088 | call assert_fails("call hlset([{'name': 'NewHLGroup', 'start': []}])", |
| 1089 | \ 'E928:') |
| 1090 | call assert_fails("call hlset([{'name': 'NewHLGroup', 'stop': []}])", |
| 1091 | \ 'E928:') |
| 1092 | call assert_fails("call hlset([{'name': 'NewHLGroup', 'term': 'Cyan'}])", |
| 1093 | \ 'E715:') |
| 1094 | call assert_equal('Search', hlget('NewHLGroup')[0].linksto) |
| 1095 | highlight clear NewHLGroup |
| 1096 | END |
| 1097 | call CheckLegacyAndVim9Success(lines) |
| 1098 | |
| 1099 | " Test for clearing the 'term', 'cterm' and 'gui' attributes of a highlight |
| 1100 | " group. |
| 1101 | let lines =<< trim END |
| 1102 | highlight myhlg1 term=bold cterm=italic gui=standout |
| 1103 | VAR id = hlID('myhlg1') |
| 1104 | call hlset([{'name': 'myhlg1', 'term': {}}]) |
| 1105 | call assert_equal([{'id': id, 'name': 'myhlg1', |
| 1106 | \ 'cterm': {'italic': v:true}, 'gui': {'standout': v:true}}], |
| 1107 | \ hlget('myhlg1')) |
| 1108 | call hlset([{'name': 'myhlg1', 'cterm': {}}]) |
| 1109 | call assert_equal([{'id': id, 'name': 'myhlg1', |
| 1110 | \ 'gui': {'standout': v:true}}], hlget('myhlg1')) |
| 1111 | call hlset([{'name': 'myhlg1', 'gui': {}}]) |
| 1112 | call assert_equal([{'id': id, 'name': 'myhlg1', 'cleared': v:true}], |
| 1113 | \ hlget('myhlg1')) |
| 1114 | highlight clear myhlg1 |
| 1115 | END |
| 1116 | call CheckLegacyAndVim9Success(lines) |
| 1117 | |
| 1118 | " Test for setting all the 'term', 'cterm' and 'gui' attributes of a |
| 1119 | " highlight group |
| 1120 | let lines =<< trim END |
| 1121 | VAR attr = {'bold': v:true, 'underline': v:true, 'undercurl': v:true, |
| 1122 | \ 'strikethrough': v:true, 'reverse': v:true, 'italic': v:true, |
| 1123 | \ 'standout': v:true, 'nocombine': v:true} |
| 1124 | call hlset([{'name': 'myhlg2', 'term': attr, 'cterm': attr, 'gui': attr}]) |
| 1125 | VAR id2 = hlID('myhlg2') |
Yegappan Lakshmanan | 2a16dc6 | 2021-11-16 17:19:30 +0000 | [diff] [blame] | 1126 | VAR expected = "myhlg2 xxx term=bold,standout,underline,undercurl,italic,reverse,nocombine,strikethrough cterm=bold,standout,underline,undercurl,italic,reverse,nocombine,strikethrough gui=bold,standout,underline,undercurl,italic,reverse,nocombine,strikethrough" |
| 1127 | VAR output = execute('highlight myhlg2') |
| 1128 | LET output = output->split("\n")->join()->substitute('\s\+', ' ', 'g') |
| 1129 | call assert_equal(expected, output) |
Yegappan Lakshmanan | d1a8d65 | 2021-11-03 21:56:45 +0000 | [diff] [blame] | 1130 | call assert_equal([{'id': id2, 'name': 'myhlg2', 'gui': attr, |
| 1131 | \ 'term': attr, 'cterm': attr}], hlget('myhlg2')) |
| 1132 | END |
| 1133 | call CheckLegacyAndVim9Success(lines) |
| 1134 | |
| 1135 | " Test for clearing some of the 'term', 'cterm' and 'gui' attributes of a |
| 1136 | " highlight group |
| 1137 | let lines =<< trim END |
| 1138 | VAR attr = {'bold': v:false, 'underline': v:true, 'strikethrough': v:true} |
| 1139 | call hlset([{'name': 'myhlg2', 'term': attr, 'cterm': attr, 'gui': attr}]) |
| 1140 | VAR id2 = hlID('myhlg2') |
Yegappan Lakshmanan | 2a16dc6 | 2021-11-16 17:19:30 +0000 | [diff] [blame] | 1141 | VAR expected = "myhlg2 xxx term=underline,strikethrough cterm=underline,strikethrough gui=underline,strikethrough" |
| 1142 | VAR output = execute('highlight myhlg2') |
| 1143 | LET output = output->split("\n")->join()->substitute('\s\+', ' ', 'g') |
| 1144 | call assert_equal(expected, output) |
Yegappan Lakshmanan | d1a8d65 | 2021-11-03 21:56:45 +0000 | [diff] [blame] | 1145 | LET attr = {'underline': v:true, 'strikethrough': v:true} |
| 1146 | call assert_equal([{'id': id2, 'name': 'myhlg2', 'gui': attr, |
| 1147 | \ 'term': attr, 'cterm': attr}], hlget('myhlg2')) |
| 1148 | END |
| 1149 | call CheckLegacyAndVim9Success(lines) |
Dominique Pelle | 6a950a6 | 2021-11-13 18:44:37 +0000 | [diff] [blame] | 1150 | |
Yegappan Lakshmanan | 2a16dc6 | 2021-11-16 17:19:30 +0000 | [diff] [blame] | 1151 | " Test for clearing the attributes and link of a highlight group |
| 1152 | let lines =<< trim END |
| 1153 | highlight myhlg3 ctermbg=green guibg=green |
| 1154 | highlight! default link myhlg3 ErrorMsg |
| 1155 | VAR id3 = hlID('myhlg3') |
| 1156 | call hlset([{'name': 'myhlg3', 'cleared': v:true, 'linksto': 'NONE'}]) |
| 1157 | call assert_equal([{'id': id3, 'name': 'myhlg3', 'cleared': v:true}], |
| 1158 | \ hlget('myhlg3')) |
| 1159 | highlight clear hlg3 |
| 1160 | END |
| 1161 | call CheckLegacyAndVim9Success(lines) |
| 1162 | |
| 1163 | " Test for setting default attributes for a highlight group |
| 1164 | let lines =<< trim END |
| 1165 | call hlset([{'name': 'hlg4', 'ctermfg': '8'}]) |
| 1166 | call hlset([{'name': 'hlg4', 'default': v:true, 'ctermfg': '9'}]) |
| 1167 | VAR id4 = hlID('hlg4') |
| 1168 | call assert_equal([{'id': id4, 'name': 'hlg4', 'ctermfg': '8'}], |
| 1169 | \ hlget('hlg4')) |
| 1170 | highlight clear hlg4 |
| 1171 | |
| 1172 | call hlset([{'name': 'hlg5', 'default': v:true, 'ctermbg': '2'}]) |
| 1173 | call hlset([{'name': 'hlg5', 'ctermbg': '4'}]) |
| 1174 | VAR id5 = hlID('hlg5') |
| 1175 | call assert_equal([{'id': id5, 'name': 'hlg5', 'ctermbg': '4'}], |
| 1176 | \ hlget('hlg5')) |
| 1177 | highlight clear hlg5 |
| 1178 | |
| 1179 | call hlset([{'name': 'hlg6', 'linksto': 'Error'}]) |
| 1180 | VAR id6 = hlID('hlg6') |
| 1181 | call hlset([{'name': 'hlg6', 'default': v:true, 'ctermbg': '2'}]) |
| 1182 | call assert_equal([{'id': id6, 'name': 'hlg6', 'linksto': 'Error'}], |
| 1183 | \ hlget('hlg6')) |
| 1184 | highlight clear hlg6 |
| 1185 | END |
| 1186 | call CheckLegacyAndVim9Success(lines) |
| 1187 | |
| 1188 | " Test for setting default links for a highlight group |
| 1189 | let lines =<< trim END |
| 1190 | call hlset([{'name': 'hlg7', 'ctermfg': '5'}]) |
| 1191 | call hlset([{'name': 'hlg7', 'default': v:true, 'linksto': 'Search'}]) |
| 1192 | VAR id7 = hlID('hlg7') |
| 1193 | call assert_equal([{'id': id7, 'name': 'hlg7', 'ctermfg': '5'}], |
| 1194 | \ hlget('hlg7')) |
| 1195 | highlight clear hlg7 |
| 1196 | |
| 1197 | call hlset([{'name': 'hlg8', 'default': v:true, 'linksto': 'Search'}]) |
| 1198 | VAR id8 = hlID('hlg8') |
| 1199 | call assert_equal([{'id': id8, 'name': 'hlg8', 'default': v:true, |
| 1200 | \ 'linksto': 'Search'}], hlget('hlg8')) |
| 1201 | call hlset([{'name': 'hlg8', 'ctermbg': '2'}]) |
| 1202 | call assert_equal([{'id': id8, 'name': 'hlg8', 'ctermbg': '2'}], |
| 1203 | \ hlget('hlg8')) |
| 1204 | highlight clear hlg8 |
| 1205 | |
| 1206 | highlight default link hlg9 ErrorMsg |
| 1207 | VAR hlg_save = hlget('hlg9') |
| 1208 | LET hlg_save[0]['name'] = 'hlg9dup' |
| 1209 | call hlset(hlg_save) |
| 1210 | VAR id9 = hlID('hlg9dup') |
| 1211 | highlight clear hlg9dup |
| 1212 | call assert_equal([{'id': id9, 'name': 'hlg9dup', 'default': v:true, |
| 1213 | \ 'linksto': 'ErrorMsg'}], hlget('hlg9dup')) |
| 1214 | highlight clear hlg9 |
| 1215 | END |
| 1216 | call CheckLegacyAndVim9Success(lines) |
| 1217 | |
| 1218 | " Test for force creating a link to a highlight group |
| 1219 | let lines =<< trim END |
| 1220 | call hlset([{'name': 'hlg10', 'ctermfg': '8'}]) |
| 1221 | call hlset([{'name': 'hlg10', 'linksto': 'Search'}]) |
| 1222 | VAR id10 = hlID('hlg10') |
| 1223 | call assert_equal([{'id': id10, 'name': 'hlg10', 'ctermfg': '8'}], |
| 1224 | \ hlget('hlg10')) |
| 1225 | call hlset([{'name': 'hlg10', 'linksto': 'Search', 'force': v:true}]) |
| 1226 | call assert_equal([{'id': id10, 'name': 'hlg10', 'ctermfg': '8', |
| 1227 | \ 'linksto': 'Search'}], hlget('hlg10')) |
| 1228 | highlight clear hlg10 |
| 1229 | END |
| 1230 | call CheckLegacyAndVim9Success(lines) |
Yegappan Lakshmanan | d1a8d65 | 2021-11-03 21:56:45 +0000 | [diff] [blame] | 1231 | endfunc |
| 1232 | |
Bram Moolenaar | ee4e0c1 | 2020-04-06 21:35:05 +0200 | [diff] [blame] | 1233 | " vim: shiftwidth=2 sts=2 expandtab |