blob: 7f1e5f0e00efed017d30d5f22660a658428360ea [file] [log] [blame]
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01001" Test for syntax and syntax iskeyword option
2
Bram Moolenaarb46fecd2019-06-15 17:58:09 +02003source check.vim
4CheckFeature syntax
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005
Bram Moolenaar4d785892017-06-22 22:00:50 +02006source view_util.vim
Bram Moolenaar6bb2cdf2018-02-24 19:53:53 +01007source screendump.vim
Bram Moolenaar4d785892017-06-22 22:00:50 +02008
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01009func 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
28endfunc
29
Bram Moolenaarb46f57e2020-11-29 14:11:41 +010030func AssertHighlightGroups(lnum, startcol, expected, trans = 1, msg = "")
31 " Assert that the characters starting at a given (line, col)
32 " sequentially match the expected highlight groups.
33 " If groups are provided as a string, each character is assumed to be a
34 " group and spaces represent no group, useful for visually describing tests.
35 let l:expectedGroups = type(a:expected) == v:t_string
36 \ ? a:expected->split('\zs')->map({_, v -> trim(v)})
37 \ : a:expected
38 let l:errors = 0
39 let l:msg = (a:msg->empty() ? "" : a:msg .. ": ")
40 \ .. "Wrong highlight group at " .. a:lnum .. ","
41
42 for l:i in range(a:startcol, a:startcol + l:expectedGroups->len() - 1)
43 let l:errors += synID(a:lnum, l:i, a:trans)
44 \ ->synIDattr("name")
45 \ ->assert_equal(l:expectedGroups[l:i - 1],
46 \ l:msg .. l:i)
47 endfor
48endfunc
49
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010050func Test_syn_iskeyword()
51 new
52 call setline(1, [
53 \ 'CREATE TABLE FOOBAR(',
54 \ ' DLTD_BY VARCHAR2(100)',
55 \ ');',
Bram Moolenaar037c54f2019-04-20 23:47:46 +020056 \ ''])
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010057
58 syntax on
59 set ft=sql
60 syn match SYN /C\k\+\>/
61 hi link SYN ErrorMsg
62 call assert_equal('DLTD_BY', GetSyntaxItem('DLTD'))
63 /\<D\k\+\>/:norm! ygn
64 call assert_equal('DLTD_BY', @0)
65 redir @c
66 syn iskeyword
67 redir END
68 call assert_equal("\nsyntax iskeyword not set", @c)
69
70 syn iskeyword @,48-57,_,192-255
71 redir @c
72 syn iskeyword
73 redir END
74 call assert_equal("\nsyntax iskeyword @,48-57,_,192-255", @c)
75
76 setlocal isk-=_
77 call assert_equal('DLTD_BY', GetSyntaxItem('DLTD'))
78 /\<D\k\+\>/:norm! ygn
Bram Moolenaar73b484c2016-12-11 15:11:17 +010079 let b2 = @0
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010080 call assert_equal('DLTD', @0)
81
82 syn iskeyword clear
83 redir @c
84 syn iskeyword
85 redir END
86 call assert_equal("\nsyntax iskeyword not set", @c)
87
88 quit!
89endfunc
Bram Moolenaarc3691332016-04-20 12:49:49 +020090
91func Test_syntax_after_reload()
92 split Xsomefile
93 call setline(1, ['hello', 'there'])
94 w!
95 only!
96 setl filetype=hello
97 au FileType hello let g:gotit = 1
98 call assert_false(exists('g:gotit'))
99 edit other
100 buf Xsomefile
101 call assert_equal('hello', &filetype)
102 call assert_true(exists('g:gotit'))
103 call delete('Xsomefile')
104endfunc
Bram Moolenaar73b484c2016-12-11 15:11:17 +0100105
106func Test_syntime()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200107 CheckFeature profile
Bram Moolenaar73b484c2016-12-11 15:11:17 +0100108
109 syntax on
110 syntime on
111 let a = execute('syntime report')
112 call assert_equal("\nNo Syntax items defined for this buffer", a)
113
Dominique Pelle6d37e8e2021-05-06 17:36:55 +0200114 let a = execute('syntime clear')
115 call assert_equal("\nNo Syntax items defined for this buffer", a)
116
Bram Moolenaar73b484c2016-12-11 15:11:17 +0100117 view ../memfile_test.c
118 setfiletype cpp
119 redraw
120 let a = execute('syntime report')
121 call assert_match('^ TOTAL *COUNT *MATCH *SLOWEST *AVERAGE *NAME *PATTERN', a)
122 call assert_match(' \d*\.\d* \+[^0]\d* .* cppRawString ', a)
123 call assert_match(' \d*\.\d* \+[^0]\d* .* cppNumber ', a)
124
125 syntime off
126 syntime clear
127 let a = execute('syntime report')
128 call assert_match('^ TOTAL *COUNT *MATCH *SLOWEST *AVERAGE *NAME *PATTERN', a)
129 call assert_notmatch('.* cppRawString *', a)
130 call assert_notmatch('.* cppNumber*', a)
131 call assert_notmatch('[1-9]', a)
132
Bram Moolenaare2e40752020-09-04 21:18:46 +0200133 call assert_fails('syntime abc', 'E475:')
Bram Moolenaar73b484c2016-12-11 15:11:17 +0100134
135 syntax clear
136 let a = execute('syntime report')
137 call assert_equal("\nNo Syntax items defined for this buffer", a)
138
139 bd
140endfunc
141
Bram Moolenaarb513d302018-12-02 14:55:08 +0100142func Test_syntime_completion()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200143 CheckFeature profile
Bram Moolenaarb513d302018-12-02 14:55:08 +0100144
145 call feedkeys(":syntime \<C-A>\<C-B>\"\<CR>", 'tx')
146 call assert_equal('"syntime clear off on report', @:)
147endfunc
148
Bram Moolenaar73b484c2016-12-11 15:11:17 +0100149func Test_syntax_list()
150 syntax on
151 let a = execute('syntax list')
152 call assert_equal("\nNo Syntax items defined for this buffer", a)
153
154 view ../memfile_test.c
155 setfiletype c
156
157 let a = execute('syntax list')
158 call assert_match('cInclude*', a)
159 call assert_match('cDefine', a)
160
161 let a = execute('syntax list cDefine')
162 call assert_notmatch('cInclude*', a)
163 call assert_match('cDefine', a)
164 call assert_match(' links to Macro$', a)
165
166 call assert_fails('syntax list ABCD', 'E28:')
167 call assert_fails('syntax list @ABCD', 'E392:')
168
169 syntax clear
170 let a = execute('syntax list')
171 call assert_equal("\nNo Syntax items defined for this buffer", a)
172
Bram Moolenaar08f41572020-04-20 16:50:00 +0200173 syntax keyword Type int containedin=g1 skipwhite skipempty skipnl nextgroup=Abc
174 let exp = "Type xxx containedin=g1 nextgroup=Abc skipnl skipwhite skipempty int"
175 call assert_equal(exp, split(execute("syntax list"), "\n")[1])
176
Bram Moolenaar73b484c2016-12-11 15:11:17 +0100177 bd
178endfunc
179
180func Test_syntax_completion()
181 call feedkeys(":syn \<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaare35a52a2020-05-31 19:48:53 +0200182 call assert_equal('"syn case clear cluster conceal enable foldlevel include iskeyword keyword list manual match off on region reset spell sync', @:)
Bram Moolenaar73b484c2016-12-11 15:11:17 +0100183
184 call feedkeys(":syn case \<C-A>\<C-B>\"\<CR>", 'tx')
185 call assert_equal('"syn case ignore match', @:)
186
Bram Moolenaar2d028392017-01-08 18:28:22 +0100187 call feedkeys(":syn spell \<C-A>\<C-B>\"\<CR>", 'tx')
188 call assert_equal('"syn spell default notoplevel toplevel', @:)
189
190 call feedkeys(":syn sync \<C-A>\<C-B>\"\<CR>", 'tx')
191 call assert_equal('"syn sync ccomment clear fromstart linebreaks= linecont lines= match maxlines= minlines= region', @:)
192
Bram Moolenaard61e8aa2017-01-17 17:44:46 +0100193 " Check that clearing "Aap" avoids it showing up before Boolean.
194 hi Aap ctermfg=blue
195 call feedkeys(":syn list \<C-A>\<C-B>\"\<CR>", 'tx')
196 call assert_match('^"syn list Aap Boolean Character ', @:)
197 hi clear Aap
198
Bram Moolenaar73b484c2016-12-11 15:11:17 +0100199 call feedkeys(":syn list \<C-A>\<C-B>\"\<CR>", 'tx')
200 call assert_match('^"syn list Boolean Character ', @:)
201
202 call feedkeys(":syn match \<C-A>\<C-B>\"\<CR>", 'tx')
203 call assert_match('^"syn match Boolean Character ', @:)
bfredlaf9a6002022-08-26 21:58:31 +0100204
205 syn cluster Aax contains=Aap
206 call feedkeys(":syn list @A\<C-A>\<C-B>\"\<CR>", 'tx')
207 call assert_match('^"syn list @Aax', @:)
Bram Moolenaar73b484c2016-12-11 15:11:17 +0100208endfunc
Bram Moolenaarde318c52017-01-17 16:27:10 +0100209
Bram Moolenaar297610b2019-12-27 17:20:55 +0100210func Test_echohl_completion()
211 call feedkeys(":echohl no\<C-A>\<C-B>\"\<CR>", 'tx')
212 call assert_equal('"echohl NonText Normal none', @:)
213endfunc
214
Bram Moolenaarde318c52017-01-17 16:27:10 +0100215func Test_syntax_arg_skipped()
216 syn clear
217 syntax case ignore
218 if 0
219 syntax case match
220 endif
221 call assert_match('case ignore', execute('syntax case'))
222
223 syn keyword Foo foo
224 call assert_match('Foo', execute('syntax'))
225 syn clear
226 call assert_match('case match', execute('syntax case'))
227 call assert_notmatch('Foo', execute('syntax'))
228
229 if has('conceal')
230 syn clear
231 syntax conceal on
232 if 0
233 syntax conceal off
234 endif
235 call assert_match('conceal on', execute('syntax conceal'))
236 syn clear
237 call assert_match('conceal off', execute('syntax conceal'))
Bram Moolenaar58f60ca2017-01-17 17:19:00 +0100238
239 syntax conceal on
240 syntax conceal off
241 call assert_match('conceal off', execute('syntax conceal'))
Bram Moolenaarde318c52017-01-17 16:27:10 +0100242 endif
243
Bram Moolenaard61e8aa2017-01-17 17:44:46 +0100244 syntax region Bar start=/</ end=/>/
Bram Moolenaarde318c52017-01-17 16:27:10 +0100245 if 0
246 syntax region NotTest start=/</ end=/>/ contains=@Spell
247 endif
Bram Moolenaard61e8aa2017-01-17 17:44:46 +0100248 call assert_match('Bar', execute('syntax'))
Bram Moolenaarde318c52017-01-17 16:27:10 +0100249 call assert_notmatch('NotTest', execute('syntax'))
250 call assert_notmatch('Spell', execute('syntax'))
251
252 hi Foo ctermfg=blue
253 let a = execute('hi Foo')
254 if 0
255 syntax rest
256 endif
257 call assert_equal(a, execute('hi Foo'))
Bram Moolenaard61e8aa2017-01-17 17:44:46 +0100258 hi clear Bar
259 hi clear Foo
Bram Moolenaarde318c52017-01-17 16:27:10 +0100260
261 set ft=tags
262 syn off
263 if 0
264 syntax enable
265 endif
266 call assert_match('No Syntax items defined', execute('syntax'))
267 syntax enable
268 call assert_match('tagComment', execute('syntax'))
269 set ft=
270
271 syn clear
272 if 0
273 syntax include @Spell nothing
274 endif
275 call assert_notmatch('Spell', execute('syntax'))
276
277 syn clear
278 syn iskeyword 48-57,$,_
279 call assert_match('48-57,$,_', execute('syntax iskeyword'))
280 if 0
281 syn clear
282 syn iskeyword clear
283 endif
284 call assert_match('48-57,$,_', execute('syntax iskeyword'))
285 syn iskeyword clear
286 call assert_match('not set', execute('syntax iskeyword'))
287 syn iskeyword 48-57,$,_
288 syn clear
289 call assert_match('not set', execute('syntax iskeyword'))
290
291 syn clear
292 syn keyword Foo foo
293 if 0
294 syn keyword NotAdded bar
295 endif
296 call assert_match('Foo', execute('syntax'))
297 call assert_notmatch('NotAdded', execute('highlight'))
298
299 syn clear
300 syn keyword Foo foo
301 call assert_match('Foo', execute('syntax'))
302 call assert_match('Foo', execute('syntax list'))
303 call assert_notmatch('Foo', execute('if 0 | syntax | endif'))
304 call assert_notmatch('Foo', execute('if 0 | syntax list | endif'))
305
306 syn clear
307 syn match Fopi /asdf/
308 if 0
309 syn match Fopx /asdf/
310 endif
311 call assert_match('Fopi', execute('syntax'))
312 call assert_notmatch('Fopx', execute('syntax'))
313
314 syn clear
315 syn spell toplevel
316 call assert_match('spell toplevel', execute('syntax spell'))
317 if 0
318 syn spell notoplevel
319 endif
320 call assert_match('spell toplevel', execute('syntax spell'))
321 syn spell notoplevel
322 call assert_match('spell notoplevel', execute('syntax spell'))
323 syn spell default
324 call assert_match('spell default', execute('syntax spell'))
325
326 syn clear
327 if 0
328 syntax cluster Spell
329 endif
330 call assert_notmatch('Spell', execute('syntax'))
331
332 syn clear
333 syn keyword Foo foo
334 syn sync ccomment
335 syn sync maxlines=5
336 if 0
337 syn sync maxlines=11
338 endif
339 call assert_match('on C-style comments', execute('syntax sync'))
340 call assert_match('maximal 5 lines', execute('syntax sync'))
Bram Moolenaar58f60ca2017-01-17 17:19:00 +0100341 syn sync clear
Bram Moolenaarde318c52017-01-17 16:27:10 +0100342 if 0
343 syn sync ccomment
344 endif
345 call assert_notmatch('on C-style comments', execute('syntax sync'))
Bram Moolenaar99502802020-11-18 16:53:23 +0100346 syn sync fromstart
347 call assert_match('syncing starts at the first line', execute('syntax sync'))
Bram Moolenaarde318c52017-01-17 16:27:10 +0100348
349 syn clear
350endfunc
351
Bram Moolenaarfbf21222020-04-19 18:31:25 +0200352" Check for an error. Used when multiple errors are thrown and we are checking
353" for an earliest error.
354func AssertFails(cmd, errcode)
355 let save_exception = ''
356 try
357 exe a:cmd
358 catch
359 let save_exception = v:exception
360 endtry
361 call assert_match(a:errcode, save_exception)
362endfunc
363
Bram Moolenaarea588152017-04-10 22:45:30 +0200364func Test_syntax_invalid_arg()
Bram Moolenaar58f60ca2017-01-17 17:19:00 +0100365 call assert_fails('syntax case asdf', 'E390:')
Bram Moolenaard61e8aa2017-01-17 17:44:46 +0100366 if has('conceal')
367 call assert_fails('syntax conceal asdf', 'E390:')
368 endif
Bram Moolenaar58f60ca2017-01-17 17:19:00 +0100369 call assert_fails('syntax spell asdf', 'E390:')
Bram Moolenaarea588152017-04-10 22:45:30 +0200370 call assert_fails('syntax clear @ABCD', 'E391:')
Bram Moolenaarfbf21222020-04-19 18:31:25 +0200371 call assert_fails('syntax include random_file', 'E484:')
372 call assert_fails('syntax include <afile>', 'E495:')
Bram Moolenaarea588152017-04-10 22:45:30 +0200373 call assert_fails('syntax sync x', 'E404:')
374 call assert_fails('syntax keyword Abc a[', 'E789:')
375 call assert_fails('syntax keyword Abc a[bc]d', 'E890:')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +0200376 call assert_fails('syntax cluster Abc add=A add=', 'E406:')
Bram Moolenaar476a6132020-04-08 19:48:56 +0200377
378 " Test for too many \z\( and unmatched \z\(
379 " Not able to use assert_fails() here because both E50:/E879: and E475:
380 " messages are emitted.
381 set regexpengine=1
Bram Moolenaarfbf21222020-04-19 18:31:25 +0200382 call AssertFails("syntax region MyRegion start='\\z\\(' end='\\*/'", 'E52:')
Bram Moolenaar476a6132020-04-08 19:48:56 +0200383
Bram Moolenaarfbf21222020-04-19 18:31:25 +0200384 let cmd = "syntax region MyRegion start='"
385 let cmd ..= repeat("\\z\\(.\\)", 10) .. "' end='\*/'"
386 call AssertFails(cmd, 'E50:')
Bram Moolenaar476a6132020-04-08 19:48:56 +0200387
388 set regexpengine=2
Bram Moolenaarfbf21222020-04-19 18:31:25 +0200389 call AssertFails("syntax region MyRegion start='\\z\\(' end='\\*/'", 'E54:')
Bram Moolenaar476a6132020-04-08 19:48:56 +0200390
Bram Moolenaarfbf21222020-04-19 18:31:25 +0200391 let cmd = "syntax region MyRegion start='"
392 let cmd ..= repeat("\\z\\(.\\)", 10) .. "' end='\*/'"
393 call AssertFails(cmd, 'E879:')
Bram Moolenaar476a6132020-04-08 19:48:56 +0200394 set regexpengine&
Bram Moolenaarfbf21222020-04-19 18:31:25 +0200395
396 call AssertFails('syntax keyword cMyItem grouphere G1', 'E393:')
397 call AssertFails('syntax sync match Abc grouphere MyItem "abc"', 'E394:')
398 call AssertFails('syn keyword Type contains int', 'E395:')
399 call assert_fails('syntax include @Xxx', 'E397:')
400 call AssertFails('syntax region X start', 'E398:')
401 call assert_fails('syntax region X start="{"', 'E399:')
402 call AssertFails('syntax cluster contains=Abc', 'E400:')
403 call AssertFails("syntax match Character /'.'", 'E401:')
404 call AssertFails("syntax match Character /'.'/a", 'E402:')
Bram Moolenaar531be472020-09-23 22:38:05 +0200405 call assert_fails('syntax sync linecont /\%(/', 'E53:')
Bram Moolenaarfbf21222020-04-19 18:31:25 +0200406 call assert_fails('syntax sync linecont /pat', 'E404:')
407 call assert_fails('syntax sync linecont', 'E404:')
408 call assert_fails('syntax sync linecont /pat1/ linecont /pat2/', 'E403:')
409 call assert_fails('syntax sync minlines=a', 'E404:')
410 call AssertFails('syntax match ABC /x/ contains=', 'E406:')
411 call AssertFails("syntax match Character contains /'.'/", 'E405:')
412 call AssertFails('syntax match ccFoo "Foo" nextgroup=ALLBUT,F', 'E407:')
413 call AssertFails('syntax region Block start="{" contains=F,ALLBUT', 'E408:')
414 call AssertFails("syntax match Characters contains=a.*x /'.'/", 'E409:')
Bram Moolenaar531be472020-09-23 22:38:05 +0200415 call assert_fails('syntax match Search /abc/ contains=ALLBUT,/\%(/', 'E53:')
Bram Moolenaar58f60ca2017-01-17 17:19:00 +0100416endfunc
417
418func Test_syn_sync()
419 syntax region HereGroup start=/this/ end=/that/
420 syntax sync match SyncHere grouphere HereGroup "pattern"
421 call assert_match('SyncHere', execute('syntax sync'))
422 syn sync clear
423 call assert_notmatch('SyncHere', execute('syntax sync'))
424 syn clear
425endfunc
426
427func Test_syn_clear()
428 syntax keyword Foo foo
Bram Moolenaard61e8aa2017-01-17 17:44:46 +0100429 syntax keyword Bar tar
Bram Moolenaar58f60ca2017-01-17 17:19:00 +0100430 call assert_match('Foo', execute('syntax'))
Bram Moolenaard61e8aa2017-01-17 17:44:46 +0100431 call assert_match('Bar', execute('syntax'))
Bram Moolenaarc96272e2017-03-26 13:50:09 +0200432 call assert_equal('Foo', synIDattr(hlID("Foo"), "name"))
Bram Moolenaar58f60ca2017-01-17 17:19:00 +0100433 syn clear Foo
434 call assert_notmatch('Foo', execute('syntax'))
Bram Moolenaard61e8aa2017-01-17 17:44:46 +0100435 call assert_match('Bar', execute('syntax'))
Bram Moolenaarc96272e2017-03-26 13:50:09 +0200436 call assert_equal('Foo', synIDattr(hlID("Foo"), "name"))
Bram Moolenaard61e8aa2017-01-17 17:44:46 +0100437 syn clear Foo Bar
Bram Moolenaar58f60ca2017-01-17 17:19:00 +0100438 call assert_notmatch('Foo', execute('syntax'))
Bram Moolenaard61e8aa2017-01-17 17:44:46 +0100439 call assert_notmatch('Bar', execute('syntax'))
440 hi clear Foo
Bram Moolenaarc96272e2017-03-26 13:50:09 +0200441 call assert_equal('Foo', synIDattr(hlID("Foo"), "name"))
Bram Moolenaard61e8aa2017-01-17 17:44:46 +0100442 hi clear Bar
Bram Moolenaarfbf21222020-04-19 18:31:25 +0200443 call assert_fails('syntax clear invalid_syngroup', 'E28:')
Bram Moolenaar58f60ca2017-01-17 17:19:00 +0100444endfunc
Bram Moolenaar4007ed42017-01-17 18:14:54 +0100445
446func Test_invalid_name()
447 syn clear
448 syn keyword Nop yes
449 call assert_fails("syntax keyword Wr\x17ong bar", 'E669:')
450 syntax keyword @Wrong bar
451 call assert_match('W18:', execute('1messages'))
452 syn clear
453 hi clear Nop
454 hi clear @Wrong
455endfunc
Bram Moolenaarf8ec9982017-04-09 15:41:31 +0200456
457func Test_ownsyntax()
458 new Xfoo
459 call setline(1, '#define FOO')
460 syntax on
461 set filetype=c
Bram Moolenaard1f76af2020-09-13 22:37:34 +0200462
Bram Moolenaarf8ec9982017-04-09 15:41:31 +0200463 ownsyntax perl
Bram Moolenaard1f76af2020-09-13 22:37:34 +0200464 " this should not crash
465 set
466
Bram Moolenaarf8ec9982017-04-09 15:41:31 +0200467 call assert_equal('perlComment', synIDattr(synID(line('.'), col('.'), 1), 'name'))
468 call assert_equal('c', b:current_syntax)
469 call assert_equal('perl', w:current_syntax)
470
471 " A new split window should have the original syntax.
472 split
473 call assert_equal('cDefine', synIDattr(synID(line('.'), col('.'), 1), 'name'))
474 call assert_equal('c', b:current_syntax)
475 call assert_equal(0, exists('w:current_syntax'))
476
477 wincmd x
478 call assert_equal('perlComment', synIDattr(synID(line("."), col("."), 1), "name"))
479
480 syntax off
481 set filetype&
482 %bw!
483endfunc
484
485func Test_ownsyntax_completion()
486 call feedkeys(":ownsyntax java\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarea7a08a2019-08-26 22:38:22 +0200487 call assert_equal('"ownsyntax java javacc javascript javascriptreact', @:)
Bram Moolenaarf8ec9982017-04-09 15:41:31 +0200488endfunc
Bram Moolenaarea588152017-04-10 22:45:30 +0200489
490func Test_highlight_invalid_arg()
491 if has('gui_running')
492 call assert_fails('hi XXX guifg=xxx', 'E254:')
493 endif
494 call assert_fails('hi DoesNotExist', 'E411:')
495 call assert_fails('hi link', 'E412:')
496 call assert_fails('hi link a', 'E412:')
497 call assert_fails('hi link a b c', 'E413:')
498 call assert_fails('hi XXX =', 'E415:')
499 call assert_fails('hi XXX cterm', 'E416:')
500 call assert_fails('hi XXX cterm=', 'E417:')
501 call assert_fails('hi XXX cterm=DoesNotExist', 'E418:')
502 call assert_fails('hi XXX ctermfg=DoesNotExist', 'E421:')
503 call assert_fails('hi XXX xxx=White', 'E423:')
504endfunc
505
Bram Moolenaar1615b362017-06-04 21:06:09 +0200506func Test_bg_detection()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200507 CheckNotGui
508
Dominique Pelle923dce22021-11-21 11:36:04 +0000509 " auto-detection of &bg, make sure it isn't set anywhere before this test
Bram Moolenaar1615b362017-06-04 21:06:09 +0200510 hi Normal ctermbg=0
511 call assert_equal('dark', &bg)
512 hi Normal ctermbg=4
513 call assert_equal('dark', &bg)
514 hi Normal ctermbg=12
515 call assert_equal('light', &bg)
516 hi Normal ctermbg=15
517 call assert_equal('light', &bg)
518
Bram Moolenaar0b2eef22017-06-27 15:43:49 +0200519 " manually-set &bg takes precedence over auto-detection
Bram Moolenaar1615b362017-06-04 21:06:09 +0200520 set bg=light
521 hi Normal ctermbg=4
522 call assert_equal('light', &bg)
523 set bg=dark
524 hi Normal ctermbg=12
525 call assert_equal('dark', &bg)
Bram Moolenaar6acadda2018-02-24 16:51:32 +0100526
527 hi Normal ctermbg=NONE
Bram Moolenaar1615b362017-06-04 21:06:09 +0200528endfunc
Bram Moolenaar06f1ed22017-06-18 22:41:03 +0200529
530func Test_syntax_hangs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200531 CheckFunction reltimefloat
532 CheckFeature syntax
Bram Moolenaar06f1ed22017-06-18 22:41:03 +0200533
Paul Ollis65745772022-06-05 16:55:54 +0100534 " So, it turns out the Windows 7 implements TimerQueue timers differently
535 " and they can expire *before* the requested time has elapsed. So allow for
536 " the timeout occurring after 80 ms (5 * 16 (the typical clock tick)).
537 if has("win32")
538 let min_timeout = 0.08
539 else
540 let min_timeout = 0.1
541 endif
542
Bram Moolenaar06f1ed22017-06-18 22:41:03 +0200543 " This pattern takes a long time to match, it should timeout.
544 new
545 call setline(1, ['aaa', repeat('abc ', 1000), 'ccc'])
546 let start = reltime()
547 set nolazyredraw redrawtime=101
548 syn match Error /\%#=1a*.*X\@<=b*/
549 redraw
550 let elapsed = reltimefloat(reltime(start))
Bram Moolenaar620aa8e2022-06-18 16:05:32 +0100551 call assert_inrange(min_timeout, 1.0, elapsed)
Bram Moolenaar06f1ed22017-06-18 22:41:03 +0200552
553 " second time syntax HL is disabled
554 let start = reltime()
555 redraw
556 let elapsed = reltimefloat(reltime(start))
Bram Moolenaar620aa8e2022-06-18 16:05:32 +0100557 call assert_inrange(0, 0.1, elapsed)
Bram Moolenaar06f1ed22017-06-18 22:41:03 +0200558
559 " after CTRL-L the timeout flag is reset
560 let start = reltime()
561 exe "normal \<C-L>"
562 redraw
563 let elapsed = reltimefloat(reltime(start))
Bram Moolenaar620aa8e2022-06-18 16:05:32 +0100564 call assert_inrange(min_timeout, 1.0, elapsed)
Bram Moolenaar06f1ed22017-06-18 22:41:03 +0200565
566 set redrawtime&
567 bwipe!
568endfunc
Bram Moolenaar4d785892017-06-22 22:00:50 +0200569
Bram Moolenaar4d785892017-06-22 22:00:50 +0200570func Test_conceal()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200571 CheckFeature conceal
Bram Moolenaar4d785892017-06-22 22:00:50 +0200572
573 new
574 call setline(1, ['', '123456'])
575 syn match test23 "23" conceal cchar=X
576 syn match test45 "45" conceal
577
578 set conceallevel=0
579 call assert_equal('123456 ', ScreenLines(2, 7)[0])
Bram Moolenaarcc0750d2017-06-24 22:29:24 +0200580 call assert_equal([[0, '', 0], [0, '', 0], [0, '', 0], [0, '', 0], [0, '', 0], [0, '', 0]], map(range(1, 6), 'synconcealed(2, v:val)'))
Bram Moolenaar4d785892017-06-22 22:00:50 +0200581
582 set conceallevel=1
583 call assert_equal('1X 6 ', ScreenLines(2, 7)[0])
Bram Moolenaarcc0750d2017-06-24 22:29:24 +0200584 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 Moolenaar4d785892017-06-22 22:00:50 +0200585
586 set conceallevel=1
587 set listchars=conceal:Y
Bram Moolenaarcc0750d2017-06-24 22:29:24 +0200588 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 Moolenaar4d785892017-06-22 22:00:50 +0200589 call assert_equal('1XY6 ', ScreenLines(2, 7)[0])
590
591 set conceallevel=2
592 call assert_match('1X6 ', ScreenLines(2, 7)[0])
Bram Moolenaarcc0750d2017-06-24 22:29:24 +0200593 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 Moolenaar4d785892017-06-22 22:00:50 +0200594
595 set conceallevel=3
596 call assert_match('16 ', ScreenLines(2, 7)[0])
Bram Moolenaarcc0750d2017-06-24 22:29:24 +0200597 call assert_equal([[0, '', 0], [1, '', 1], [1, '', 1], [1, '', 2], [1, '', 2], [0, '', 0]], map(range(1, 6), 'synconcealed(2, v:val)'))
Bram Moolenaar4d785892017-06-22 22:00:50 +0200598
Bram Moolenaarfbf21222020-04-19 18:31:25 +0200599 call AssertFails("syntax match Entity '&amp;' conceal cchar=\<Tab>", 'E844:')
600
Bram Moolenaar4d785892017-06-22 22:00:50 +0200601 syn clear
602 set conceallevel&
603 bw!
604endfunc
Bram Moolenaar0b2eef22017-06-27 15:43:49 +0200605
Bram Moolenaarda650582018-02-20 15:51:40 +0100606func Test_synstack_synIDtrans()
Bram Moolenaar0b2eef22017-06-27 15:43:49 +0200607 new
608 setfiletype c
609 syntax on
610 call setline(1, ' /* A comment with a TODO */')
611
612 call assert_equal([], synstack(1, 1))
613
614 norm f/
Bram Moolenaara74e4942019-08-04 17:35:53 +0200615 eval synstack(line("."), col("."))->map('synIDattr(v:val, "name")')->assert_equal(['cComment', 'cCommentStart'])
616 eval synstack(line("."), col("."))->map('synIDattr(synIDtrans(v:val), "name")')->assert_equal(['Comment', 'Comment'])
Bram Moolenaar0b2eef22017-06-27 15:43:49 +0200617
618 norm fA
619 call assert_equal(['cComment'], map(synstack(line("."), col(".")), 'synIDattr(v:val, "name")'))
620 call assert_equal(['Comment'], map(synstack(line("."), col(".")), 'synIDattr(synIDtrans(v:val), "name")'))
621
622 norm fT
623 call assert_equal(['cComment', 'cTodo'], map(synstack(line("."), col(".")), 'synIDattr(v:val, "name")'))
624 call assert_equal(['Comment', 'Todo'], map(synstack(line("."), col(".")), 'synIDattr(synIDtrans(v:val), "name")'))
625
Bram Moolenaar0e05de42020-03-25 22:23:46 +0100626 call assert_fails("let n=synIDtrans([])", 'E745:')
627
Bram Moolenaar0b2eef22017-06-27 15:43:49 +0200628 syn clear
629 bw!
630endfunc
Bram Moolenaarda650582018-02-20 15:51:40 +0100631
632" Check highlighting for a small piece of C code with a screen dump.
633func Test_syntax_c()
Bram Moolenaar494e9062020-05-31 21:28:02 +0200634 CheckRunVimInTerminal
Bram Moolenaarda650582018-02-20 15:51:40 +0100635 call writefile([
636 \ '/* comment line at the top */',
Bram Moolenaar83e9a1c2019-10-20 14:51:23 +0200637 \ 'int main(int argc, char **argv) { // another comment',
Bram Moolenaarda650582018-02-20 15:51:40 +0100638 \ '#if 0',
639 \ ' int not_used;',
640 \ '#else',
641 \ ' int used;',
642 \ '#endif',
643 \ ' printf("Just an example piece of C code\n");',
644 \ ' return 0x0ff;',
645 \ '}',
Bram Moolenaar82260af2019-10-20 13:16:22 +0200646 \ "\t\t ",
Bram Moolenaarda650582018-02-20 15:51:40 +0100647 \ ' static void',
648 \ 'myFunction(const double count, struct nothing, long there) {',
Bram Moolenaar84590062019-10-18 23:12:20 +0200649 \ "\t// 123: nothing to endif here",
Bram Moolenaar9115c612019-10-16 16:57:06 +0200650 \ "\tfor (int i = 0; i < count; ++i) {",
651 \ "\t break;",
652 \ "\t}",
Bram Moolenaarbbfd1562019-10-19 20:38:15 +0200653 \ "\tNote: asdf",
Bram Moolenaarda650582018-02-20 15:51:40 +0100654 \ '}',
655 \ ], 'Xtest.c')
Paul Ollis65745772022-06-05 16:55:54 +0100656
Bram Moolenaarb7ea7cb2018-02-24 14:38:51 +0100657 " This makes the default for 'background' use "dark", check that the
658 " response to t_RB corrects it to "light".
659 let $COLORFGBG = '15;0'
660
Bram Moolenaar83e9a1c2019-10-20 14:51:23 +0200661 let buf = RunVimInTerminal('Xtest.c', {})
Bram Moolenaarbbfd1562019-10-19 20:38:15 +0200662 call term_sendkeys(buf, ":syn keyword Search Note\r")
Bram Moolenaar82260af2019-10-20 13:16:22 +0200663 call term_sendkeys(buf, ":syn match Error /^\\s\\+$/\r")
Bram Moolenaar84590062019-10-18 23:12:20 +0200664 call term_sendkeys(buf, ":set hlsearch\r")
665 call term_sendkeys(buf, "/endif\r")
666 call term_sendkeys(buf, "vjfC")
Bram Moolenaar6bb2cdf2018-02-24 19:53:53 +0100667 call VerifyScreenDump(buf, 'Test_syntax_c_01', {})
Bram Moolenaar84590062019-10-18 23:12:20 +0200668
669 call term_sendkeys(buf, "\<Esc>")
Bram Moolenaarda650582018-02-20 15:51:40 +0100670 call StopVimInTerminal(buf)
671
Bram Moolenaarb7ea7cb2018-02-24 14:38:51 +0100672 let $COLORFGBG = ''
Bram Moolenaarda650582018-02-20 15:51:40 +0100673 call delete('Xtest.c')
674endfun
Bram Moolenaarbcf94422018-06-23 14:21:42 +0200675
Dominique Pelle354b23a2021-12-17 17:32:29 +0000676" Test \z(...) along with \z1
677func Test_syn_zsub()
678 new
679 syntax on
680 call setline(1, 'xxx start foo xxx not end foo xxx end foo xxx')
681 let l:expected = ' ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ '
682
683 for l:re in [0, 1, 2]
684 " Example taken from :help :syn-ext-match
685 syntax region Z start="start \z(\I\i*\)" skip="not end \z1" end="end \z1"
686 eval AssertHighlightGroups(1, 1, l:expected, 1, 'regexp=' .. l:re)
687 syntax clear Z
688 endfor
689
690 set re&
691 bw!
692endfunc
693
Bram Moolenaarbcf94422018-06-23 14:21:42 +0200694" Using \z() in a region with NFA failing should not crash.
695func Test_syn_wrong_z_one()
696 new
697 call setline(1, ['just some text', 'with foo and bar to match with'])
698 syn region FooBar start="foo\z(.*\)bar" end="\z1"
699 call test_override("nfa_fail", 1)
700 redraw!
701 redraw!
702 call test_override("ALL", 0)
703 bwipe!
704endfunc
Bram Moolenaarc7f1e402019-08-03 13:29:46 +0200705
706func Test_syntax_after_bufdo()
707 call writefile(['/* aaa comment */'], 'Xaaa.c')
708 call writefile(['/* bbb comment */'], 'Xbbb.c')
709 call writefile(['/* ccc comment */'], 'Xccc.c')
710 call writefile(['/* ddd comment */'], 'Xddd.c')
711
712 let bnr = bufnr('%')
713 new Xaaa.c
714 badd Xbbb.c
715 badd Xccc.c
716 badd Xddd.c
717 exe "bwipe " . bnr
718 let l = []
719 bufdo call add(l, bufnr('%'))
720 call assert_equal(4, len(l))
721
722 syntax on
723
724 " This used to only enable syntax HL in the last buffer.
725 bufdo tab split
726 tabrewind
727 for tab in range(1, 4)
728 norm fm
729 call assert_equal(['cComment'], map(synstack(line("."), col(".")), 'synIDattr(v:val, "name")'))
730 tabnext
731 endfor
732
733 bwipe! Xaaa.c
734 bwipe! Xbbb.c
735 bwipe! Xccc.c
736 bwipe! Xddd.c
737 syntax off
738 call delete('Xaaa.c')
739 call delete('Xbbb.c')
740 call delete('Xccc.c')
741 call delete('Xddd.c')
742endfunc
Bram Moolenaar0e05de42020-03-25 22:23:46 +0100743
Bram Moolenaare35a52a2020-05-31 19:48:53 +0200744func Test_syntax_foldlevel()
745 new
746 call setline(1, [
747 \ 'void f(int a)',
748 \ '{',
749 \ ' if (a == 1) {',
750 \ ' a = 0;',
751 \ ' } else if (a == 2) {',
752 \ ' a = 1;',
753 \ ' } else {',
754 \ ' a = 2;',
755 \ ' }',
756 \ ' if (a > 0) {',
757 \ ' if (a == 1) {',
758 \ ' a = 0;',
759 \ ' } /* missing newline */ } /* end of outer if */ else {',
760 \ ' a = 1;',
761 \ ' }',
762 \ ' if (a == 1)',
763 \ ' {',
764 \ ' a = 0;',
765 \ ' }',
766 \ ' else if (a == 2)',
767 \ ' {',
768 \ ' a = 1;',
769 \ ' }',
770 \ ' else',
771 \ ' {',
772 \ ' a = 2;',
773 \ ' }',
774 \ '}',
775 \ ])
776 setfiletype c
777 syntax on
778 set foldmethod=syntax
779
Bram Moolenaare2e40752020-09-04 21:18:46 +0200780 call assert_fails('syn foldlevel start start', 'E390:')
781 call assert_fails('syn foldlevel not_an_option', 'E390:')
Bram Moolenaare35a52a2020-05-31 19:48:53 +0200782
783 set foldlevel=1
784
785 syn foldlevel start
786 redir @c
787 syn foldlevel
788 redir END
789 call assert_equal("\nsyntax foldlevel start", @c)
790 syn sync fromstart
Bram Moolenaar99502802020-11-18 16:53:23 +0100791 call assert_match('from the first line$', execute('syn sync'))
Bram Moolenaare35a52a2020-05-31 19:48:53 +0200792 let a = map(range(3,9), 'foldclosed(v:val)')
793 call assert_equal([3,3,3,3,3,3,3], a) " attached cascade folds together
794 let a = map(range(10,15), 'foldclosed(v:val)')
795 call assert_equal([10,10,10,10,10,10], a) " over-attached 'else' hidden
796 let a = map(range(16,27), 'foldclosed(v:val)')
797 let unattached_results = [-1,17,17,17,-1,21,21,21,-1,25,25,25]
798 call assert_equal(unattached_results, a) " unattached cascade folds separately
799
800 syn foldlevel minimum
801 redir @c
802 syn foldlevel
803 redir END
804 call assert_equal("\nsyntax foldlevel minimum", @c)
805 syn sync fromstart
806 let a = map(range(3,9), 'foldclosed(v:val)')
807 call assert_equal([3,3,5,5,7,7,7], a) " attached cascade folds separately
808 let a = map(range(10,15), 'foldclosed(v:val)')
809 call assert_equal([10,10,10,13,13,13], a) " over-attached 'else' visible
810 let a = map(range(16,27), 'foldclosed(v:val)')
811 call assert_equal(unattached_results, a) " unattached cascade folds separately
812
813 set foldlevel=2
814
815 syn foldlevel start
816 syn sync fromstart
817 let a = map(range(11,14), 'foldclosed(v:val)')
818 call assert_equal([11,11,11,-1], a) " over-attached 'else' hidden
819
820 syn foldlevel minimum
821 syn sync fromstart
822 let a = map(range(11,14), 'foldclosed(v:val)')
823 call assert_equal([11,11,-1,-1], a) " over-attached 'else' visible
824
825 quit!
826endfunc
827
Bram Moolenaaradc17a52020-06-06 18:37:51 +0200828func Test_search_syntax_skip()
829 new
830 let lines =<< trim END
831
832 /* This is VIM */
833 Another Text for VIM
834 let a = "VIM"
835 END
836 call setline(1, lines)
837 syntax on
838 syntax match Comment "^/\*.*\*/"
839 syntax match String '".*"'
840
841 " Skip argument using string evaluation.
842 1
843 call search('VIM', 'w', '', 0, 'synIDattr(synID(line("."), col("."), 1), "name") =~? "comment"')
844 call assert_equal('Another Text for VIM', getline('.'))
zeertzjq180246c2022-06-23 12:04:46 +0100845
Bram Moolenaaradc17a52020-06-06 18:37:51 +0200846 1
zeertzjq180246c2022-06-23 12:04:46 +0100847 call search('VIM', 'cw', '', 0, 'synIDattr(synID(line("."), col("."), 1), "name") !~? "string"')
Bram Moolenaaradc17a52020-06-06 18:37:51 +0200848 call assert_equal(' let a = "VIM"', getline('.'))
849
850 " Skip argument using Lambda.
851 1
852 call search('VIM', 'w', '', 0, { -> synIDattr(synID(line("."), col("."), 1), "name") =~? "comment"})
853 call assert_equal('Another Text for VIM', getline('.'))
854
855 1
zeertzjq180246c2022-06-23 12:04:46 +0100856 call search('VIM', 'cw', '', 0, { -> synIDattr(synID(line("."), col("."), 1), "name") !~? "string"})
Bram Moolenaaradc17a52020-06-06 18:37:51 +0200857 call assert_equal(' let a = "VIM"', getline('.'))
858
859 " Skip argument using funcref.
860 func InComment()
861 return synIDattr(synID(line("."), col("."), 1), "name") =~? "comment"
862 endfunc
zeertzjq180246c2022-06-23 12:04:46 +0100863 func NotInString()
Bram Moolenaaradc17a52020-06-06 18:37:51 +0200864 return synIDattr(synID(line("."), col("."), 1), "name") !~? "string"
865 endfunc
zeertzjq180246c2022-06-23 12:04:46 +0100866
Bram Moolenaaradc17a52020-06-06 18:37:51 +0200867 1
868 call search('VIM', 'w', '', 0, function('InComment'))
869 call assert_equal('Another Text for VIM', getline('.'))
870
871 1
zeertzjq180246c2022-06-23 12:04:46 +0100872 call search('VIM', 'cw', '', 0, function('NotInString'))
Bram Moolenaaradc17a52020-06-06 18:37:51 +0200873 call assert_equal(' let a = "VIM"', getline('.'))
874
875 delfunc InComment
zeertzjq180246c2022-06-23 12:04:46 +0100876 delfunc NotInString
Bram Moolenaaradc17a52020-06-06 18:37:51 +0200877 bwipe!
878endfunc
879
Bram Moolenaarb46f57e2020-11-29 14:11:41 +0100880func Test_syn_contained_transparent()
881 " Comments starting with "Regression:" show the result when the highlighting
882 " span of the containing item is assigned to the contained region.
883 syntax on
884
885 let l:case = "Transparent region contained in region"
886 new
887 syntax region X start=/\[/ end=/\]/ contained transparent
888 syntax region Y start=/(/ end=/)/ contains=X
889
890 call setline(1, "==(--[~~]--)==")
891 let l:expected = " YYYYYYYYYY "
892 eval AssertHighlightGroups(1, 1, l:expected, 1, l:case)
893 syntax clear Y X
894 bw!
895
896 let l:case = "Transparent region extends region"
897 new
898 syntax region X start=/\[/ end=/\]/ contained transparent
899 syntax region Y start=/(/ end=/)/ end=/e/ contains=X
900
901 call setline(1, "==(--[~~e~~]--)==")
902 let l:expected = " YYYYYYYYYYYYY "
903 " Regression: " YYYYYYY YYY "
904 eval AssertHighlightGroups(1, 1, l:expected, 1, l:case)
905 syntax clear Y X
906 bw!
907
908 let l:case = "Nested transparent regions extend region"
909 new
910 syntax region X start=/\[/ end=/\]/ contained transparent
911 syntax region Y start=/(/ end=/)/ end=/e/ contains=X
912
913 call setline(1, "==(--[~~e~~[~~e~~]~~e~~]--)==")
914 let l:expected = " YYYYYYYYYYYYYYYYYYYYYYYYY "
915 " Regression: " YYYYYYY YYYYYYYYY "
916 eval AssertHighlightGroups(1, 1, l:expected, 1, l:case)
917 syntax clear Y X
918 bw!
919
920 let l:case = "Transparent region contained in match"
921 new
922 syntax region X start=/\[/ end=/\]/ contained transparent
923 syntax match Y /(.\{-})/ contains=X
924
925 call setline(1, "==(--[~~]--)==")
926 let l:expected = " YYYYYYYYYY "
927 eval AssertHighlightGroups(1, 1, l:expected, 1, l:case)
928 syntax clear Y X
929 bw!
930
931 let l:case = "Transparent region extends match"
932 new
933 syntax region X start=/\[/ end=/\]/ contained transparent
934 syntax match Y /(.\{-}[e)]/ contains=X
935
936 call setline(1, "==(--[~~e~~]--)==")
937 let l:expected = " YYYYYYYYYY "
938 " Regression: " YYYYYYY "
939 eval AssertHighlightGroups(1, 1, l:expected, 1, l:case)
940 syntax clear Y X
941 bw!
942
943 let l:case = "Nested transparent regions extend match"
944 new
945 syntax region X start=/\[/ end=/\]/ contained transparent
946 syntax match Y /(.\{-}[e)]/ contains=X
947
948 call setline(1, "==(--[~~e~~[~~e~~]~~e~~]--)==")
949 let l:expected = " YYYYYYYYYYYYYYYYYYYYYY "
950 " Regression: " YYYYYYY YYYYYY "
951 eval AssertHighlightGroups(1, 1, l:expected, 1, l:case)
952 syntax clear Y X
953 bw!
954endfunc
955
Bram Moolenaar2e240bd2021-04-14 11:15:08 +0200956func Test_syn_include_contains_TOP()
957 let l:case = "TOP in included syntax means its group list name"
958 new
959 syntax include @INCLUDED syntax/c.vim
960 syntax region FencedCodeBlockC start=/```c/ end=/```/ contains=@INCLUDED
961
962 call setline(1, ['```c', '#if 0', 'int', '#else', 'int', '#endif', '```' ])
963 let l:expected = ["cCppOutIf2"]
964 eval AssertHighlightGroups(3, 1, l:expected, 1)
965 " cCppOutElse has contains=TOP
966 let l:expected = ["cType"]
967 eval AssertHighlightGroups(5, 1, l:expected, 1, l:case)
968 syntax clear
969 bw!
970endfunc
971
zeertzjqca7e86c2022-04-16 16:49:24 +0100972" This was using freed memory
973func Test_WinEnter_synstack_synID()
974 autocmd WinEnter * call synstack(line("."), col("."))
975 autocmd WinEnter * call synID(line('.'), col('.') - 1, 1)
976 call setline(1, 'aaaaa')
977 normal! $
978 new
979 close
980
981 au! WinEnter
982 bw!
983endfunc
984
Bram Moolenaar2e240bd2021-04-14 11:15:08 +0200985
Bram Moolenaar0e05de42020-03-25 22:23:46 +0100986" vim: shiftwidth=2 sts=2 expandtab