blob: 0374077bdb94d7b6755809d048b711b49be2a62a [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 +02003CheckFeature syntax
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01004
Christian Brabandteb380b92025-07-07 20:53:55 +02005source util/screendump.vim
Bram Moolenaar4d785892017-06-22 22:00:50 +02006
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01007func GetSyntaxItem(pat)
8 let c = ''
9 let a = ['a', getreg('a'), getregtype('a')]
10 0
11 redraw!
12 call search(a:pat, 'W')
13 let synid = synID(line('.'), col('.'), 1)
14 while synid == synID(line('.'), col('.'), 1)
15 norm! v"ay
16 " stop at whitespace
17 if @a =~# '\s'
18 break
19 endif
20 let c .= @a
21 norm! l
22 endw
23 call call('setreg', a)
24 0
25 return c
26endfunc
27
Bram Moolenaarb46f57e2020-11-29 14:11:41 +010028func AssertHighlightGroups(lnum, startcol, expected, trans = 1, msg = "")
29 " Assert that the characters starting at a given (line, col)
30 " sequentially match the expected highlight groups.
31 " If groups are provided as a string, each character is assumed to be a
32 " group and spaces represent no group, useful for visually describing tests.
33 let l:expectedGroups = type(a:expected) == v:t_string
34 \ ? a:expected->split('\zs')->map({_, v -> trim(v)})
35 \ : a:expected
36 let l:errors = 0
37 let l:msg = (a:msg->empty() ? "" : a:msg .. ": ")
38 \ .. "Wrong highlight group at " .. a:lnum .. ","
39
40 for l:i in range(a:startcol, a:startcol + l:expectedGroups->len() - 1)
41 let l:errors += synID(a:lnum, l:i, a:trans)
42 \ ->synIDattr("name")
43 \ ->assert_equal(l:expectedGroups[l:i - 1],
44 \ l:msg .. l:i)
45 endfor
46endfunc
47
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010048func Test_syn_iskeyword()
49 new
50 call setline(1, [
51 \ 'CREATE TABLE FOOBAR(',
52 \ ' DLTD_BY VARCHAR2(100)',
53 \ ');',
Bram Moolenaar037c54f2019-04-20 23:47:46 +020054 \ ''])
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010055
56 syntax on
57 set ft=sql
58 syn match SYN /C\k\+\>/
59 hi link SYN ErrorMsg
60 call assert_equal('DLTD_BY', GetSyntaxItem('DLTD'))
61 /\<D\k\+\>/:norm! ygn
62 call assert_equal('DLTD_BY', @0)
63 redir @c
64 syn iskeyword
65 redir END
66 call assert_equal("\nsyntax iskeyword not set", @c)
67
68 syn iskeyword @,48-57,_,192-255
69 redir @c
70 syn iskeyword
71 redir END
72 call assert_equal("\nsyntax iskeyword @,48-57,_,192-255", @c)
73
74 setlocal isk-=_
75 call assert_equal('DLTD_BY', GetSyntaxItem('DLTD'))
76 /\<D\k\+\>/:norm! ygn
Bram Moolenaar73b484c2016-12-11 15:11:17 +010077 let b2 = @0
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010078 call assert_equal('DLTD', @0)
79
80 syn iskeyword clear
81 redir @c
82 syn iskeyword
83 redir END
84 call assert_equal("\nsyntax iskeyword not set", @c)
85
86 quit!
87endfunc
Bram Moolenaarc3691332016-04-20 12:49:49 +020088
89func Test_syntax_after_reload()
90 split Xsomefile
91 call setline(1, ['hello', 'there'])
92 w!
93 only!
94 setl filetype=hello
95 au FileType hello let g:gotit = 1
96 call assert_false(exists('g:gotit'))
97 edit other
98 buf Xsomefile
99 call assert_equal('hello', &filetype)
100 call assert_true(exists('g:gotit'))
101 call delete('Xsomefile')
102endfunc
Bram Moolenaar73b484c2016-12-11 15:11:17 +0100103
104func Test_syntime()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200105 CheckFeature profile
Bram Moolenaar73b484c2016-12-11 15:11:17 +0100106
107 syntax on
108 syntime on
109 let a = execute('syntime report')
110 call assert_equal("\nNo Syntax items defined for this buffer", a)
111
Dominique Pelle6d37e8e2021-05-06 17:36:55 +0200112 let a = execute('syntime clear')
113 call assert_equal("\nNo Syntax items defined for this buffer", a)
114
Bram Moolenaar73b484c2016-12-11 15:11:17 +0100115 view ../memfile_test.c
116 setfiletype cpp
117 redraw
118 let a = execute('syntime report')
119 call assert_match('^ TOTAL *COUNT *MATCH *SLOWEST *AVERAGE *NAME *PATTERN', a)
120 call assert_match(' \d*\.\d* \+[^0]\d* .* cppRawString ', a)
121 call assert_match(' \d*\.\d* \+[^0]\d* .* cppNumber ', a)
122
123 syntime off
124 syntime clear
125 let a = execute('syntime report')
126 call assert_match('^ TOTAL *COUNT *MATCH *SLOWEST *AVERAGE *NAME *PATTERN', a)
127 call assert_notmatch('.* cppRawString *', a)
128 call assert_notmatch('.* cppNumber*', a)
129 call assert_notmatch('[1-9]', a)
130
Bram Moolenaare2e40752020-09-04 21:18:46 +0200131 call assert_fails('syntime abc', 'E475:')
Bram Moolenaar73b484c2016-12-11 15:11:17 +0100132
133 syntax clear
134 let a = execute('syntime report')
135 call assert_equal("\nNo Syntax items defined for this buffer", a)
136
137 bd
138endfunc
139
Bram Moolenaarb513d302018-12-02 14:55:08 +0100140func Test_syntime_completion()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200141 CheckFeature profile
Bram Moolenaarb513d302018-12-02 14:55:08 +0100142
143 call feedkeys(":syntime \<C-A>\<C-B>\"\<CR>", 'tx')
144 call assert_equal('"syntime clear off on report', @:)
145endfunc
146
Bram Moolenaar73b484c2016-12-11 15:11:17 +0100147func Test_syntax_list()
148 syntax on
149 let a = execute('syntax list')
150 call assert_equal("\nNo Syntax items defined for this buffer", a)
151
152 view ../memfile_test.c
153 setfiletype c
154
155 let a = execute('syntax list')
156 call assert_match('cInclude*', a)
157 call assert_match('cDefine', a)
158
159 let a = execute('syntax list cDefine')
160 call assert_notmatch('cInclude*', a)
161 call assert_match('cDefine', a)
162 call assert_match(' links to Macro$', a)
163
164 call assert_fails('syntax list ABCD', 'E28:')
165 call assert_fails('syntax list @ABCD', 'E392:')
166
167 syntax clear
168 let a = execute('syntax list')
169 call assert_equal("\nNo Syntax items defined for this buffer", a)
170
Bram Moolenaar08f41572020-04-20 16:50:00 +0200171 syntax keyword Type int containedin=g1 skipwhite skipempty skipnl nextgroup=Abc
172 let exp = "Type xxx containedin=g1 nextgroup=Abc skipnl skipwhite skipempty int"
173 call assert_equal(exp, split(execute("syntax list"), "\n")[1])
174
Bram Moolenaar73b484c2016-12-11 15:11:17 +0100175 bd
176endfunc
177
178func Test_syntax_completion()
179 call feedkeys(":syn \<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaare35a52a2020-05-31 19:48:53 +0200180 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 +0100181
182 call feedkeys(":syn case \<C-A>\<C-B>\"\<CR>", 'tx')
183 call assert_equal('"syn case ignore match', @:)
184
Bram Moolenaar2d028392017-01-08 18:28:22 +0100185 call feedkeys(":syn spell \<C-A>\<C-B>\"\<CR>", 'tx')
186 call assert_equal('"syn spell default notoplevel toplevel', @:)
187
188 call feedkeys(":syn sync \<C-A>\<C-B>\"\<CR>", 'tx')
189 call assert_equal('"syn sync ccomment clear fromstart linebreaks= linecont lines= match maxlines= minlines= region', @:)
190
Bram Moolenaard61e8aa2017-01-17 17:44:46 +0100191 " Check that clearing "Aap" avoids it showing up before Boolean.
192 hi Aap ctermfg=blue
193 call feedkeys(":syn list \<C-A>\<C-B>\"\<CR>", 'tx')
Romain Lafourcade124371c2024-01-07 15:08:31 +0100194 call assert_match('^"syn list Aap Added Boolean Changed Character ', @:)
Bram Moolenaard61e8aa2017-01-17 17:44:46 +0100195 hi clear Aap
196
Bram Moolenaar73b484c2016-12-11 15:11:17 +0100197 call feedkeys(":syn list \<C-A>\<C-B>\"\<CR>", 'tx')
Romain Lafourcade124371c2024-01-07 15:08:31 +0100198 call assert_match('^"syn list Added Boolean Changed Character ', @:)
Bram Moolenaar73b484c2016-12-11 15:11:17 +0100199
200 call feedkeys(":syn match \<C-A>\<C-B>\"\<CR>", 'tx')
Romain Lafourcade124371c2024-01-07 15:08:31 +0100201 call assert_match('^"syn match Added Boolean Changed Character ', @:)
bfredlaf9a6002022-08-26 21:58:31 +0100202
203 syn cluster Aax contains=Aap
204 call feedkeys(":syn list @A\<C-A>\<C-B>\"\<CR>", 'tx')
205 call assert_match('^"syn list @Aax', @:)
Bram Moolenaar73b484c2016-12-11 15:11:17 +0100206endfunc
Bram Moolenaarde318c52017-01-17 16:27:10 +0100207
Bram Moolenaar297610b2019-12-27 17:20:55 +0100208func Test_echohl_completion()
209 call feedkeys(":echohl no\<C-A>\<C-B>\"\<CR>", 'tx')
Yee Cheng China7b81202025-02-23 09:32:47 +0100210 call assert_equal('"echohl NONE NonText Normal', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +0100211endfunc
212
Bram Moolenaarde318c52017-01-17 16:27:10 +0100213func Test_syntax_arg_skipped()
214 syn clear
215 syntax case ignore
216 if 0
217 syntax case match
218 endif
219 call assert_match('case ignore', execute('syntax case'))
220
221 syn keyword Foo foo
222 call assert_match('Foo', execute('syntax'))
223 syn clear
224 call assert_match('case match', execute('syntax case'))
225 call assert_notmatch('Foo', execute('syntax'))
226
227 if has('conceal')
228 syn clear
229 syntax conceal on
230 if 0
231 syntax conceal off
232 endif
233 call assert_match('conceal on', execute('syntax conceal'))
234 syn clear
235 call assert_match('conceal off', execute('syntax conceal'))
Bram Moolenaar58f60ca2017-01-17 17:19:00 +0100236
237 syntax conceal on
238 syntax conceal off
239 call assert_match('conceal off', execute('syntax conceal'))
Bram Moolenaarde318c52017-01-17 16:27:10 +0100240 endif
241
Bram Moolenaard61e8aa2017-01-17 17:44:46 +0100242 syntax region Bar start=/</ end=/>/
Bram Moolenaarde318c52017-01-17 16:27:10 +0100243 if 0
244 syntax region NotTest start=/</ end=/>/ contains=@Spell
245 endif
Bram Moolenaard61e8aa2017-01-17 17:44:46 +0100246 call assert_match('Bar', execute('syntax'))
Bram Moolenaarde318c52017-01-17 16:27:10 +0100247 call assert_notmatch('NotTest', execute('syntax'))
248 call assert_notmatch('Spell', execute('syntax'))
249
250 hi Foo ctermfg=blue
251 let a = execute('hi Foo')
252 if 0
253 syntax rest
254 endif
255 call assert_equal(a, execute('hi Foo'))
Bram Moolenaard61e8aa2017-01-17 17:44:46 +0100256 hi clear Bar
257 hi clear Foo
Bram Moolenaarde318c52017-01-17 16:27:10 +0100258
259 set ft=tags
260 syn off
261 if 0
262 syntax enable
263 endif
264 call assert_match('No Syntax items defined', execute('syntax'))
265 syntax enable
266 call assert_match('tagComment', execute('syntax'))
267 set ft=
268
269 syn clear
270 if 0
271 syntax include @Spell nothing
272 endif
273 call assert_notmatch('Spell', execute('syntax'))
274
275 syn clear
276 syn iskeyword 48-57,$,_
277 call assert_match('48-57,$,_', execute('syntax iskeyword'))
278 if 0
279 syn clear
280 syn iskeyword clear
281 endif
282 call assert_match('48-57,$,_', execute('syntax iskeyword'))
283 syn iskeyword clear
284 call assert_match('not set', execute('syntax iskeyword'))
285 syn iskeyword 48-57,$,_
286 syn clear
287 call assert_match('not set', execute('syntax iskeyword'))
288
289 syn clear
290 syn keyword Foo foo
291 if 0
292 syn keyword NotAdded bar
293 endif
294 call assert_match('Foo', execute('syntax'))
295 call assert_notmatch('NotAdded', execute('highlight'))
296
297 syn clear
298 syn keyword Foo foo
299 call assert_match('Foo', execute('syntax'))
300 call assert_match('Foo', execute('syntax list'))
301 call assert_notmatch('Foo', execute('if 0 | syntax | endif'))
302 call assert_notmatch('Foo', execute('if 0 | syntax list | endif'))
303
304 syn clear
305 syn match Fopi /asdf/
306 if 0
307 syn match Fopx /asdf/
308 endif
309 call assert_match('Fopi', execute('syntax'))
310 call assert_notmatch('Fopx', execute('syntax'))
311
312 syn clear
313 syn spell toplevel
314 call assert_match('spell toplevel', execute('syntax spell'))
315 if 0
316 syn spell notoplevel
317 endif
318 call assert_match('spell toplevel', execute('syntax spell'))
319 syn spell notoplevel
320 call assert_match('spell notoplevel', execute('syntax spell'))
321 syn spell default
322 call assert_match('spell default', execute('syntax spell'))
323
324 syn clear
325 if 0
326 syntax cluster Spell
327 endif
328 call assert_notmatch('Spell', execute('syntax'))
329
330 syn clear
331 syn keyword Foo foo
332 syn sync ccomment
333 syn sync maxlines=5
334 if 0
335 syn sync maxlines=11
336 endif
337 call assert_match('on C-style comments', execute('syntax sync'))
338 call assert_match('maximal 5 lines', execute('syntax sync'))
Bram Moolenaar58f60ca2017-01-17 17:19:00 +0100339 syn sync clear
Bram Moolenaarde318c52017-01-17 16:27:10 +0100340 if 0
341 syn sync ccomment
342 endif
343 call assert_notmatch('on C-style comments', execute('syntax sync'))
Bram Moolenaar99502802020-11-18 16:53:23 +0100344 syn sync fromstart
345 call assert_match('syncing starts at the first line', execute('syntax sync'))
Bram Moolenaarde318c52017-01-17 16:27:10 +0100346
347 syn clear
348endfunc
349
Bram Moolenaarfbf21222020-04-19 18:31:25 +0200350" Check for an error. Used when multiple errors are thrown and we are checking
351" for an earliest error.
352func AssertFails(cmd, errcode)
353 let save_exception = ''
354 try
355 exe a:cmd
356 catch
357 let save_exception = v:exception
358 endtry
359 call assert_match(a:errcode, save_exception)
360endfunc
361
Bram Moolenaarea588152017-04-10 22:45:30 +0200362func Test_syntax_invalid_arg()
Bram Moolenaar58f60ca2017-01-17 17:19:00 +0100363 call assert_fails('syntax case asdf', 'E390:')
Bram Moolenaard61e8aa2017-01-17 17:44:46 +0100364 if has('conceal')
365 call assert_fails('syntax conceal asdf', 'E390:')
366 endif
Bram Moolenaar58f60ca2017-01-17 17:19:00 +0100367 call assert_fails('syntax spell asdf', 'E390:')
Bram Moolenaarea588152017-04-10 22:45:30 +0200368 call assert_fails('syntax clear @ABCD', 'E391:')
Bram Moolenaarfbf21222020-04-19 18:31:25 +0200369 call assert_fails('syntax include random_file', 'E484:')
370 call assert_fails('syntax include <afile>', 'E495:')
Bram Moolenaarea588152017-04-10 22:45:30 +0200371 call assert_fails('syntax sync x', 'E404:')
372 call assert_fails('syntax keyword Abc a[', 'E789:')
373 call assert_fails('syntax keyword Abc a[bc]d', 'E890:')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +0200374 call assert_fails('syntax cluster Abc add=A add=', 'E406:')
Bram Moolenaar476a6132020-04-08 19:48:56 +0200375
376 " Test for too many \z\( and unmatched \z\(
377 " Not able to use assert_fails() here because both E50:/E879: and E475:
378 " messages are emitted.
379 set regexpengine=1
Bram Moolenaarfbf21222020-04-19 18:31:25 +0200380 call AssertFails("syntax region MyRegion start='\\z\\(' end='\\*/'", 'E52:')
Bram Moolenaar476a6132020-04-08 19:48:56 +0200381
Bram Moolenaarfbf21222020-04-19 18:31:25 +0200382 let cmd = "syntax region MyRegion start='"
383 let cmd ..= repeat("\\z\\(.\\)", 10) .. "' end='\*/'"
384 call AssertFails(cmd, 'E50:')
Bram Moolenaar476a6132020-04-08 19:48:56 +0200385
386 set regexpengine=2
Bram Moolenaarfbf21222020-04-19 18:31:25 +0200387 call AssertFails("syntax region MyRegion start='\\z\\(' end='\\*/'", 'E54:')
Bram Moolenaar476a6132020-04-08 19:48:56 +0200388
Bram Moolenaarfbf21222020-04-19 18:31:25 +0200389 let cmd = "syntax region MyRegion start='"
390 let cmd ..= repeat("\\z\\(.\\)", 10) .. "' end='\*/'"
391 call AssertFails(cmd, 'E879:')
Bram Moolenaar476a6132020-04-08 19:48:56 +0200392 set regexpengine&
Bram Moolenaarfbf21222020-04-19 18:31:25 +0200393
394 call AssertFails('syntax keyword cMyItem grouphere G1', 'E393:')
395 call AssertFails('syntax sync match Abc grouphere MyItem "abc"', 'E394:')
396 call AssertFails('syn keyword Type contains int', 'E395:')
397 call assert_fails('syntax include @Xxx', 'E397:')
398 call AssertFails('syntax region X start', 'E398:')
399 call assert_fails('syntax region X start="{"', 'E399:')
400 call AssertFails('syntax cluster contains=Abc', 'E400:')
401 call AssertFails("syntax match Character /'.'", 'E401:')
402 call AssertFails("syntax match Character /'.'/a", 'E402:')
Bram Moolenaar531be472020-09-23 22:38:05 +0200403 call assert_fails('syntax sync linecont /\%(/', 'E53:')
Bram Moolenaarfbf21222020-04-19 18:31:25 +0200404 call assert_fails('syntax sync linecont /pat', 'E404:')
405 call assert_fails('syntax sync linecont', 'E404:')
406 call assert_fails('syntax sync linecont /pat1/ linecont /pat2/', 'E403:')
407 call assert_fails('syntax sync minlines=a', 'E404:')
408 call AssertFails('syntax match ABC /x/ contains=', 'E406:')
409 call AssertFails("syntax match Character contains /'.'/", 'E405:')
410 call AssertFails('syntax match ccFoo "Foo" nextgroup=ALLBUT,F', 'E407:')
411 call AssertFails('syntax region Block start="{" contains=F,ALLBUT', 'E408:')
412 call AssertFails("syntax match Characters contains=a.*x /'.'/", 'E409:')
Bram Moolenaar531be472020-09-23 22:38:05 +0200413 call assert_fails('syntax match Search /abc/ contains=ALLBUT,/\%(/', 'E53:')
Bram Moolenaar58f60ca2017-01-17 17:19:00 +0100414endfunc
415
416func Test_syn_sync()
417 syntax region HereGroup start=/this/ end=/that/
418 syntax sync match SyncHere grouphere HereGroup "pattern"
419 call assert_match('SyncHere', execute('syntax sync'))
420 syn sync clear
421 call assert_notmatch('SyncHere', execute('syntax sync'))
422 syn clear
423endfunc
424
425func Test_syn_clear()
426 syntax keyword Foo foo
Bram Moolenaard61e8aa2017-01-17 17:44:46 +0100427 syntax keyword Bar tar
Bram Moolenaar58f60ca2017-01-17 17:19:00 +0100428 call assert_match('Foo', execute('syntax'))
Bram Moolenaard61e8aa2017-01-17 17:44:46 +0100429 call assert_match('Bar', execute('syntax'))
Bram Moolenaarc96272e2017-03-26 13:50:09 +0200430 call assert_equal('Foo', synIDattr(hlID("Foo"), "name"))
Bram Moolenaar58f60ca2017-01-17 17:19:00 +0100431 syn clear Foo
432 call assert_notmatch('Foo', execute('syntax'))
Bram Moolenaard61e8aa2017-01-17 17:44:46 +0100433 call assert_match('Bar', execute('syntax'))
Bram Moolenaarc96272e2017-03-26 13:50:09 +0200434 call assert_equal('Foo', synIDattr(hlID("Foo"), "name"))
Bram Moolenaard61e8aa2017-01-17 17:44:46 +0100435 syn clear Foo Bar
Bram Moolenaar58f60ca2017-01-17 17:19:00 +0100436 call assert_notmatch('Foo', execute('syntax'))
Bram Moolenaard61e8aa2017-01-17 17:44:46 +0100437 call assert_notmatch('Bar', execute('syntax'))
438 hi clear Foo
Bram Moolenaarc96272e2017-03-26 13:50:09 +0200439 call assert_equal('Foo', synIDattr(hlID("Foo"), "name"))
Bram Moolenaard61e8aa2017-01-17 17:44:46 +0100440 hi clear Bar
Bram Moolenaarfbf21222020-04-19 18:31:25 +0200441 call assert_fails('syntax clear invalid_syngroup', 'E28:')
Bram Moolenaar58f60ca2017-01-17 17:19:00 +0100442endfunc
Bram Moolenaar4007ed42017-01-17 18:14:54 +0100443
444func Test_invalid_name()
445 syn clear
446 syn keyword Nop yes
447 call assert_fails("syntax keyword Wr\x17ong bar", 'E669:')
448 syntax keyword @Wrong bar
449 call assert_match('W18:', execute('1messages'))
450 syn clear
451 hi clear Nop
452 hi clear @Wrong
453endfunc
Bram Moolenaarf8ec9982017-04-09 15:41:31 +0200454
455func Test_ownsyntax()
Bram Moolenaard0f8d392022-12-04 23:00:41 +0000456 new XfooOwnSyntax
Bram Moolenaarf8ec9982017-04-09 15:41:31 +0200457 call setline(1, '#define FOO')
458 syntax on
459 set filetype=c
Bram Moolenaard1f76af2020-09-13 22:37:34 +0200460
Bram Moolenaarf8ec9982017-04-09 15:41:31 +0200461 ownsyntax perl
Bram Moolenaard1f76af2020-09-13 22:37:34 +0200462 " this should not crash
463 set
464
Bram Moolenaarf8ec9982017-04-09 15:41:31 +0200465 call assert_equal('perlComment', synIDattr(synID(line('.'), col('.'), 1), 'name'))
466 call assert_equal('c', b:current_syntax)
467 call assert_equal('perl', w:current_syntax)
468
469 " A new split window should have the original syntax.
470 split
471 call assert_equal('cDefine', synIDattr(synID(line('.'), col('.'), 1), 'name'))
472 call assert_equal('c', b:current_syntax)
473 call assert_equal(0, exists('w:current_syntax'))
474
475 wincmd x
476 call assert_equal('perlComment', synIDattr(synID(line("."), col("."), 1), "name"))
477
478 syntax off
479 set filetype&
480 %bw!
481endfunc
482
483func Test_ownsyntax_completion()
484 call feedkeys(":ownsyntax java\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarea7a08a2019-08-26 22:38:22 +0200485 call assert_equal('"ownsyntax java javacc javascript javascriptreact', @:)
Bram Moolenaarf8ec9982017-04-09 15:41:31 +0200486endfunc
Bram Moolenaarea588152017-04-10 22:45:30 +0200487
488func Test_highlight_invalid_arg()
489 if has('gui_running')
490 call assert_fails('hi XXX guifg=xxx', 'E254:')
491 endif
492 call assert_fails('hi DoesNotExist', 'E411:')
493 call assert_fails('hi link', 'E412:')
494 call assert_fails('hi link a', 'E412:')
495 call assert_fails('hi link a b c', 'E413:')
496 call assert_fails('hi XXX =', 'E415:')
497 call assert_fails('hi XXX cterm', 'E416:')
498 call assert_fails('hi XXX cterm=', 'E417:')
499 call assert_fails('hi XXX cterm=DoesNotExist', 'E418:')
500 call assert_fails('hi XXX ctermfg=DoesNotExist', 'E421:')
501 call assert_fails('hi XXX xxx=White', 'E423:')
502endfunc
503
Bram Moolenaar1615b362017-06-04 21:06:09 +0200504func Test_bg_detection()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200505 CheckNotGui
506
Dominique Pelle923dce22021-11-21 11:36:04 +0000507 " auto-detection of &bg, make sure it isn't set anywhere before this test
Bram Moolenaar1615b362017-06-04 21:06:09 +0200508 hi Normal ctermbg=0
509 call assert_equal('dark', &bg)
510 hi Normal ctermbg=4
511 call assert_equal('dark', &bg)
512 hi Normal ctermbg=12
513 call assert_equal('light', &bg)
514 hi Normal ctermbg=15
515 call assert_equal('light', &bg)
516
Bram Moolenaar0b2eef22017-06-27 15:43:49 +0200517 " manually-set &bg takes precedence over auto-detection
Bram Moolenaar1615b362017-06-04 21:06:09 +0200518 set bg=light
519 hi Normal ctermbg=4
520 call assert_equal('light', &bg)
521 set bg=dark
522 hi Normal ctermbg=12
523 call assert_equal('dark', &bg)
Bram Moolenaar6acadda2018-02-24 16:51:32 +0100524
525 hi Normal ctermbg=NONE
Bram Moolenaar1615b362017-06-04 21:06:09 +0200526endfunc
Bram Moolenaar06f1ed22017-06-18 22:41:03 +0200527
528func Test_syntax_hangs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200529 CheckFunction reltimefloat
530 CheckFeature syntax
Bram Moolenaar06f1ed22017-06-18 22:41:03 +0200531
Paul Ollis65745772022-06-05 16:55:54 +0100532 " So, it turns out the Windows 7 implements TimerQueue timers differently
533 " and they can expire *before* the requested time has elapsed. So allow for
534 " the timeout occurring after 80 ms (5 * 16 (the typical clock tick)).
535 if has("win32")
536 let min_timeout = 0.08
537 else
538 let min_timeout = 0.1
539 endif
540
Bram Moolenaar06f1ed22017-06-18 22:41:03 +0200541 " This pattern takes a long time to match, it should timeout.
542 new
543 call setline(1, ['aaa', repeat('abc ', 1000), 'ccc'])
544 let start = reltime()
545 set nolazyredraw redrawtime=101
546 syn match Error /\%#=1a*.*X\@<=b*/
547 redraw
548 let elapsed = reltimefloat(reltime(start))
Bram Moolenaar620aa8e2022-06-18 16:05:32 +0100549 call assert_inrange(min_timeout, 1.0, elapsed)
Bram Moolenaar06f1ed22017-06-18 22:41:03 +0200550
551 " second time syntax HL is disabled
552 let start = reltime()
553 redraw
554 let elapsed = reltimefloat(reltime(start))
Bram Moolenaar620aa8e2022-06-18 16:05:32 +0100555 call assert_inrange(0, 0.1, elapsed)
Bram Moolenaar06f1ed22017-06-18 22:41:03 +0200556
557 " after CTRL-L the timeout flag is reset
558 let start = reltime()
559 exe "normal \<C-L>"
560 redraw
561 let elapsed = reltimefloat(reltime(start))
Bram Moolenaar620aa8e2022-06-18 16:05:32 +0100562 call assert_inrange(min_timeout, 1.0, elapsed)
Bram Moolenaar06f1ed22017-06-18 22:41:03 +0200563
564 set redrawtime&
565 bwipe!
566endfunc
Bram Moolenaar4d785892017-06-22 22:00:50 +0200567
Bram Moolenaar4d785892017-06-22 22:00:50 +0200568func Test_conceal()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200569 CheckFeature conceal
Bram Moolenaar4d785892017-06-22 22:00:50 +0200570
571 new
572 call setline(1, ['', '123456'])
573 syn match test23 "23" conceal cchar=X
574 syn match test45 "45" conceal
575
576 set conceallevel=0
577 call assert_equal('123456 ', ScreenLines(2, 7)[0])
Bram Moolenaarcc0750d2017-06-24 22:29:24 +0200578 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 +0200579
580 set conceallevel=1
581 call assert_equal('1X 6 ', ScreenLines(2, 7)[0])
Bram Moolenaarcc0750d2017-06-24 22:29:24 +0200582 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 +0200583
584 set conceallevel=1
585 set listchars=conceal:Y
Bram Moolenaarcc0750d2017-06-24 22:29:24 +0200586 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 +0200587 call assert_equal('1XY6 ', ScreenLines(2, 7)[0])
588
589 set conceallevel=2
590 call assert_match('1X6 ', ScreenLines(2, 7)[0])
Bram Moolenaarcc0750d2017-06-24 22:29:24 +0200591 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 +0200592
593 set conceallevel=3
594 call assert_match('16 ', ScreenLines(2, 7)[0])
Bram Moolenaarcc0750d2017-06-24 22:29:24 +0200595 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 +0200596
Bram Moolenaarfbf21222020-04-19 18:31:25 +0200597 call AssertFails("syntax match Entity '&amp;' conceal cchar=\<Tab>", 'E844:')
598
Bram Moolenaar4d785892017-06-22 22:00:50 +0200599 syn clear
600 set conceallevel&
601 bw!
602endfunc
Bram Moolenaar0b2eef22017-06-27 15:43:49 +0200603
Bram Moolenaarda650582018-02-20 15:51:40 +0100604func Test_synstack_synIDtrans()
Bram Moolenaar0b2eef22017-06-27 15:43:49 +0200605 new
606 setfiletype c
607 syntax on
608 call setline(1, ' /* A comment with a TODO */')
609
610 call assert_equal([], synstack(1, 1))
611
612 norm f/
Bram Moolenaara74e4942019-08-04 17:35:53 +0200613 eval synstack(line("."), col("."))->map('synIDattr(v:val, "name")')->assert_equal(['cComment', 'cCommentStart'])
614 eval synstack(line("."), col("."))->map('synIDattr(synIDtrans(v:val), "name")')->assert_equal(['Comment', 'Comment'])
Bram Moolenaar0b2eef22017-06-27 15:43:49 +0200615
616 norm fA
617 call assert_equal(['cComment'], map(synstack(line("."), col(".")), 'synIDattr(v:val, "name")'))
618 call assert_equal(['Comment'], map(synstack(line("."), col(".")), 'synIDattr(synIDtrans(v:val), "name")'))
619
620 norm fT
621 call assert_equal(['cComment', 'cTodo'], map(synstack(line("."), col(".")), 'synIDattr(v:val, "name")'))
622 call assert_equal(['Comment', 'Todo'], map(synstack(line("."), col(".")), 'synIDattr(synIDtrans(v:val), "name")'))
623
Bram Moolenaar0e05de42020-03-25 22:23:46 +0100624 call assert_fails("let n=synIDtrans([])", 'E745:')
625
Bram Moolenaar0b2eef22017-06-27 15:43:49 +0200626 syn clear
627 bw!
628endfunc
Bram Moolenaarda650582018-02-20 15:51:40 +0100629
630" Check highlighting for a small piece of C code with a screen dump.
631func Test_syntax_c()
Drew Vogelea67ba72025-05-07 22:05:17 +0200632 CheckScreendump
Bram Moolenaar494e9062020-05-31 21:28:02 +0200633 CheckRunVimInTerminal
Bram Moolenaarda650582018-02-20 15:51:40 +0100634 call writefile([
635 \ '/* comment line at the top */',
Bram Moolenaar83e9a1c2019-10-20 14:51:23 +0200636 \ 'int main(int argc, char **argv) { // another comment',
Bram Moolenaarda650582018-02-20 15:51:40 +0100637 \ '#if 0',
638 \ ' int not_used;',
639 \ '#else',
640 \ ' int used;',
641 \ '#endif',
642 \ ' printf("Just an example piece of C code\n");',
643 \ ' return 0x0ff;',
644 \ '}',
Bram Moolenaar82260af2019-10-20 13:16:22 +0200645 \ "\t\t ",
Bram Moolenaarda650582018-02-20 15:51:40 +0100646 \ ' static void',
647 \ 'myFunction(const double count, struct nothing, long there) {',
Bram Moolenaar84590062019-10-18 23:12:20 +0200648 \ "\t// 123: nothing to endif here",
Bram Moolenaar9115c612019-10-16 16:57:06 +0200649 \ "\tfor (int i = 0; i < count; ++i) {",
650 \ "\t break;",
651 \ "\t}",
Bram Moolenaarbbfd1562019-10-19 20:38:15 +0200652 \ "\tNote: asdf",
Bram Moolenaarda650582018-02-20 15:51:40 +0100653 \ '}',
Bram Moolenaar56564962022-10-10 22:39:42 +0100654 \ ], 'Xtest.c', 'D')
Paul Ollis65745772022-06-05 16:55:54 +0100655
Bram Moolenaarb7ea7cb2018-02-24 14:38:51 +0100656 " This makes the default for 'background' use "dark", check that the
657 " response to t_RB corrects it to "light".
658 let $COLORFGBG = '15;0'
659
Bram Moolenaar83e9a1c2019-10-20 14:51:23 +0200660 let buf = RunVimInTerminal('Xtest.c', {})
Bram Moolenaarbbfd1562019-10-19 20:38:15 +0200661 call term_sendkeys(buf, ":syn keyword Search Note\r")
Bram Moolenaar82260af2019-10-20 13:16:22 +0200662 call term_sendkeys(buf, ":syn match Error /^\\s\\+$/\r")
Bram Moolenaar84590062019-10-18 23:12:20 +0200663 call term_sendkeys(buf, ":set hlsearch\r")
664 call term_sendkeys(buf, "/endif\r")
665 call term_sendkeys(buf, "vjfC")
Bram Moolenaar6bb2cdf2018-02-24 19:53:53 +0100666 call VerifyScreenDump(buf, 'Test_syntax_c_01', {})
Bram Moolenaar84590062019-10-18 23:12:20 +0200667
668 call term_sendkeys(buf, "\<Esc>")
Bram Moolenaarda650582018-02-20 15:51:40 +0100669 call StopVimInTerminal(buf)
670
Bram Moolenaarb7ea7cb2018-02-24 14:38:51 +0100671 let $COLORFGBG = ''
Bram Moolenaarda650582018-02-20 15:51:40 +0100672endfun
Bram Moolenaarbcf94422018-06-23 14:21:42 +0200673
Dominique Pelle354b23a2021-12-17 17:32:29 +0000674" Test \z(...) along with \z1
675func Test_syn_zsub()
676 new
677 syntax on
678 call setline(1, 'xxx start foo xxx not end foo xxx end foo xxx')
679 let l:expected = ' ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ '
680
681 for l:re in [0, 1, 2]
682 " Example taken from :help :syn-ext-match
683 syntax region Z start="start \z(\I\i*\)" skip="not end \z1" end="end \z1"
684 eval AssertHighlightGroups(1, 1, l:expected, 1, 'regexp=' .. l:re)
685 syntax clear Z
686 endfor
687
688 set re&
689 bw!
690endfunc
691
Bram Moolenaarbcf94422018-06-23 14:21:42 +0200692" Using \z() in a region with NFA failing should not crash.
693func Test_syn_wrong_z_one()
694 new
695 call setline(1, ['just some text', 'with foo and bar to match with'])
696 syn region FooBar start="foo\z(.*\)bar" end="\z1"
697 call test_override("nfa_fail", 1)
698 redraw!
699 redraw!
700 call test_override("ALL", 0)
701 bwipe!
702endfunc
Bram Moolenaarc7f1e402019-08-03 13:29:46 +0200703
704func Test_syntax_after_bufdo()
Bram Moolenaar56564962022-10-10 22:39:42 +0100705 call writefile(['/* aaa comment */'], 'Xaaa.c', 'D')
706 call writefile(['/* bbb comment */'], 'Xbbb.c', 'D')
707 call writefile(['/* ccc comment */'], 'Xccc.c', 'D')
708 call writefile(['/* ddd comment */'], 'Xddd.c', 'D')
Bram Moolenaarc7f1e402019-08-03 13:29:46 +0200709
710 let bnr = bufnr('%')
711 new Xaaa.c
712 badd Xbbb.c
713 badd Xccc.c
714 badd Xddd.c
715 exe "bwipe " . bnr
716 let l = []
717 bufdo call add(l, bufnr('%'))
718 call assert_equal(4, len(l))
719
720 syntax on
721
722 " This used to only enable syntax HL in the last buffer.
723 bufdo tab split
724 tabrewind
725 for tab in range(1, 4)
726 norm fm
727 call assert_equal(['cComment'], map(synstack(line("."), col(".")), 'synIDattr(v:val, "name")'))
728 tabnext
729 endfor
730
731 bwipe! Xaaa.c
732 bwipe! Xbbb.c
733 bwipe! Xccc.c
734 bwipe! Xddd.c
735 syntax off
Bram Moolenaarc7f1e402019-08-03 13:29:46 +0200736endfunc
Bram Moolenaar0e05de42020-03-25 22:23:46 +0100737
Bram Moolenaare35a52a2020-05-31 19:48:53 +0200738func Test_syntax_foldlevel()
739 new
740 call setline(1, [
741 \ 'void f(int a)',
742 \ '{',
743 \ ' if (a == 1) {',
744 \ ' a = 0;',
745 \ ' } else if (a == 2) {',
746 \ ' a = 1;',
747 \ ' } else {',
748 \ ' a = 2;',
749 \ ' }',
750 \ ' if (a > 0) {',
751 \ ' if (a == 1) {',
752 \ ' a = 0;',
753 \ ' } /* missing newline */ } /* end of outer if */ else {',
754 \ ' a = 1;',
755 \ ' }',
756 \ ' if (a == 1)',
757 \ ' {',
758 \ ' a = 0;',
759 \ ' }',
760 \ ' else if (a == 2)',
761 \ ' {',
762 \ ' a = 1;',
763 \ ' }',
764 \ ' else',
765 \ ' {',
766 \ ' a = 2;',
767 \ ' }',
768 \ '}',
769 \ ])
770 setfiletype c
771 syntax on
772 set foldmethod=syntax
773
Bram Moolenaare2e40752020-09-04 21:18:46 +0200774 call assert_fails('syn foldlevel start start', 'E390:')
775 call assert_fails('syn foldlevel not_an_option', 'E390:')
Bram Moolenaare35a52a2020-05-31 19:48:53 +0200776
777 set foldlevel=1
778
779 syn foldlevel start
780 redir @c
781 syn foldlevel
782 redir END
783 call assert_equal("\nsyntax foldlevel start", @c)
784 syn sync fromstart
Bram Moolenaar99502802020-11-18 16:53:23 +0100785 call assert_match('from the first line$', execute('syn sync'))
Bram Moolenaare35a52a2020-05-31 19:48:53 +0200786 let a = map(range(3,9), 'foldclosed(v:val)')
787 call assert_equal([3,3,3,3,3,3,3], a) " attached cascade folds together
788 let a = map(range(10,15), 'foldclosed(v:val)')
789 call assert_equal([10,10,10,10,10,10], a) " over-attached 'else' hidden
790 let a = map(range(16,27), 'foldclosed(v:val)')
791 let unattached_results = [-1,17,17,17,-1,21,21,21,-1,25,25,25]
792 call assert_equal(unattached_results, a) " unattached cascade folds separately
793
794 syn foldlevel minimum
795 redir @c
796 syn foldlevel
797 redir END
798 call assert_equal("\nsyntax foldlevel minimum", @c)
799 syn sync fromstart
800 let a = map(range(3,9), 'foldclosed(v:val)')
801 call assert_equal([3,3,5,5,7,7,7], a) " attached cascade folds separately
802 let a = map(range(10,15), 'foldclosed(v:val)')
803 call assert_equal([10,10,10,13,13,13], a) " over-attached 'else' visible
804 let a = map(range(16,27), 'foldclosed(v:val)')
805 call assert_equal(unattached_results, a) " unattached cascade folds separately
806
807 set foldlevel=2
808
809 syn foldlevel start
810 syn sync fromstart
811 let a = map(range(11,14), 'foldclosed(v:val)')
812 call assert_equal([11,11,11,-1], a) " over-attached 'else' hidden
813
814 syn foldlevel minimum
815 syn sync fromstart
816 let a = map(range(11,14), 'foldclosed(v:val)')
817 call assert_equal([11,11,-1,-1], a) " over-attached 'else' visible
818
819 quit!
820endfunc
821
Bram Moolenaaradc17a52020-06-06 18:37:51 +0200822func Test_search_syntax_skip()
823 new
824 let lines =<< trim END
825
826 /* This is VIM */
827 Another Text for VIM
828 let a = "VIM"
829 END
830 call setline(1, lines)
831 syntax on
832 syntax match Comment "^/\*.*\*/"
833 syntax match String '".*"'
834
835 " Skip argument using string evaluation.
836 1
837 call search('VIM', 'w', '', 0, 'synIDattr(synID(line("."), col("."), 1), "name") =~? "comment"')
838 call assert_equal('Another Text for VIM', getline('.'))
zeertzjq180246c2022-06-23 12:04:46 +0100839
Bram Moolenaaradc17a52020-06-06 18:37:51 +0200840 1
zeertzjq180246c2022-06-23 12:04:46 +0100841 call search('VIM', 'cw', '', 0, 'synIDattr(synID(line("."), col("."), 1), "name") !~? "string"')
Bram Moolenaaradc17a52020-06-06 18:37:51 +0200842 call assert_equal(' let a = "VIM"', getline('.'))
843
844 " Skip argument using Lambda.
845 1
846 call search('VIM', 'w', '', 0, { -> synIDattr(synID(line("."), col("."), 1), "name") =~? "comment"})
847 call assert_equal('Another Text for VIM', getline('.'))
848
849 1
zeertzjq180246c2022-06-23 12:04:46 +0100850 call search('VIM', 'cw', '', 0, { -> synIDattr(synID(line("."), col("."), 1), "name") !~? "string"})
Bram Moolenaaradc17a52020-06-06 18:37:51 +0200851 call assert_equal(' let a = "VIM"', getline('.'))
852
853 " Skip argument using funcref.
854 func InComment()
855 return synIDattr(synID(line("."), col("."), 1), "name") =~? "comment"
856 endfunc
zeertzjq180246c2022-06-23 12:04:46 +0100857 func NotInString()
Bram Moolenaaradc17a52020-06-06 18:37:51 +0200858 return synIDattr(synID(line("."), col("."), 1), "name") !~? "string"
859 endfunc
zeertzjq180246c2022-06-23 12:04:46 +0100860
Bram Moolenaaradc17a52020-06-06 18:37:51 +0200861 1
862 call search('VIM', 'w', '', 0, function('InComment'))
863 call assert_equal('Another Text for VIM', getline('.'))
864
865 1
zeertzjq180246c2022-06-23 12:04:46 +0100866 call search('VIM', 'cw', '', 0, function('NotInString'))
Bram Moolenaaradc17a52020-06-06 18:37:51 +0200867 call assert_equal(' let a = "VIM"', getline('.'))
868
869 delfunc InComment
zeertzjq180246c2022-06-23 12:04:46 +0100870 delfunc NotInString
Bram Moolenaaradc17a52020-06-06 18:37:51 +0200871 bwipe!
872endfunc
873
Bram Moolenaarb46f57e2020-11-29 14:11:41 +0100874func Test_syn_contained_transparent()
875 " Comments starting with "Regression:" show the result when the highlighting
876 " span of the containing item is assigned to the contained region.
877 syntax on
878
879 let l:case = "Transparent region contained in region"
880 new
881 syntax region X start=/\[/ end=/\]/ contained transparent
882 syntax region Y start=/(/ end=/)/ contains=X
883
884 call setline(1, "==(--[~~]--)==")
885 let l:expected = " YYYYYYYYYY "
886 eval AssertHighlightGroups(1, 1, l:expected, 1, l:case)
887 syntax clear Y X
888 bw!
889
890 let l:case = "Transparent region extends region"
891 new
892 syntax region X start=/\[/ end=/\]/ contained transparent
893 syntax region Y start=/(/ end=/)/ end=/e/ contains=X
894
895 call setline(1, "==(--[~~e~~]--)==")
896 let l:expected = " YYYYYYYYYYYYY "
897 " Regression: " YYYYYYY YYY "
898 eval AssertHighlightGroups(1, 1, l:expected, 1, l:case)
899 syntax clear Y X
900 bw!
901
902 let l:case = "Nested transparent regions extend region"
903 new
904 syntax region X start=/\[/ end=/\]/ contained transparent
905 syntax region Y start=/(/ end=/)/ end=/e/ contains=X
906
907 call setline(1, "==(--[~~e~~[~~e~~]~~e~~]--)==")
908 let l:expected = " YYYYYYYYYYYYYYYYYYYYYYYYY "
909 " Regression: " YYYYYYY YYYYYYYYY "
910 eval AssertHighlightGroups(1, 1, l:expected, 1, l:case)
911 syntax clear Y X
912 bw!
913
914 let l:case = "Transparent region contained in match"
915 new
916 syntax region X start=/\[/ end=/\]/ contained transparent
917 syntax match Y /(.\{-})/ contains=X
918
919 call setline(1, "==(--[~~]--)==")
920 let l:expected = " YYYYYYYYYY "
921 eval AssertHighlightGroups(1, 1, l:expected, 1, l:case)
922 syntax clear Y X
923 bw!
924
925 let l:case = "Transparent region extends match"
926 new
927 syntax region X start=/\[/ end=/\]/ contained transparent
928 syntax match Y /(.\{-}[e)]/ contains=X
929
930 call setline(1, "==(--[~~e~~]--)==")
931 let l:expected = " YYYYYYYYYY "
932 " Regression: " YYYYYYY "
933 eval AssertHighlightGroups(1, 1, l:expected, 1, l:case)
934 syntax clear Y X
935 bw!
936
937 let l:case = "Nested transparent regions extend match"
938 new
939 syntax region X start=/\[/ end=/\]/ contained transparent
940 syntax match Y /(.\{-}[e)]/ contains=X
941
942 call setline(1, "==(--[~~e~~[~~e~~]~~e~~]--)==")
943 let l:expected = " YYYYYYYYYYYYYYYYYYYYYY "
944 " Regression: " YYYYYYY YYYYYY "
945 eval AssertHighlightGroups(1, 1, l:expected, 1, l:case)
946 syntax clear Y X
947 bw!
948endfunc
949
Bram Moolenaar2e240bd2021-04-14 11:15:08 +0200950func Test_syn_include_contains_TOP()
Theodore Duboisf50d5362025-02-05 23:59:25 +0100951 let l:case = "TOP in included syntax refers to top level of that included syntax"
Bram Moolenaar2e240bd2021-04-14 11:15:08 +0200952 new
953 syntax include @INCLUDED syntax/c.vim
954 syntax region FencedCodeBlockC start=/```c/ end=/```/ contains=@INCLUDED
955
956 call setline(1, ['```c', '#if 0', 'int', '#else', 'int', '#endif', '```' ])
957 let l:expected = ["cCppOutIf2"]
958 eval AssertHighlightGroups(3, 1, l:expected, 1)
959 " cCppOutElse has contains=TOP
960 let l:expected = ["cType"]
961 eval AssertHighlightGroups(5, 1, l:expected, 1, l:case)
962 syntax clear
963 bw!
964endfunc
965
Theodore Duboisf50d5362025-02-05 23:59:25 +0100966func Test_syn_include_contains_TOP_excluding()
967 new
968 syntax include @INCLUDED syntax/c.vim
969 syntax region FencedCodeBlockC start=/```c/ end=/```/ contains=@INCLUDED
970
971 call setline(1, ['```c', '#if 0', 'int', '#else', 'int', '#if', '#endif', '```' ])
972 let l:expected = ["cCppOutElse", "cConditional"]
973 eval AssertHighlightGroups(6, 1, l:expected, 1)
974 syntax clear
975 bw!
976endfunc
977
zeertzjqca7e86c2022-04-16 16:49:24 +0100978" This was using freed memory
979func Test_WinEnter_synstack_synID()
980 autocmd WinEnter * call synstack(line("."), col("."))
981 autocmd WinEnter * call synID(line('.'), col('.') - 1, 1)
982 call setline(1, 'aaaaa')
983 normal! $
984 new
985 close
986
987 au! WinEnter
988 bw!
989endfunc
990
Bram Moolenaar2e240bd2021-04-14 11:15:08 +0200991
Bram Moolenaar0e05de42020-03-25 22:23:46 +0100992" vim: shiftwidth=2 sts=2 expandtab