0
0
mirror of https://github.com/vim/vim.git synced 2025-09-28 04:24:06 -04:00

patch 8.2.1077: no enough test coverage for highlighting

Problem:    No enough test coverage for highlighting.
Solution:   Add more tests. (Yegappan Lakshmanan, closes #6351)
This commit is contained in:
Bram Moolenaar
2020-06-28 13:10:22 +02:00
parent faf8626b79
commit 75e15670b8
5 changed files with 100 additions and 2 deletions

View File

@@ -5018,7 +5018,7 @@ ctermul={color-nr} *highlight-ctermul*
console. Example, for reverse video: >
:highlight Visual ctermfg=bg ctermbg=fg
< Note that the colors are used that are valid at the moment this
command are given. If the Normal group colors are changed later, the
command is given. If the Normal group colors are changed later, the
"fg" and "bg" colors will not be adjusted.

View File

@@ -191,6 +191,10 @@ func Test_highlight_completion()
call assert_equal('"hi default', getreg(':'))
call feedkeys(":hi c\<S-Tab>\<Home>\"\<CR>", 'xt')
call assert_equal('"hi clear', getreg(':'))
call feedkeys(":hi clear Aardig Aard\<Tab>\<C-B>\"\<CR>", 'xt')
call assert_equal('"hi clear Aardig Aardig', getreg(':'))
call feedkeys(":hi Aardig \<Tab>\<C-B>\"\<CR>", 'xt')
call assert_equal("\"hi Aardig \t", getreg(':'))
" A cleared group does not show up in completions.
hi Anders ctermfg=green
@@ -201,6 +205,14 @@ func Test_highlight_completion()
call assert_equal([], getcompletion('A', 'highlight'))
endfunc
" Test for command-line expansion of "hi Ni " (easter egg)
func Test_highlight_easter_egg()
call test_override('ui_delay', 1)
call feedkeys(":hi Ni \<Tab>\<C-B>\"\<CR>", 'xt')
call assert_equal("\"hi Ni \<Tab>", @:)
call test_override('ALL', 0)
endfunc
func Test_getcompletion()
if !has('cmdline_compl')
return

View File

@@ -701,8 +701,9 @@ endfunc
func Test_highlight_cmd_errors()
if has('gui_running')
" This test doesn't fail in the MS-Windows console version.
call assert_fails('hi Xcomment ctermfg=fg', 'E419:')
call assert_fails('hi Xcomment ctermbg=fg', 'E419:')
call assert_fails('hi Xcomment ctermfg=bg', 'E420:')
call assert_fails('hi Xcomment ctermfg=ul', 'E453:')
endif
" Try using a very long terminal code. Define a dummy terminal code for this
@@ -713,4 +714,51 @@ func Test_highlight_cmd_errors()
let &t_fo = ""
endfunc
" Test for 'highlight' option
func Test_highlight_opt()
let save_hl = &highlight
call assert_fails('set highlight=j:b', 'E474:')
set highlight=f\ r
call assert_equal('f r', &highlight)
set highlight=fb
call assert_equal('fb', &highlight)
set highlight=fi
call assert_equal('fi', &highlight)
set highlight=f-
call assert_equal('f-', &highlight)
set highlight=fr
call assert_equal('fr', &highlight)
set highlight=fs
call assert_equal('fs', &highlight)
set highlight=fu
call assert_equal('fu', &highlight)
set highlight=fc
call assert_equal('fc', &highlight)
set highlight=ft
call assert_equal('ft', &highlight)
call assert_fails('set highlight=fr:Search', 'E474:')
set highlight=f:$#
call assert_match('W18:', v:statusmsg)
let &highlight = save_hl
endfunc
" Test for User group highlighting used in the statusline
func Test_highlight_User()
CheckNotGui
hi User1 ctermfg=12
redraw!
call assert_equal('12', synIDattr(synIDtrans(hlID('User1')), 'fg'))
hi clear
endfunc
" Test for using RGB color values in a highlight group
func Test_highlight_RGB_color()
CheckGui
hi MySearch guifg=#110000 guibg=#001100 guisp=#000011
call assert_equal('#110000', synIDattr(synIDtrans(hlID('MySearch')), 'fg#'))
call assert_equal('#001100', synIDattr(synIDtrans(hlID('MySearch')), 'bg#'))
call assert_equal('#000011', synIDattr(synIDtrans(hlID('MySearch')), 'sp#'))
hi clear
endfunc
" vim: shiftwidth=2 sts=2 expandtab

View File

@@ -98,6 +98,7 @@ function Test_match()
call assert_fails('call setmatches(0)', 'E714:')
call assert_fails('call setmatches([0])', 'E474:')
call assert_fails("call setmatches([{'wrong key': 'wrong value'}])", 'E474:')
call assert_equal(-1, setmatches([{'group' : 'Search', 'priority' : 10, 'id' : 5, 'pos1' : {}}]))
call setline(1, 'abcdefghijklmnopq')
call matchaddpos("MyGroup1", [[1, 5], [1, 8, 3]], 10, 3)
@@ -164,6 +165,8 @@ func Test_matchadd_error()
call assert_fails("call matchadd('Error', 'XXX', 1, 3)", 'E798:')
call assert_fails("call matchadd('Error', 'XXX', 1, 0)", 'E799:')
call assert_fails("call matchadd('Error', 'XXX', [], 0)", 'E745:')
call assert_equal(-1, matchadd('', 'pat'))
call assert_equal(-1, matchadd('Search', ''))
endfunc
func Test_matchaddpos()
@@ -202,6 +205,14 @@ func Test_matchaddpos()
call assert_equal(screenattr(2,2), screenattr(1,10))
call assert_notequal(screenattr(2,2), screenattr(1,11))
" matchaddpos() with line number as 0
call clearmatches()
let id = matchaddpos('Search', [[0], [3], [0]])
call assert_equal([{'group' : 'Search', 'priority' : 10, 'id' : id, 'pos1' : [3]}], getmatches())
call clearmatches()
let id = matchaddpos('Search', [0, 3, 0])
call assert_equal([{'group' : 'Search', 'priority' : 10, 'id' : id, 'pos1' : [3]}], getmatches())
nohl
call clearmatches()
syntax off
@@ -233,6 +244,7 @@ func Test_matchaddpos_otherwin()
eval winid->clearmatches()
call assert_equal([], getmatches(winid))
call assert_fails('echo getmatches(-1)', 'E957:')
call setmatches(savematches, winid)
call assert_equal(expect, savematches)
@@ -281,6 +293,10 @@ func Test_matchaddpos_error()
call assert_fails("call matchaddpos('Error', [{}])", 'E290:')
call assert_equal(-1, matchaddpos('Error', test_null_list()))
call assert_fails("call matchaddpos('Error', [1], [], 1)", 'E745:')
call assert_equal(-1, matchaddpos('Search', [[]]))
call assert_fails("call matchaddpos('Search', [[{}]])", 'E728:')
call assert_fails("call matchaddpos('Search', [[2, {}]])", 'E728:')
call assert_fails("call matchaddpos('Search', [[3, 4, {}]])", 'E728:')
endfunc
func OtherWindowCommon()
@@ -333,4 +349,24 @@ func Test_matchadd_other_window()
call delete('XscriptMatchCommon')
endfunc
" Test for deleting matches outside of the screen redraw top/bottom lines
" This should cause a redraw of those lines.
func Test_matchdelete_redraw()
new
call setline(1, range(1, 500))
call cursor(250, 1)
let m1 = matchaddpos('Search', [[250]])
let m2 = matchaddpos('Search', [[10], [450]])
redraw!
let m3 = matchaddpos('Search', [[240], [260]])
call matchdelete(m2)
let m = getmatches()
call assert_equal(2, len(m))
call assert_equal([250], m[0].pos1)
redraw!
call matchdelete(m1)
call assert_equal(1, len(getmatches()))
bw!
endfunc
" vim: shiftwidth=2 sts=2 expandtab

View File

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