Mercurial > vim
changeset 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 | 6c52f2ebe4e7 |
children | c7b95b2427fb |
files | src/testdir/test_syntax.vim src/version.c |
diffstat | 2 files changed, 48 insertions(+), 51 deletions(-) [+] |
line wrap: on
line diff
--- a/src/testdir/test_syntax.vim +++ b/src/testdir/test_syntax.vim @@ -320,6 +320,18 @@ func Test_syntax_arg_skipped() syn clear endfunc +" Check for an error. Used when multiple errors are thrown and we are checking +" for an earliest error. +func AssertFails(cmd, errcode) + let save_exception = '' + try + exe a:cmd + catch + let save_exception = v:exception + endtry + call assert_match(a:errcode, save_exception) +endfunc + func Test_syntax_invalid_arg() call assert_fails('syntax case asdf', 'E390:') if has('conceal') @@ -327,69 +339,49 @@ func Test_syntax_invalid_arg() endif call assert_fails('syntax spell asdf', 'E390:') call assert_fails('syntax clear @ABCD', 'E391:') - call assert_fails('syntax include @Xxx', 'E397:') - call assert_fails('syntax region X start="{"', 'E399:') + call assert_fails('syntax include random_file', 'E484:') + call assert_fails('syntax include <afile>', 'E495:') call assert_fails('syntax sync x', 'E404:') call assert_fails('syntax keyword Abc a[', 'E789:') call assert_fails('syntax keyword Abc a[bc]d', 'E890:') - - let caught_393 = 0 - try - syntax keyword cMyItem grouphere G1 - catch /E393:/ - let caught_393 = 1 - endtry - call assert_equal(1, caught_393) - - let caught_394 = 0 - try - syntax sync match Abc grouphere MyItem "abc"' - catch /E394:/ - let caught_394 = 1 - endtry - call assert_equal(1, caught_394) + call assert_fails('syntax cluster Abc add=A add=', 'E475:') " Test for too many \z\( and unmatched \z\( " Not able to use assert_fails() here because both E50:/E879: and E475: " messages are emitted. set regexpengine=1 - let caught_52 = 0 - try - syntax region MyRegion start='\z\(' end='\*/' - catch /E52:/ - let caught_52 = 1 - endtry - call assert_equal(1, caught_52) + call AssertFails("syntax region MyRegion start='\\z\\(' end='\\*/'", 'E52:') - let caught_50 = 0 - try - let cmd = "syntax region MyRegion start='" - let cmd ..= repeat("\\z\\(.\\)", 10) .. "' end='\*/'" - exe cmd - catch /E50:/ - let caught_50 = 1 - endtry - call assert_equal(1, caught_50) + let cmd = "syntax region MyRegion start='" + let cmd ..= repeat("\\z\\(.\\)", 10) .. "' end='\*/'" + call AssertFails(cmd, 'E50:') set regexpengine=2 - let caught_54 = 0 - try - syntax region MyRegion start='\z\(' end='\*/' - catch /E54:/ - let caught_54 = 1 - endtry - call assert_equal(1, caught_54) + call AssertFails("syntax region MyRegion start='\\z\\(' end='\\*/'", 'E54:') + + let cmd = "syntax region MyRegion start='" + let cmd ..= repeat("\\z\\(.\\)", 10) .. "' end='\*/'" + call AssertFails(cmd, 'E879:') + set regexpengine& - let caught_879 = 0 - try - let cmd = "syntax region MyRegion start='" - let cmd ..= repeat("\\z\\(.\\)", 10) .. "' end='\*/'" - exe cmd - catch /E879:/ - let caught_879 = 1 - endtry - call assert_equal(1, caught_879) - set regexpengine& + call AssertFails('syntax keyword cMyItem grouphere G1', 'E393:') + call AssertFails('syntax sync match Abc grouphere MyItem "abc"', 'E394:') + call AssertFails('syn keyword Type contains int', 'E395:') + call assert_fails('syntax include @Xxx', 'E397:') + call AssertFails('syntax region X start', 'E398:') + call assert_fails('syntax region X start="{"', 'E399:') + call AssertFails('syntax cluster contains=Abc', 'E400:') + call AssertFails("syntax match Character /'.'", 'E401:') + call AssertFails("syntax match Character /'.'/a", 'E402:') + call assert_fails('syntax sync linecont /pat', 'E404:') + call assert_fails('syntax sync linecont', 'E404:') + call assert_fails('syntax sync linecont /pat1/ linecont /pat2/', 'E403:') + call assert_fails('syntax sync minlines=a', 'E404:') + call AssertFails('syntax match ABC /x/ contains=', 'E406:') + call AssertFails("syntax match Character contains /'.'/", 'E405:') + call AssertFails('syntax match ccFoo "Foo" nextgroup=ALLBUT,F', 'E407:') + call AssertFails('syntax region Block start="{" contains=F,ALLBUT', 'E408:') + call AssertFails("syntax match Characters contains=a.*x /'.'/", 'E409:') endfunc func Test_syn_sync() @@ -417,6 +409,7 @@ func Test_syn_clear() hi clear Foo call assert_equal('Foo', synIDattr(hlID("Foo"), "name")) hi clear Bar + call assert_fails('syntax clear invalid_syngroup', 'E28:') endfunc func Test_invalid_name() @@ -565,6 +558,8 @@ func Test_conceal() call assert_match('16 ', ScreenLines(2, 7)[0]) call assert_equal([[0, '', 0], [1, '', 1], [1, '', 1], [1, '', 2], [1, '', 2], [0, '', 0]], map(range(1, 6), 'synconcealed(2, v:val)')) + call AssertFails("syntax match Entity '&' conceal cchar=\<Tab>", 'E844:') + syn clear set conceallevel& bw!