blob: aeb2c51c580400759ff89e9a4437f442beb729b3 [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')
Romain Lafourcade124371c2024-01-07 15:08:31 +0100196 call assert_match('^"syn list Aap Added Boolean Changed Character ', @:)
Bram Moolenaard61e8aa2017-01-17 17:44:46 +0100197 hi clear Aap
198
Bram Moolenaar73b484c2016-12-11 15:11:17 +0100199 call feedkeys(":syn list \<C-A>\<C-B>\"\<CR>", 'tx')
Romain Lafourcade124371c2024-01-07 15:08:31 +0100200 call assert_match('^"syn list Added Boolean Changed Character ', @:)
Bram Moolenaar73b484c2016-12-11 15:11:17 +0100201
202 call feedkeys(":syn match \<C-A>\<C-B>\"\<CR>", 'tx')
Romain Lafourcade124371c2024-01-07 15:08:31 +0100203 call assert_match('^"syn match Added Boolean Changed 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()
Bram Moolenaard0f8d392022-12-04 23:00:41 +0000458 new XfooOwnSyntax
Bram Moolenaarf8ec9982017-04-09 15:41:31 +0200459 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 \ '}',
Bram Moolenaar56564962022-10-10 22:39:42 +0100655 \ ], 'Xtest.c', 'D')
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 +0100673endfun
Bram Moolenaarbcf94422018-06-23 14:21:42 +0200674
Dominique Pelle354b23a2021-12-17 17:32:29 +0000675" Test \z(...) along with \z1
676func Test_syn_zsub()
677 new
678 syntax on
679 call setline(1, 'xxx start foo xxx not end foo xxx end foo xxx')
680 let l:expected = ' ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ '
681
682 for l:re in [0, 1, 2]
683 " Example taken from :help :syn-ext-match
684 syntax region Z start="start \z(\I\i*\)" skip="not end \z1" end="end \z1"
685 eval AssertHighlightGroups(1, 1, l:expected, 1, 'regexp=' .. l:re)
686 syntax clear Z
687 endfor
688
689 set re&
690 bw!
691endfunc
692
Bram Moolenaarbcf94422018-06-23 14:21:42 +0200693" Using \z() in a region with NFA failing should not crash.
694func Test_syn_wrong_z_one()
695 new
696 call setline(1, ['just some text', 'with foo and bar to match with'])
697 syn region FooBar start="foo\z(.*\)bar" end="\z1"
698 call test_override("nfa_fail", 1)
699 redraw!
700 redraw!
701 call test_override("ALL", 0)
702 bwipe!
703endfunc
Bram Moolenaarc7f1e402019-08-03 13:29:46 +0200704
705func Test_syntax_after_bufdo()
Bram Moolenaar56564962022-10-10 22:39:42 +0100706 call writefile(['/* aaa comment */'], 'Xaaa.c', 'D')
707 call writefile(['/* bbb comment */'], 'Xbbb.c', 'D')
708 call writefile(['/* ccc comment */'], 'Xccc.c', 'D')
709 call writefile(['/* ddd comment */'], 'Xddd.c', 'D')
Bram Moolenaarc7f1e402019-08-03 13:29:46 +0200710
711 let bnr = bufnr('%')
712 new Xaaa.c
713 badd Xbbb.c
714 badd Xccc.c
715 badd Xddd.c
716 exe "bwipe " . bnr
717 let l = []
718 bufdo call add(l, bufnr('%'))
719 call assert_equal(4, len(l))
720
721 syntax on
722
723 " This used to only enable syntax HL in the last buffer.
724 bufdo tab split
725 tabrewind
726 for tab in range(1, 4)
727 norm fm
728 call assert_equal(['cComment'], map(synstack(line("."), col(".")), 'synIDattr(v:val, "name")'))
729 tabnext
730 endfor
731
732 bwipe! Xaaa.c
733 bwipe! Xbbb.c
734 bwipe! Xccc.c
735 bwipe! Xddd.c
736 syntax off
Bram Moolenaarc7f1e402019-08-03 13:29:46 +0200737endfunc
Bram Moolenaar0e05de42020-03-25 22:23:46 +0100738
Bram Moolenaare35a52a2020-05-31 19:48:53 +0200739func Test_syntax_foldlevel()
740 new
741 call setline(1, [
742 \ 'void f(int a)',
743 \ '{',
744 \ ' if (a == 1) {',
745 \ ' a = 0;',
746 \ ' } else if (a == 2) {',
747 \ ' a = 1;',
748 \ ' } else {',
749 \ ' a = 2;',
750 \ ' }',
751 \ ' if (a > 0) {',
752 \ ' if (a == 1) {',
753 \ ' a = 0;',
754 \ ' } /* missing newline */ } /* end of outer if */ else {',
755 \ ' a = 1;',
756 \ ' }',
757 \ ' if (a == 1)',
758 \ ' {',
759 \ ' a = 0;',
760 \ ' }',
761 \ ' else if (a == 2)',
762 \ ' {',
763 \ ' a = 1;',
764 \ ' }',
765 \ ' else',
766 \ ' {',
767 \ ' a = 2;',
768 \ ' }',
769 \ '}',
770 \ ])
771 setfiletype c
772 syntax on
773 set foldmethod=syntax
774
Bram Moolenaare2e40752020-09-04 21:18:46 +0200775 call assert_fails('syn foldlevel start start', 'E390:')
776 call assert_fails('syn foldlevel not_an_option', 'E390:')
Bram Moolenaare35a52a2020-05-31 19:48:53 +0200777
778 set foldlevel=1
779
780 syn foldlevel start
781 redir @c
782 syn foldlevel
783 redir END
784 call assert_equal("\nsyntax foldlevel start", @c)
785 syn sync fromstart
Bram Moolenaar99502802020-11-18 16:53:23 +0100786 call assert_match('from the first line$', execute('syn sync'))
Bram Moolenaare35a52a2020-05-31 19:48:53 +0200787 let a = map(range(3,9), 'foldclosed(v:val)')
788 call assert_equal([3,3,3,3,3,3,3], a) " attached cascade folds together
789 let a = map(range(10,15), 'foldclosed(v:val)')
790 call assert_equal([10,10,10,10,10,10], a) " over-attached 'else' hidden
791 let a = map(range(16,27), 'foldclosed(v:val)')
792 let unattached_results = [-1,17,17,17,-1,21,21,21,-1,25,25,25]
793 call assert_equal(unattached_results, a) " unattached cascade folds separately
794
795 syn foldlevel minimum
796 redir @c
797 syn foldlevel
798 redir END
799 call assert_equal("\nsyntax foldlevel minimum", @c)
800 syn sync fromstart
801 let a = map(range(3,9), 'foldclosed(v:val)')
802 call assert_equal([3,3,5,5,7,7,7], a) " attached cascade folds separately
803 let a = map(range(10,15), 'foldclosed(v:val)')
804 call assert_equal([10,10,10,13,13,13], a) " over-attached 'else' visible
805 let a = map(range(16,27), 'foldclosed(v:val)')
806 call assert_equal(unattached_results, a) " unattached cascade folds separately
807
808 set foldlevel=2
809
810 syn foldlevel start
811 syn sync fromstart
812 let a = map(range(11,14), 'foldclosed(v:val)')
813 call assert_equal([11,11,11,-1], a) " over-attached 'else' hidden
814
815 syn foldlevel minimum
816 syn sync fromstart
817 let a = map(range(11,14), 'foldclosed(v:val)')
818 call assert_equal([11,11,-1,-1], a) " over-attached 'else' visible
819
820 quit!
821endfunc
822
Bram Moolenaaradc17a52020-06-06 18:37:51 +0200823func Test_search_syntax_skip()
824 new
825 let lines =<< trim END
826
827 /* This is VIM */
828 Another Text for VIM
829 let a = "VIM"
830 END
831 call setline(1, lines)
832 syntax on
833 syntax match Comment "^/\*.*\*/"
834 syntax match String '".*"'
835
836 " Skip argument using string evaluation.
837 1
838 call search('VIM', 'w', '', 0, 'synIDattr(synID(line("."), col("."), 1), "name") =~? "comment"')
839 call assert_equal('Another Text for VIM', getline('.'))
zeertzjq180246c2022-06-23 12:04:46 +0100840
Bram Moolenaaradc17a52020-06-06 18:37:51 +0200841 1
zeertzjq180246c2022-06-23 12:04:46 +0100842 call search('VIM', 'cw', '', 0, 'synIDattr(synID(line("."), col("."), 1), "name") !~? "string"')
Bram Moolenaaradc17a52020-06-06 18:37:51 +0200843 call assert_equal(' let a = "VIM"', getline('.'))
844
845 " Skip argument using Lambda.
846 1
847 call search('VIM', 'w', '', 0, { -> synIDattr(synID(line("."), col("."), 1), "name") =~? "comment"})
848 call assert_equal('Another Text for VIM', getline('.'))
849
850 1
zeertzjq180246c2022-06-23 12:04:46 +0100851 call search('VIM', 'cw', '', 0, { -> synIDattr(synID(line("."), col("."), 1), "name") !~? "string"})
Bram Moolenaaradc17a52020-06-06 18:37:51 +0200852 call assert_equal(' let a = "VIM"', getline('.'))
853
854 " Skip argument using funcref.
855 func InComment()
856 return synIDattr(synID(line("."), col("."), 1), "name") =~? "comment"
857 endfunc
zeertzjq180246c2022-06-23 12:04:46 +0100858 func NotInString()
Bram Moolenaaradc17a52020-06-06 18:37:51 +0200859 return synIDattr(synID(line("."), col("."), 1), "name") !~? "string"
860 endfunc
zeertzjq180246c2022-06-23 12:04:46 +0100861
Bram Moolenaaradc17a52020-06-06 18:37:51 +0200862 1
863 call search('VIM', 'w', '', 0, function('InComment'))
864 call assert_equal('Another Text for VIM', getline('.'))
865
866 1
zeertzjq180246c2022-06-23 12:04:46 +0100867 call search('VIM', 'cw', '', 0, function('NotInString'))
Bram Moolenaaradc17a52020-06-06 18:37:51 +0200868 call assert_equal(' let a = "VIM"', getline('.'))
869
870 delfunc InComment
zeertzjq180246c2022-06-23 12:04:46 +0100871 delfunc NotInString
Bram Moolenaaradc17a52020-06-06 18:37:51 +0200872 bwipe!
873endfunc
874
Bram Moolenaarb46f57e2020-11-29 14:11:41 +0100875func Test_syn_contained_transparent()
876 " Comments starting with "Regression:" show the result when the highlighting
877 " span of the containing item is assigned to the contained region.
878 syntax on
879
880 let l:case = "Transparent region contained in region"
881 new
882 syntax region X start=/\[/ end=/\]/ contained transparent
883 syntax region Y start=/(/ end=/)/ contains=X
884
885 call setline(1, "==(--[~~]--)==")
886 let l:expected = " YYYYYYYYYY "
887 eval AssertHighlightGroups(1, 1, l:expected, 1, l:case)
888 syntax clear Y X
889 bw!
890
891 let l:case = "Transparent region extends region"
892 new
893 syntax region X start=/\[/ end=/\]/ contained transparent
894 syntax region Y start=/(/ end=/)/ end=/e/ contains=X
895
896 call setline(1, "==(--[~~e~~]--)==")
897 let l:expected = " YYYYYYYYYYYYY "
898 " Regression: " YYYYYYY YYY "
899 eval AssertHighlightGroups(1, 1, l:expected, 1, l:case)
900 syntax clear Y X
901 bw!
902
903 let l:case = "Nested transparent regions extend region"
904 new
905 syntax region X start=/\[/ end=/\]/ contained transparent
906 syntax region Y start=/(/ end=/)/ end=/e/ contains=X
907
908 call setline(1, "==(--[~~e~~[~~e~~]~~e~~]--)==")
909 let l:expected = " YYYYYYYYYYYYYYYYYYYYYYYYY "
910 " Regression: " YYYYYYY YYYYYYYYY "
911 eval AssertHighlightGroups(1, 1, l:expected, 1, l:case)
912 syntax clear Y X
913 bw!
914
915 let l:case = "Transparent region contained in match"
916 new
917 syntax region X start=/\[/ end=/\]/ contained transparent
918 syntax match Y /(.\{-})/ contains=X
919
920 call setline(1, "==(--[~~]--)==")
921 let l:expected = " YYYYYYYYYY "
922 eval AssertHighlightGroups(1, 1, l:expected, 1, l:case)
923 syntax clear Y X
924 bw!
925
926 let l:case = "Transparent region extends match"
927 new
928 syntax region X start=/\[/ end=/\]/ contained transparent
929 syntax match Y /(.\{-}[e)]/ contains=X
930
931 call setline(1, "==(--[~~e~~]--)==")
932 let l:expected = " YYYYYYYYYY "
933 " Regression: " YYYYYYY "
934 eval AssertHighlightGroups(1, 1, l:expected, 1, l:case)
935 syntax clear Y X
936 bw!
937
938 let l:case = "Nested transparent regions extend match"
939 new
940 syntax region X start=/\[/ end=/\]/ contained transparent
941 syntax match Y /(.\{-}[e)]/ contains=X
942
943 call setline(1, "==(--[~~e~~[~~e~~]~~e~~]--)==")
944 let l:expected = " YYYYYYYYYYYYYYYYYYYYYY "
945 " Regression: " YYYYYYY YYYYYY "
946 eval AssertHighlightGroups(1, 1, l:expected, 1, l:case)
947 syntax clear Y X
948 bw!
949endfunc
950
Bram Moolenaar2e240bd2021-04-14 11:15:08 +0200951func Test_syn_include_contains_TOP()
952 let l:case = "TOP in included syntax means its group list name"
953 new
954 syntax include @INCLUDED syntax/c.vim
955 syntax region FencedCodeBlockC start=/```c/ end=/```/ contains=@INCLUDED
956
957 call setline(1, ['```c', '#if 0', 'int', '#else', 'int', '#endif', '```' ])
958 let l:expected = ["cCppOutIf2"]
959 eval AssertHighlightGroups(3, 1, l:expected, 1)
960 " cCppOutElse has contains=TOP
961 let l:expected = ["cType"]
962 eval AssertHighlightGroups(5, 1, l:expected, 1, l:case)
963 syntax clear
964 bw!
965endfunc
966
zeertzjqca7e86c2022-04-16 16:49:24 +0100967" This was using freed memory
968func Test_WinEnter_synstack_synID()
969 autocmd WinEnter * call synstack(line("."), col("."))
970 autocmd WinEnter * call synID(line('.'), col('.') - 1, 1)
971 call setline(1, 'aaaaa')
972 normal! $
973 new
974 close
975
976 au! WinEnter
977 bw!
978endfunc
979
Bram Moolenaar2e240bd2021-04-14 11:15:08 +0200980
Bram Moolenaar0e05de42020-03-25 22:23:46 +0100981" vim: shiftwidth=2 sts=2 expandtab