0
0
mirror of https://github.com/vim/vim.git synced 2025-07-26 11:04:33 -04:00

patch 8.2.0606: several syntax HL errors not checked

Problem:    Several syntax HL errors not checked.
Solution:   Add tests. (Yegappan Lakshmanan, closes #5954)
This commit is contained in:
Bram Moolenaar 2020-04-19 18:31:25 +02:00
parent 7bdaea6e0d
commit fbf2122cf9
2 changed files with 47 additions and 50 deletions

View File

@ -320,6 +320,18 @@ func Test_syntax_arg_skipped()
syn clear syn clear
endfunc 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() func Test_syntax_invalid_arg()
call assert_fails('syntax case asdf', 'E390:') call assert_fails('syntax case asdf', 'E390:')
if has('conceal') if has('conceal')
@ -327,69 +339,49 @@ func Test_syntax_invalid_arg()
endif endif
call assert_fails('syntax spell asdf', 'E390:') call assert_fails('syntax spell asdf', 'E390:')
call assert_fails('syntax clear @ABCD', 'E391:') call assert_fails('syntax clear @ABCD', 'E391:')
call assert_fails('syntax include @Xxx', 'E397:') call assert_fails('syntax include random_file', 'E484:')
call assert_fails('syntax region X start="{"', 'E399:') call assert_fails('syntax include <afile>', 'E495:')
call assert_fails('syntax sync x', 'E404:') call assert_fails('syntax sync x', 'E404:')
call assert_fails('syntax keyword Abc a[', 'E789:') call assert_fails('syntax keyword Abc a[', 'E789:')
call assert_fails('syntax keyword Abc a[bc]d', 'E890:') call assert_fails('syntax keyword Abc a[bc]d', 'E890:')
call assert_fails('syntax cluster Abc add=A add=', 'E475:')
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)
" Test for too many \z\( and unmatched \z\( " Test for too many \z\( and unmatched \z\(
" Not able to use assert_fails() here because both E50:/E879: and E475: " Not able to use assert_fails() here because both E50:/E879: and E475:
" messages are emitted. " messages are emitted.
set regexpengine=1 set regexpengine=1
let caught_52 = 0 call AssertFails("syntax region MyRegion start='\\z\\(' end='\\*/'", 'E52:')
try
syntax region MyRegion start='\z\(' end='\*/'
catch /E52:/
let caught_52 = 1
endtry
call assert_equal(1, caught_52)
let caught_50 = 0
try
let cmd = "syntax region MyRegion start='" let cmd = "syntax region MyRegion start='"
let cmd ..= repeat("\\z\\(.\\)", 10) .. "' end='\*/'" let cmd ..= repeat("\\z\\(.\\)", 10) .. "' end='\*/'"
exe cmd call AssertFails(cmd, 'E50:')
catch /E50:/
let caught_50 = 1
endtry
call assert_equal(1, caught_50)
set regexpengine=2 set regexpengine=2
let caught_54 = 0 call AssertFails("syntax region MyRegion start='\\z\\(' end='\\*/'", 'E54:')
try
syntax region MyRegion start='\z\(' end='\*/'
catch /E54:/
let caught_54 = 1
endtry
call assert_equal(1, caught_54)
let caught_879 = 0
try
let cmd = "syntax region MyRegion start='" let cmd = "syntax region MyRegion start='"
let cmd ..= repeat("\\z\\(.\\)", 10) .. "' end='\*/'" let cmd ..= repeat("\\z\\(.\\)", 10) .. "' end='\*/'"
exe cmd call AssertFails(cmd, 'E879:')
catch /E879:/
let caught_879 = 1
endtry
call assert_equal(1, caught_879)
set regexpengine& 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 endfunc
func Test_syn_sync() func Test_syn_sync()
@ -417,6 +409,7 @@ func Test_syn_clear()
hi clear Foo hi clear Foo
call assert_equal('Foo', synIDattr(hlID("Foo"), "name")) call assert_equal('Foo', synIDattr(hlID("Foo"), "name"))
hi clear Bar hi clear Bar
call assert_fails('syntax clear invalid_syngroup', 'E28:')
endfunc endfunc
func Test_invalid_name() func Test_invalid_name()
@ -565,6 +558,8 @@ func Test_conceal()
call assert_match('16 ', ScreenLines(2, 7)[0]) 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 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 '&amp;' conceal cchar=\<Tab>", 'E844:')
syn clear syn clear
set conceallevel& set conceallevel&
bw! bw!

View File

@ -746,6 +746,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
606,
/**/ /**/
605, 605,
/**/ /**/