Bram Moolenaar | b8060fe | 2016-01-19 22:29:28 +0100 | [diff] [blame] | 1 | " Test for syntax and syntax iskeyword option |
| 2 | |
Bram Moolenaar | b46fecd | 2019-06-15 17:58:09 +0200 | [diff] [blame] | 3 | source check.vim |
| 4 | CheckFeature syntax |
Bram Moolenaar | b8060fe | 2016-01-19 22:29:28 +0100 | [diff] [blame] | 5 | |
Bram Moolenaar | 4d78589 | 2017-06-22 22:00:50 +0200 | [diff] [blame] | 6 | source view_util.vim |
Bram Moolenaar | 6bb2cdf | 2018-02-24 19:53:53 +0100 | [diff] [blame] | 7 | source screendump.vim |
Bram Moolenaar | 4d78589 | 2017-06-22 22:00:50 +0200 | [diff] [blame] | 8 | |
Bram Moolenaar | b8060fe | 2016-01-19 22:29:28 +0100 | [diff] [blame] | 9 | func GetSyntaxItem(pat) |
| 10 | let c = '' |
| 11 | let a = ['a', getreg('a'), getregtype('a')] |
| 12 | 0 |
| 13 | redraw! |
| 14 | call search(a:pat, 'W') |
| 15 | let synid = synID(line('.'), col('.'), 1) |
| 16 | while synid == synID(line('.'), col('.'), 1) |
| 17 | norm! v"ay |
| 18 | " stop at whitespace |
| 19 | if @a =~# '\s' |
| 20 | break |
| 21 | endif |
| 22 | let c .= @a |
| 23 | norm! l |
| 24 | endw |
| 25 | call call('setreg', a) |
| 26 | 0 |
| 27 | return c |
| 28 | endfunc |
| 29 | |
| 30 | func Test_syn_iskeyword() |
| 31 | new |
| 32 | call setline(1, [ |
| 33 | \ 'CREATE TABLE FOOBAR(', |
| 34 | \ ' DLTD_BY VARCHAR2(100)', |
| 35 | \ ');', |
Bram Moolenaar | 037c54f | 2019-04-20 23:47:46 +0200 | [diff] [blame] | 36 | \ '']) |
Bram Moolenaar | b8060fe | 2016-01-19 22:29:28 +0100 | [diff] [blame] | 37 | |
| 38 | syntax on |
| 39 | set ft=sql |
| 40 | syn match SYN /C\k\+\>/ |
| 41 | hi link SYN ErrorMsg |
| 42 | call assert_equal('DLTD_BY', GetSyntaxItem('DLTD')) |
| 43 | /\<D\k\+\>/:norm! ygn |
| 44 | call assert_equal('DLTD_BY', @0) |
| 45 | redir @c |
| 46 | syn iskeyword |
| 47 | redir END |
| 48 | call assert_equal("\nsyntax iskeyword not set", @c) |
| 49 | |
| 50 | syn iskeyword @,48-57,_,192-255 |
| 51 | redir @c |
| 52 | syn iskeyword |
| 53 | redir END |
| 54 | call assert_equal("\nsyntax iskeyword @,48-57,_,192-255", @c) |
| 55 | |
| 56 | setlocal isk-=_ |
| 57 | call assert_equal('DLTD_BY', GetSyntaxItem('DLTD')) |
| 58 | /\<D\k\+\>/:norm! ygn |
Bram Moolenaar | 73b484c | 2016-12-11 15:11:17 +0100 | [diff] [blame] | 59 | let b2 = @0 |
Bram Moolenaar | b8060fe | 2016-01-19 22:29:28 +0100 | [diff] [blame] | 60 | call assert_equal('DLTD', @0) |
| 61 | |
| 62 | syn iskeyword clear |
| 63 | redir @c |
| 64 | syn iskeyword |
| 65 | redir END |
| 66 | call assert_equal("\nsyntax iskeyword not set", @c) |
| 67 | |
| 68 | quit! |
| 69 | endfunc |
Bram Moolenaar | c369133 | 2016-04-20 12:49:49 +0200 | [diff] [blame] | 70 | |
| 71 | func Test_syntax_after_reload() |
| 72 | split Xsomefile |
| 73 | call setline(1, ['hello', 'there']) |
| 74 | w! |
| 75 | only! |
| 76 | setl filetype=hello |
| 77 | au FileType hello let g:gotit = 1 |
| 78 | call assert_false(exists('g:gotit')) |
| 79 | edit other |
| 80 | buf Xsomefile |
| 81 | call assert_equal('hello', &filetype) |
| 82 | call assert_true(exists('g:gotit')) |
| 83 | call delete('Xsomefile') |
| 84 | endfunc |
Bram Moolenaar | 73b484c | 2016-12-11 15:11:17 +0100 | [diff] [blame] | 85 | |
| 86 | func Test_syntime() |
| 87 | if !has('profile') |
Bram Moolenaar | 4c8980b | 2016-12-11 15:24:48 +0100 | [diff] [blame] | 88 | return |
Bram Moolenaar | 73b484c | 2016-12-11 15:11:17 +0100 | [diff] [blame] | 89 | endif |
| 90 | |
| 91 | syntax on |
| 92 | syntime on |
| 93 | let a = execute('syntime report') |
| 94 | call assert_equal("\nNo Syntax items defined for this buffer", a) |
| 95 | |
| 96 | view ../memfile_test.c |
| 97 | setfiletype cpp |
| 98 | redraw |
| 99 | let a = execute('syntime report') |
| 100 | call assert_match('^ TOTAL *COUNT *MATCH *SLOWEST *AVERAGE *NAME *PATTERN', a) |
| 101 | call assert_match(' \d*\.\d* \+[^0]\d* .* cppRawString ', a) |
| 102 | call assert_match(' \d*\.\d* \+[^0]\d* .* cppNumber ', a) |
| 103 | |
| 104 | syntime off |
| 105 | syntime clear |
| 106 | let a = execute('syntime report') |
| 107 | call assert_match('^ TOTAL *COUNT *MATCH *SLOWEST *AVERAGE *NAME *PATTERN', a) |
| 108 | call assert_notmatch('.* cppRawString *', a) |
| 109 | call assert_notmatch('.* cppNumber*', a) |
| 110 | call assert_notmatch('[1-9]', a) |
| 111 | |
| 112 | call assert_fails('syntime abc', 'E475') |
| 113 | |
| 114 | syntax clear |
| 115 | let a = execute('syntime report') |
| 116 | call assert_equal("\nNo Syntax items defined for this buffer", a) |
| 117 | |
| 118 | bd |
| 119 | endfunc |
| 120 | |
Bram Moolenaar | b513d30 | 2018-12-02 14:55:08 +0100 | [diff] [blame] | 121 | func Test_syntime_completion() |
| 122 | if !has('profile') |
| 123 | return |
| 124 | endif |
| 125 | |
| 126 | call feedkeys(":syntime \<C-A>\<C-B>\"\<CR>", 'tx') |
| 127 | call assert_equal('"syntime clear off on report', @:) |
| 128 | endfunc |
| 129 | |
Bram Moolenaar | 73b484c | 2016-12-11 15:11:17 +0100 | [diff] [blame] | 130 | func Test_syntax_list() |
| 131 | syntax on |
| 132 | let a = execute('syntax list') |
| 133 | call assert_equal("\nNo Syntax items defined for this buffer", a) |
| 134 | |
| 135 | view ../memfile_test.c |
| 136 | setfiletype c |
| 137 | |
| 138 | let a = execute('syntax list') |
| 139 | call assert_match('cInclude*', a) |
| 140 | call assert_match('cDefine', a) |
| 141 | |
| 142 | let a = execute('syntax list cDefine') |
| 143 | call assert_notmatch('cInclude*', a) |
| 144 | call assert_match('cDefine', a) |
| 145 | call assert_match(' links to Macro$', a) |
| 146 | |
| 147 | call assert_fails('syntax list ABCD', 'E28:') |
| 148 | call assert_fails('syntax list @ABCD', 'E392:') |
| 149 | |
| 150 | syntax clear |
| 151 | let a = execute('syntax list') |
| 152 | call assert_equal("\nNo Syntax items defined for this buffer", a) |
| 153 | |
| 154 | bd |
| 155 | endfunc |
| 156 | |
| 157 | func Test_syntax_completion() |
| 158 | call feedkeys(":syn \<C-A>\<C-B>\"\<CR>", 'tx') |
| 159 | call assert_equal('"syn case clear cluster conceal enable include iskeyword keyword list manual match off on region reset spell sync', @:) |
| 160 | |
| 161 | call feedkeys(":syn case \<C-A>\<C-B>\"\<CR>", 'tx') |
| 162 | call assert_equal('"syn case ignore match', @:) |
| 163 | |
Bram Moolenaar | 2d02839 | 2017-01-08 18:28:22 +0100 | [diff] [blame] | 164 | call feedkeys(":syn spell \<C-A>\<C-B>\"\<CR>", 'tx') |
| 165 | call assert_equal('"syn spell default notoplevel toplevel', @:) |
| 166 | |
| 167 | call feedkeys(":syn sync \<C-A>\<C-B>\"\<CR>", 'tx') |
| 168 | call assert_equal('"syn sync ccomment clear fromstart linebreaks= linecont lines= match maxlines= minlines= region', @:) |
| 169 | |
Bram Moolenaar | d61e8aa | 2017-01-17 17:44:46 +0100 | [diff] [blame] | 170 | " Check that clearing "Aap" avoids it showing up before Boolean. |
| 171 | hi Aap ctermfg=blue |
| 172 | call feedkeys(":syn list \<C-A>\<C-B>\"\<CR>", 'tx') |
| 173 | call assert_match('^"syn list Aap Boolean Character ', @:) |
| 174 | hi clear Aap |
| 175 | |
Bram Moolenaar | 73b484c | 2016-12-11 15:11:17 +0100 | [diff] [blame] | 176 | call feedkeys(":syn list \<C-A>\<C-B>\"\<CR>", 'tx') |
| 177 | call assert_match('^"syn list Boolean Character ', @:) |
| 178 | |
| 179 | call feedkeys(":syn match \<C-A>\<C-B>\"\<CR>", 'tx') |
| 180 | call assert_match('^"syn match Boolean Character ', @:) |
| 181 | endfunc |
Bram Moolenaar | de318c5 | 2017-01-17 16:27:10 +0100 | [diff] [blame] | 182 | |
| 183 | func Test_syntax_arg_skipped() |
| 184 | syn clear |
| 185 | syntax case ignore |
| 186 | if 0 |
| 187 | syntax case match |
| 188 | endif |
| 189 | call assert_match('case ignore', execute('syntax case')) |
| 190 | |
| 191 | syn keyword Foo foo |
| 192 | call assert_match('Foo', execute('syntax')) |
| 193 | syn clear |
| 194 | call assert_match('case match', execute('syntax case')) |
| 195 | call assert_notmatch('Foo', execute('syntax')) |
| 196 | |
| 197 | if has('conceal') |
| 198 | syn clear |
| 199 | syntax conceal on |
| 200 | if 0 |
| 201 | syntax conceal off |
| 202 | endif |
| 203 | call assert_match('conceal on', execute('syntax conceal')) |
| 204 | syn clear |
| 205 | call assert_match('conceal off', execute('syntax conceal')) |
Bram Moolenaar | 58f60ca | 2017-01-17 17:19:00 +0100 | [diff] [blame] | 206 | |
| 207 | syntax conceal on |
| 208 | syntax conceal off |
| 209 | call assert_match('conceal off', execute('syntax conceal')) |
Bram Moolenaar | de318c5 | 2017-01-17 16:27:10 +0100 | [diff] [blame] | 210 | endif |
| 211 | |
Bram Moolenaar | d61e8aa | 2017-01-17 17:44:46 +0100 | [diff] [blame] | 212 | syntax region Bar start=/</ end=/>/ |
Bram Moolenaar | de318c5 | 2017-01-17 16:27:10 +0100 | [diff] [blame] | 213 | if 0 |
| 214 | syntax region NotTest start=/</ end=/>/ contains=@Spell |
| 215 | endif |
Bram Moolenaar | d61e8aa | 2017-01-17 17:44:46 +0100 | [diff] [blame] | 216 | call assert_match('Bar', execute('syntax')) |
Bram Moolenaar | de318c5 | 2017-01-17 16:27:10 +0100 | [diff] [blame] | 217 | call assert_notmatch('NotTest', execute('syntax')) |
| 218 | call assert_notmatch('Spell', execute('syntax')) |
| 219 | |
| 220 | hi Foo ctermfg=blue |
| 221 | let a = execute('hi Foo') |
| 222 | if 0 |
| 223 | syntax rest |
| 224 | endif |
| 225 | call assert_equal(a, execute('hi Foo')) |
Bram Moolenaar | d61e8aa | 2017-01-17 17:44:46 +0100 | [diff] [blame] | 226 | hi clear Bar |
| 227 | hi clear Foo |
Bram Moolenaar | de318c5 | 2017-01-17 16:27:10 +0100 | [diff] [blame] | 228 | |
| 229 | set ft=tags |
| 230 | syn off |
| 231 | if 0 |
| 232 | syntax enable |
| 233 | endif |
| 234 | call assert_match('No Syntax items defined', execute('syntax')) |
| 235 | syntax enable |
| 236 | call assert_match('tagComment', execute('syntax')) |
| 237 | set ft= |
| 238 | |
| 239 | syn clear |
| 240 | if 0 |
| 241 | syntax include @Spell nothing |
| 242 | endif |
| 243 | call assert_notmatch('Spell', execute('syntax')) |
| 244 | |
| 245 | syn clear |
| 246 | syn iskeyword 48-57,$,_ |
| 247 | call assert_match('48-57,$,_', execute('syntax iskeyword')) |
| 248 | if 0 |
| 249 | syn clear |
| 250 | syn iskeyword clear |
| 251 | endif |
| 252 | call assert_match('48-57,$,_', execute('syntax iskeyword')) |
| 253 | syn iskeyword clear |
| 254 | call assert_match('not set', execute('syntax iskeyword')) |
| 255 | syn iskeyword 48-57,$,_ |
| 256 | syn clear |
| 257 | call assert_match('not set', execute('syntax iskeyword')) |
| 258 | |
| 259 | syn clear |
| 260 | syn keyword Foo foo |
| 261 | if 0 |
| 262 | syn keyword NotAdded bar |
| 263 | endif |
| 264 | call assert_match('Foo', execute('syntax')) |
| 265 | call assert_notmatch('NotAdded', execute('highlight')) |
| 266 | |
| 267 | syn clear |
| 268 | syn keyword Foo foo |
| 269 | call assert_match('Foo', execute('syntax')) |
| 270 | call assert_match('Foo', execute('syntax list')) |
| 271 | call assert_notmatch('Foo', execute('if 0 | syntax | endif')) |
| 272 | call assert_notmatch('Foo', execute('if 0 | syntax list | endif')) |
| 273 | |
| 274 | syn clear |
| 275 | syn match Fopi /asdf/ |
| 276 | if 0 |
| 277 | syn match Fopx /asdf/ |
| 278 | endif |
| 279 | call assert_match('Fopi', execute('syntax')) |
| 280 | call assert_notmatch('Fopx', execute('syntax')) |
| 281 | |
| 282 | syn clear |
| 283 | syn spell toplevel |
| 284 | call assert_match('spell toplevel', execute('syntax spell')) |
| 285 | if 0 |
| 286 | syn spell notoplevel |
| 287 | endif |
| 288 | call assert_match('spell toplevel', execute('syntax spell')) |
| 289 | syn spell notoplevel |
| 290 | call assert_match('spell notoplevel', execute('syntax spell')) |
| 291 | syn spell default |
| 292 | call assert_match('spell default', execute('syntax spell')) |
| 293 | |
| 294 | syn clear |
| 295 | if 0 |
| 296 | syntax cluster Spell |
| 297 | endif |
| 298 | call assert_notmatch('Spell', execute('syntax')) |
| 299 | |
| 300 | syn clear |
| 301 | syn keyword Foo foo |
| 302 | syn sync ccomment |
| 303 | syn sync maxlines=5 |
| 304 | if 0 |
| 305 | syn sync maxlines=11 |
| 306 | endif |
| 307 | call assert_match('on C-style comments', execute('syntax sync')) |
| 308 | call assert_match('maximal 5 lines', execute('syntax sync')) |
Bram Moolenaar | 58f60ca | 2017-01-17 17:19:00 +0100 | [diff] [blame] | 309 | syn sync clear |
Bram Moolenaar | de318c5 | 2017-01-17 16:27:10 +0100 | [diff] [blame] | 310 | if 0 |
| 311 | syn sync ccomment |
| 312 | endif |
| 313 | call assert_notmatch('on C-style comments', execute('syntax sync')) |
| 314 | |
| 315 | syn clear |
| 316 | endfunc |
| 317 | |
Bram Moolenaar | ea58815 | 2017-04-10 22:45:30 +0200 | [diff] [blame] | 318 | func Test_syntax_invalid_arg() |
Bram Moolenaar | 58f60ca | 2017-01-17 17:19:00 +0100 | [diff] [blame] | 319 | call assert_fails('syntax case asdf', 'E390:') |
Bram Moolenaar | d61e8aa | 2017-01-17 17:44:46 +0100 | [diff] [blame] | 320 | if has('conceal') |
| 321 | call assert_fails('syntax conceal asdf', 'E390:') |
| 322 | endif |
Bram Moolenaar | 58f60ca | 2017-01-17 17:19:00 +0100 | [diff] [blame] | 323 | call assert_fails('syntax spell asdf', 'E390:') |
Bram Moolenaar | ea58815 | 2017-04-10 22:45:30 +0200 | [diff] [blame] | 324 | call assert_fails('syntax clear @ABCD', 'E391:') |
| 325 | call assert_fails('syntax include @Xxx', 'E397:') |
| 326 | call assert_fails('syntax region X start="{"', 'E399:') |
| 327 | call assert_fails('syntax sync x', 'E404:') |
| 328 | call assert_fails('syntax keyword Abc a[', 'E789:') |
| 329 | call assert_fails('syntax keyword Abc a[bc]d', 'E890:') |
Bram Moolenaar | 58f60ca | 2017-01-17 17:19:00 +0100 | [diff] [blame] | 330 | endfunc |
| 331 | |
| 332 | func Test_syn_sync() |
| 333 | syntax region HereGroup start=/this/ end=/that/ |
| 334 | syntax sync match SyncHere grouphere HereGroup "pattern" |
| 335 | call assert_match('SyncHere', execute('syntax sync')) |
| 336 | syn sync clear |
| 337 | call assert_notmatch('SyncHere', execute('syntax sync')) |
| 338 | syn clear |
| 339 | endfunc |
| 340 | |
| 341 | func Test_syn_clear() |
| 342 | syntax keyword Foo foo |
Bram Moolenaar | d61e8aa | 2017-01-17 17:44:46 +0100 | [diff] [blame] | 343 | syntax keyword Bar tar |
Bram Moolenaar | 58f60ca | 2017-01-17 17:19:00 +0100 | [diff] [blame] | 344 | call assert_match('Foo', execute('syntax')) |
Bram Moolenaar | d61e8aa | 2017-01-17 17:44:46 +0100 | [diff] [blame] | 345 | call assert_match('Bar', execute('syntax')) |
Bram Moolenaar | c96272e | 2017-03-26 13:50:09 +0200 | [diff] [blame] | 346 | call assert_equal('Foo', synIDattr(hlID("Foo"), "name")) |
Bram Moolenaar | 58f60ca | 2017-01-17 17:19:00 +0100 | [diff] [blame] | 347 | syn clear Foo |
| 348 | call assert_notmatch('Foo', execute('syntax')) |
Bram Moolenaar | d61e8aa | 2017-01-17 17:44:46 +0100 | [diff] [blame] | 349 | call assert_match('Bar', execute('syntax')) |
Bram Moolenaar | c96272e | 2017-03-26 13:50:09 +0200 | [diff] [blame] | 350 | call assert_equal('Foo', synIDattr(hlID("Foo"), "name")) |
Bram Moolenaar | d61e8aa | 2017-01-17 17:44:46 +0100 | [diff] [blame] | 351 | syn clear Foo Bar |
Bram Moolenaar | 58f60ca | 2017-01-17 17:19:00 +0100 | [diff] [blame] | 352 | call assert_notmatch('Foo', execute('syntax')) |
Bram Moolenaar | d61e8aa | 2017-01-17 17:44:46 +0100 | [diff] [blame] | 353 | call assert_notmatch('Bar', execute('syntax')) |
| 354 | hi clear Foo |
Bram Moolenaar | c96272e | 2017-03-26 13:50:09 +0200 | [diff] [blame] | 355 | call assert_equal('Foo', synIDattr(hlID("Foo"), "name")) |
Bram Moolenaar | d61e8aa | 2017-01-17 17:44:46 +0100 | [diff] [blame] | 356 | hi clear Bar |
Bram Moolenaar | 58f60ca | 2017-01-17 17:19:00 +0100 | [diff] [blame] | 357 | endfunc |
Bram Moolenaar | 4007ed4 | 2017-01-17 18:14:54 +0100 | [diff] [blame] | 358 | |
| 359 | func Test_invalid_name() |
| 360 | syn clear |
| 361 | syn keyword Nop yes |
| 362 | call assert_fails("syntax keyword Wr\x17ong bar", 'E669:') |
| 363 | syntax keyword @Wrong bar |
| 364 | call assert_match('W18:', execute('1messages')) |
| 365 | syn clear |
| 366 | hi clear Nop |
| 367 | hi clear @Wrong |
| 368 | endfunc |
Bram Moolenaar | f8ec998 | 2017-04-09 15:41:31 +0200 | [diff] [blame] | 369 | |
| 370 | func Test_ownsyntax() |
| 371 | new Xfoo |
| 372 | call setline(1, '#define FOO') |
| 373 | syntax on |
| 374 | set filetype=c |
| 375 | ownsyntax perl |
| 376 | call assert_equal('perlComment', synIDattr(synID(line('.'), col('.'), 1), 'name')) |
| 377 | call assert_equal('c', b:current_syntax) |
| 378 | call assert_equal('perl', w:current_syntax) |
| 379 | |
| 380 | " A new split window should have the original syntax. |
| 381 | split |
| 382 | call assert_equal('cDefine', synIDattr(synID(line('.'), col('.'), 1), 'name')) |
| 383 | call assert_equal('c', b:current_syntax) |
| 384 | call assert_equal(0, exists('w:current_syntax')) |
| 385 | |
| 386 | wincmd x |
| 387 | call assert_equal('perlComment', synIDattr(synID(line("."), col("."), 1), "name")) |
| 388 | |
| 389 | syntax off |
| 390 | set filetype& |
| 391 | %bw! |
| 392 | endfunc |
| 393 | |
| 394 | func Test_ownsyntax_completion() |
| 395 | call feedkeys(":ownsyntax java\<C-A>\<C-B>\"\<CR>", 'tx') |
| 396 | call assert_equal('"ownsyntax java javacc javascript', @:) |
| 397 | endfunc |
Bram Moolenaar | ea58815 | 2017-04-10 22:45:30 +0200 | [diff] [blame] | 398 | |
| 399 | func Test_highlight_invalid_arg() |
| 400 | if has('gui_running') |
| 401 | call assert_fails('hi XXX guifg=xxx', 'E254:') |
| 402 | endif |
| 403 | call assert_fails('hi DoesNotExist', 'E411:') |
| 404 | call assert_fails('hi link', 'E412:') |
| 405 | call assert_fails('hi link a', 'E412:') |
| 406 | call assert_fails('hi link a b c', 'E413:') |
| 407 | call assert_fails('hi XXX =', 'E415:') |
| 408 | call assert_fails('hi XXX cterm', 'E416:') |
| 409 | call assert_fails('hi XXX cterm=', 'E417:') |
| 410 | call assert_fails('hi XXX cterm=DoesNotExist', 'E418:') |
| 411 | call assert_fails('hi XXX ctermfg=DoesNotExist', 'E421:') |
| 412 | call assert_fails('hi XXX xxx=White', 'E423:') |
| 413 | endfunc |
| 414 | |
Bram Moolenaar | 1615b36 | 2017-06-04 21:06:09 +0200 | [diff] [blame] | 415 | func Test_bg_detection() |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 416 | CheckNotGui |
| 417 | |
Bram Moolenaar | 1615b36 | 2017-06-04 21:06:09 +0200 | [diff] [blame] | 418 | " auto-detection of &bg, make sure sure it isn't set anywhere before |
| 419 | " this test |
| 420 | hi Normal ctermbg=0 |
| 421 | call assert_equal('dark', &bg) |
| 422 | hi Normal ctermbg=4 |
| 423 | call assert_equal('dark', &bg) |
| 424 | hi Normal ctermbg=12 |
| 425 | call assert_equal('light', &bg) |
| 426 | hi Normal ctermbg=15 |
| 427 | call assert_equal('light', &bg) |
| 428 | |
Bram Moolenaar | 0b2eef2 | 2017-06-27 15:43:49 +0200 | [diff] [blame] | 429 | " manually-set &bg takes precedence over auto-detection |
Bram Moolenaar | 1615b36 | 2017-06-04 21:06:09 +0200 | [diff] [blame] | 430 | set bg=light |
| 431 | hi Normal ctermbg=4 |
| 432 | call assert_equal('light', &bg) |
| 433 | set bg=dark |
| 434 | hi Normal ctermbg=12 |
| 435 | call assert_equal('dark', &bg) |
Bram Moolenaar | 6acadda | 2018-02-24 16:51:32 +0100 | [diff] [blame] | 436 | |
| 437 | hi Normal ctermbg=NONE |
Bram Moolenaar | 1615b36 | 2017-06-04 21:06:09 +0200 | [diff] [blame] | 438 | endfunc |
Bram Moolenaar | 06f1ed2 | 2017-06-18 22:41:03 +0200 | [diff] [blame] | 439 | |
| 440 | func Test_syntax_hangs() |
| 441 | if !has('reltime') || !has('float') || !has('syntax') |
| 442 | return |
| 443 | endif |
| 444 | |
| 445 | " This pattern takes a long time to match, it should timeout. |
| 446 | new |
| 447 | call setline(1, ['aaa', repeat('abc ', 1000), 'ccc']) |
| 448 | let start = reltime() |
| 449 | set nolazyredraw redrawtime=101 |
| 450 | syn match Error /\%#=1a*.*X\@<=b*/ |
| 451 | redraw |
| 452 | let elapsed = reltimefloat(reltime(start)) |
| 453 | call assert_true(elapsed > 0.1) |
| 454 | call assert_true(elapsed < 1.0) |
| 455 | |
| 456 | " second time syntax HL is disabled |
| 457 | let start = reltime() |
| 458 | redraw |
| 459 | let elapsed = reltimefloat(reltime(start)) |
| 460 | call assert_true(elapsed < 0.1) |
| 461 | |
| 462 | " after CTRL-L the timeout flag is reset |
| 463 | let start = reltime() |
| 464 | exe "normal \<C-L>" |
| 465 | redraw |
| 466 | let elapsed = reltimefloat(reltime(start)) |
| 467 | call assert_true(elapsed > 0.1) |
| 468 | call assert_true(elapsed < 1.0) |
| 469 | |
| 470 | set redrawtime& |
| 471 | bwipe! |
| 472 | endfunc |
Bram Moolenaar | 4d78589 | 2017-06-22 22:00:50 +0200 | [diff] [blame] | 473 | |
Bram Moolenaar | 4d78589 | 2017-06-22 22:00:50 +0200 | [diff] [blame] | 474 | func Test_conceal() |
| 475 | if !has('conceal') |
| 476 | return |
| 477 | endif |
| 478 | |
| 479 | new |
| 480 | call setline(1, ['', '123456']) |
| 481 | syn match test23 "23" conceal cchar=X |
| 482 | syn match test45 "45" conceal |
| 483 | |
| 484 | set conceallevel=0 |
| 485 | call assert_equal('123456 ', ScreenLines(2, 7)[0]) |
Bram Moolenaar | cc0750d | 2017-06-24 22:29:24 +0200 | [diff] [blame] | 486 | call assert_equal([[0, '', 0], [0, '', 0], [0, '', 0], [0, '', 0], [0, '', 0], [0, '', 0]], map(range(1, 6), 'synconcealed(2, v:val)')) |
Bram Moolenaar | 4d78589 | 2017-06-22 22:00:50 +0200 | [diff] [blame] | 487 | |
| 488 | set conceallevel=1 |
| 489 | call assert_equal('1X 6 ', ScreenLines(2, 7)[0]) |
Bram Moolenaar | cc0750d | 2017-06-24 22:29:24 +0200 | [diff] [blame] | 490 | call assert_equal([[0, '', 0], [1, 'X', 1], [1, 'X', 1], [1, ' ', 2], [1, ' ', 2], [0, '', 0]], map(range(1, 6), 'synconcealed(2, v:val)')) |
Bram Moolenaar | 4d78589 | 2017-06-22 22:00:50 +0200 | [diff] [blame] | 491 | |
| 492 | set conceallevel=1 |
| 493 | set listchars=conceal:Y |
Bram Moolenaar | cc0750d | 2017-06-24 22:29:24 +0200 | [diff] [blame] | 494 | call assert_equal([[0, '', 0], [1, 'X', 1], [1, 'X', 1], [1, 'Y', 2], [1, 'Y', 2], [0, '', 0]], map(range(1, 6), 'synconcealed(2, v:val)')) |
Bram Moolenaar | 4d78589 | 2017-06-22 22:00:50 +0200 | [diff] [blame] | 495 | call assert_equal('1XY6 ', ScreenLines(2, 7)[0]) |
| 496 | |
| 497 | set conceallevel=2 |
| 498 | call assert_match('1X6 ', ScreenLines(2, 7)[0]) |
Bram Moolenaar | cc0750d | 2017-06-24 22:29:24 +0200 | [diff] [blame] | 499 | call assert_equal([[0, '', 0], [1, 'X', 1], [1, 'X', 1], [1, '', 2], [1, '', 2], [0, '', 0]], map(range(1, 6), 'synconcealed(2, v:val)')) |
Bram Moolenaar | 4d78589 | 2017-06-22 22:00:50 +0200 | [diff] [blame] | 500 | |
| 501 | set conceallevel=3 |
| 502 | call assert_match('16 ', ScreenLines(2, 7)[0]) |
Bram Moolenaar | cc0750d | 2017-06-24 22:29:24 +0200 | [diff] [blame] | 503 | call assert_equal([[0, '', 0], [1, '', 1], [1, '', 1], [1, '', 2], [1, '', 2], [0, '', 0]], map(range(1, 6), 'synconcealed(2, v:val)')) |
Bram Moolenaar | 4d78589 | 2017-06-22 22:00:50 +0200 | [diff] [blame] | 504 | |
| 505 | syn clear |
| 506 | set conceallevel& |
| 507 | bw! |
| 508 | endfunc |
Bram Moolenaar | 0b2eef2 | 2017-06-27 15:43:49 +0200 | [diff] [blame] | 509 | |
Bram Moolenaar | da65058 | 2018-02-20 15:51:40 +0100 | [diff] [blame] | 510 | func Test_synstack_synIDtrans() |
Bram Moolenaar | 0b2eef2 | 2017-06-27 15:43:49 +0200 | [diff] [blame] | 511 | new |
| 512 | setfiletype c |
| 513 | syntax on |
| 514 | call setline(1, ' /* A comment with a TODO */') |
| 515 | |
| 516 | call assert_equal([], synstack(1, 1)) |
| 517 | |
| 518 | norm f/ |
Bram Moolenaar | a74e494 | 2019-08-04 17:35:53 +0200 | [diff] [blame] | 519 | eval synstack(line("."), col("."))->map('synIDattr(v:val, "name")')->assert_equal(['cComment', 'cCommentStart']) |
| 520 | eval synstack(line("."), col("."))->map('synIDattr(synIDtrans(v:val), "name")')->assert_equal(['Comment', 'Comment']) |
Bram Moolenaar | 0b2eef2 | 2017-06-27 15:43:49 +0200 | [diff] [blame] | 521 | |
| 522 | norm fA |
| 523 | call assert_equal(['cComment'], map(synstack(line("."), col(".")), 'synIDattr(v:val, "name")')) |
| 524 | call assert_equal(['Comment'], map(synstack(line("."), col(".")), 'synIDattr(synIDtrans(v:val), "name")')) |
| 525 | |
| 526 | norm fT |
| 527 | call assert_equal(['cComment', 'cTodo'], map(synstack(line("."), col(".")), 'synIDattr(v:val, "name")')) |
| 528 | call assert_equal(['Comment', 'Todo'], map(synstack(line("."), col(".")), 'synIDattr(synIDtrans(v:val), "name")')) |
| 529 | |
| 530 | syn clear |
| 531 | bw! |
| 532 | endfunc |
Bram Moolenaar | da65058 | 2018-02-20 15:51:40 +0100 | [diff] [blame] | 533 | |
| 534 | " Check highlighting for a small piece of C code with a screen dump. |
| 535 | func Test_syntax_c() |
Bram Moolenaar | 6bb2cdf | 2018-02-24 19:53:53 +0100 | [diff] [blame] | 536 | if !CanRunVimInTerminal() |
Bram Moolenaar | 5d30ff1 | 2019-06-06 16:12:12 +0200 | [diff] [blame] | 537 | throw 'Skipped: cannot make screendumps' |
Bram Moolenaar | da65058 | 2018-02-20 15:51:40 +0100 | [diff] [blame] | 538 | endif |
| 539 | call writefile([ |
| 540 | \ '/* comment line at the top */', |
| 541 | \ ' int', |
| 542 | \ 'main(int argc, char **argv)// another comment', |
| 543 | \ '{', |
| 544 | \ '#if 0', |
| 545 | \ ' int not_used;', |
| 546 | \ '#else', |
| 547 | \ ' int used;', |
| 548 | \ '#endif', |
| 549 | \ ' printf("Just an example piece of C code\n");', |
| 550 | \ ' return 0x0ff;', |
| 551 | \ '}', |
| 552 | \ ' static void', |
| 553 | \ 'myFunction(const double count, struct nothing, long there) {', |
| 554 | \ ' // 123: nothing to read here', |
| 555 | \ ' for (int i = 0; i < count; ++i) {', |
| 556 | \ ' break;', |
| 557 | \ ' }', |
| 558 | \ '}', |
| 559 | \ ], 'Xtest.c') |
Bram Moolenaar | b7ea7cb | 2018-02-24 14:38:51 +0100 | [diff] [blame] | 560 | |
| 561 | " This makes the default for 'background' use "dark", check that the |
| 562 | " response to t_RB corrects it to "light". |
| 563 | let $COLORFGBG = '15;0' |
| 564 | |
Bram Moolenaar | da65058 | 2018-02-20 15:51:40 +0100 | [diff] [blame] | 565 | let buf = RunVimInTerminal('Xtest.c', {}) |
Bram Moolenaar | 6bb2cdf | 2018-02-24 19:53:53 +0100 | [diff] [blame] | 566 | call VerifyScreenDump(buf, 'Test_syntax_c_01', {}) |
Bram Moolenaar | da65058 | 2018-02-20 15:51:40 +0100 | [diff] [blame] | 567 | call StopVimInTerminal(buf) |
| 568 | |
Bram Moolenaar | b7ea7cb | 2018-02-24 14:38:51 +0100 | [diff] [blame] | 569 | let $COLORFGBG = '' |
Bram Moolenaar | da65058 | 2018-02-20 15:51:40 +0100 | [diff] [blame] | 570 | call delete('Xtest.c') |
| 571 | endfun |
Bram Moolenaar | bcf9442 | 2018-06-23 14:21:42 +0200 | [diff] [blame] | 572 | |
| 573 | " Using \z() in a region with NFA failing should not crash. |
| 574 | func Test_syn_wrong_z_one() |
| 575 | new |
| 576 | call setline(1, ['just some text', 'with foo and bar to match with']) |
| 577 | syn region FooBar start="foo\z(.*\)bar" end="\z1" |
| 578 | call test_override("nfa_fail", 1) |
| 579 | redraw! |
| 580 | redraw! |
| 581 | call test_override("ALL", 0) |
| 582 | bwipe! |
| 583 | endfunc |
Bram Moolenaar | c7f1e40 | 2019-08-03 13:29:46 +0200 | [diff] [blame] | 584 | |
| 585 | func Test_syntax_after_bufdo() |
| 586 | call writefile(['/* aaa comment */'], 'Xaaa.c') |
| 587 | call writefile(['/* bbb comment */'], 'Xbbb.c') |
| 588 | call writefile(['/* ccc comment */'], 'Xccc.c') |
| 589 | call writefile(['/* ddd comment */'], 'Xddd.c') |
| 590 | |
| 591 | let bnr = bufnr('%') |
| 592 | new Xaaa.c |
| 593 | badd Xbbb.c |
| 594 | badd Xccc.c |
| 595 | badd Xddd.c |
| 596 | exe "bwipe " . bnr |
| 597 | let l = [] |
| 598 | bufdo call add(l, bufnr('%')) |
| 599 | call assert_equal(4, len(l)) |
| 600 | |
| 601 | syntax on |
| 602 | |
| 603 | " This used to only enable syntax HL in the last buffer. |
| 604 | bufdo tab split |
| 605 | tabrewind |
| 606 | for tab in range(1, 4) |
| 607 | norm fm |
| 608 | call assert_equal(['cComment'], map(synstack(line("."), col(".")), 'synIDattr(v:val, "name")')) |
| 609 | tabnext |
| 610 | endfor |
| 611 | |
| 612 | bwipe! Xaaa.c |
| 613 | bwipe! Xbbb.c |
| 614 | bwipe! Xccc.c |
| 615 | bwipe! Xddd.c |
| 616 | syntax off |
| 617 | call delete('Xaaa.c') |
| 618 | call delete('Xbbb.c') |
| 619 | call delete('Xccc.c') |
| 620 | call delete('Xddd.c') |
| 621 | endfunc |