Mercurial > vim
comparison src/testdir/test_syntax.vim @ 20101:64ea318298b7 v8.2.0606
patch 8.2.0606: several syntax HL errors not checked
Commit: https://github.com/vim/vim/commit/fbf2122cf920a89274ffbefaaeb6c5eeacf5187b
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Apr 19 18:31:25 2020 +0200
patch 8.2.0606: several syntax HL errors not checked
Problem: Several syntax HL errors not checked.
Solution: Add tests. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/5954)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 19 Apr 2020 18:45:03 +0200 |
parents | 9cbe3a4f1492 |
children | e82996ad131f |
comparison
equal
deleted
inserted
replaced
20100:6c52f2ebe4e7 | 20101:64ea318298b7 |
---|---|
318 call assert_notmatch('on C-style comments', execute('syntax sync')) | 318 call assert_notmatch('on C-style comments', execute('syntax sync')) |
319 | 319 |
320 syn clear | 320 syn clear |
321 endfunc | 321 endfunc |
322 | 322 |
323 " Check for an error. Used when multiple errors are thrown and we are checking | |
324 " for an earliest error. | |
325 func AssertFails(cmd, errcode) | |
326 let save_exception = '' | |
327 try | |
328 exe a:cmd | |
329 catch | |
330 let save_exception = v:exception | |
331 endtry | |
332 call assert_match(a:errcode, save_exception) | |
333 endfunc | |
334 | |
323 func Test_syntax_invalid_arg() | 335 func Test_syntax_invalid_arg() |
324 call assert_fails('syntax case asdf', 'E390:') | 336 call assert_fails('syntax case asdf', 'E390:') |
325 if has('conceal') | 337 if has('conceal') |
326 call assert_fails('syntax conceal asdf', 'E390:') | 338 call assert_fails('syntax conceal asdf', 'E390:') |
327 endif | 339 endif |
328 call assert_fails('syntax spell asdf', 'E390:') | 340 call assert_fails('syntax spell asdf', 'E390:') |
329 call assert_fails('syntax clear @ABCD', 'E391:') | 341 call assert_fails('syntax clear @ABCD', 'E391:') |
330 call assert_fails('syntax include @Xxx', 'E397:') | 342 call assert_fails('syntax include random_file', 'E484:') |
331 call assert_fails('syntax region X start="{"', 'E399:') | 343 call assert_fails('syntax include <afile>', 'E495:') |
332 call assert_fails('syntax sync x', 'E404:') | 344 call assert_fails('syntax sync x', 'E404:') |
333 call assert_fails('syntax keyword Abc a[', 'E789:') | 345 call assert_fails('syntax keyword Abc a[', 'E789:') |
334 call assert_fails('syntax keyword Abc a[bc]d', 'E890:') | 346 call assert_fails('syntax keyword Abc a[bc]d', 'E890:') |
335 | 347 call assert_fails('syntax cluster Abc add=A add=', 'E475:') |
336 let caught_393 = 0 | |
337 try | |
338 syntax keyword cMyItem grouphere G1 | |
339 catch /E393:/ | |
340 let caught_393 = 1 | |
341 endtry | |
342 call assert_equal(1, caught_393) | |
343 | |
344 let caught_394 = 0 | |
345 try | |
346 syntax sync match Abc grouphere MyItem "abc"' | |
347 catch /E394:/ | |
348 let caught_394 = 1 | |
349 endtry | |
350 call assert_equal(1, caught_394) | |
351 | 348 |
352 " Test for too many \z\( and unmatched \z\( | 349 " Test for too many \z\( and unmatched \z\( |
353 " Not able to use assert_fails() here because both E50:/E879: and E475: | 350 " Not able to use assert_fails() here because both E50:/E879: and E475: |
354 " messages are emitted. | 351 " messages are emitted. |
355 set regexpengine=1 | 352 set regexpengine=1 |
356 let caught_52 = 0 | 353 call AssertFails("syntax region MyRegion start='\\z\\(' end='\\*/'", 'E52:') |
357 try | 354 |
358 syntax region MyRegion start='\z\(' end='\*/' | 355 let cmd = "syntax region MyRegion start='" |
359 catch /E52:/ | 356 let cmd ..= repeat("\\z\\(.\\)", 10) .. "' end='\*/'" |
360 let caught_52 = 1 | 357 call AssertFails(cmd, 'E50:') |
361 endtry | |
362 call assert_equal(1, caught_52) | |
363 | |
364 let caught_50 = 0 | |
365 try | |
366 let cmd = "syntax region MyRegion start='" | |
367 let cmd ..= repeat("\\z\\(.\\)", 10) .. "' end='\*/'" | |
368 exe cmd | |
369 catch /E50:/ | |
370 let caught_50 = 1 | |
371 endtry | |
372 call assert_equal(1, caught_50) | |
373 | 358 |
374 set regexpengine=2 | 359 set regexpengine=2 |
375 let caught_54 = 0 | 360 call AssertFails("syntax region MyRegion start='\\z\\(' end='\\*/'", 'E54:') |
376 try | 361 |
377 syntax region MyRegion start='\z\(' end='\*/' | 362 let cmd = "syntax region MyRegion start='" |
378 catch /E54:/ | 363 let cmd ..= repeat("\\z\\(.\\)", 10) .. "' end='\*/'" |
379 let caught_54 = 1 | 364 call AssertFails(cmd, 'E879:') |
380 endtry | |
381 call assert_equal(1, caught_54) | |
382 | |
383 let caught_879 = 0 | |
384 try | |
385 let cmd = "syntax region MyRegion start='" | |
386 let cmd ..= repeat("\\z\\(.\\)", 10) .. "' end='\*/'" | |
387 exe cmd | |
388 catch /E879:/ | |
389 let caught_879 = 1 | |
390 endtry | |
391 call assert_equal(1, caught_879) | |
392 set regexpengine& | 365 set regexpengine& |
366 | |
367 call AssertFails('syntax keyword cMyItem grouphere G1', 'E393:') | |
368 call AssertFails('syntax sync match Abc grouphere MyItem "abc"', 'E394:') | |
369 call AssertFails('syn keyword Type contains int', 'E395:') | |
370 call assert_fails('syntax include @Xxx', 'E397:') | |
371 call AssertFails('syntax region X start', 'E398:') | |
372 call assert_fails('syntax region X start="{"', 'E399:') | |
373 call AssertFails('syntax cluster contains=Abc', 'E400:') | |
374 call AssertFails("syntax match Character /'.'", 'E401:') | |
375 call AssertFails("syntax match Character /'.'/a", 'E402:') | |
376 call assert_fails('syntax sync linecont /pat', 'E404:') | |
377 call assert_fails('syntax sync linecont', 'E404:') | |
378 call assert_fails('syntax sync linecont /pat1/ linecont /pat2/', 'E403:') | |
379 call assert_fails('syntax sync minlines=a', 'E404:') | |
380 call AssertFails('syntax match ABC /x/ contains=', 'E406:') | |
381 call AssertFails("syntax match Character contains /'.'/", 'E405:') | |
382 call AssertFails('syntax match ccFoo "Foo" nextgroup=ALLBUT,F', 'E407:') | |
383 call AssertFails('syntax region Block start="{" contains=F,ALLBUT', 'E408:') | |
384 call AssertFails("syntax match Characters contains=a.*x /'.'/", 'E409:') | |
393 endfunc | 385 endfunc |
394 | 386 |
395 func Test_syn_sync() | 387 func Test_syn_sync() |
396 syntax region HereGroup start=/this/ end=/that/ | 388 syntax region HereGroup start=/this/ end=/that/ |
397 syntax sync match SyncHere grouphere HereGroup "pattern" | 389 syntax sync match SyncHere grouphere HereGroup "pattern" |
415 call assert_notmatch('Foo', execute('syntax')) | 407 call assert_notmatch('Foo', execute('syntax')) |
416 call assert_notmatch('Bar', execute('syntax')) | 408 call assert_notmatch('Bar', execute('syntax')) |
417 hi clear Foo | 409 hi clear Foo |
418 call assert_equal('Foo', synIDattr(hlID("Foo"), "name")) | 410 call assert_equal('Foo', synIDattr(hlID("Foo"), "name")) |
419 hi clear Bar | 411 hi clear Bar |
412 call assert_fails('syntax clear invalid_syngroup', 'E28:') | |
420 endfunc | 413 endfunc |
421 | 414 |
422 func Test_invalid_name() | 415 func Test_invalid_name() |
423 syn clear | 416 syn clear |
424 syn keyword Nop yes | 417 syn keyword Nop yes |
562 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)')) | 555 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)')) |
563 | 556 |
564 set conceallevel=3 | 557 set conceallevel=3 |
565 call assert_match('16 ', ScreenLines(2, 7)[0]) | 558 call assert_match('16 ', ScreenLines(2, 7)[0]) |
566 call assert_equal([[0, '', 0], [1, '', 1], [1, '', 1], [1, '', 2], [1, '', 2], [0, '', 0]], map(range(1, 6), 'synconcealed(2, v:val)')) | 559 call assert_equal([[0, '', 0], [1, '', 1], [1, '', 1], [1, '', 2], [1, '', 2], [0, '', 0]], map(range(1, 6), 'synconcealed(2, v:val)')) |
560 | |
561 call AssertFails("syntax match Entity '&' conceal cchar=\<Tab>", 'E844:') | |
567 | 562 |
568 syn clear | 563 syn clear |
569 set conceallevel& | 564 set conceallevel& |
570 bw! | 565 bw! |
571 endfunc | 566 endfunc |