vim-patch:8.0.0659: no test for conceal mode

Problem:    No test for conceal mode.
Solution:   Add a conceal mode test. (Dominique Pelle, closes vim/vim#1783)

4d785895d1
This commit is contained in:
Justin M. Keyes 2018-01-21 11:27:17 +01:00
parent a5d33d5e90
commit 154822933e
3 changed files with 61 additions and 13 deletions

View File

@ -7602,17 +7602,20 @@ synIDtrans({synID}) *synIDtrans()*
":highlight link" are followed. ":highlight link" are followed.
synconcealed({lnum}, {col}) *synconcealed()* synconcealed({lnum}, {col}) *synconcealed()*
The result is a List. The first item in the list is 0 if the The result is a List with currently three items:
character at the position {lnum} and {col} is not part of a 1. The first item in the list is 0 if the character at the
concealable region, 1 if it is. The second item in the list is position {lnum} and {col} is not part of a concealable
a string. If the first item is 1, the second item contains the region, 1 if it is.
text which will be displayed in place of the concealed text, 2. The second item in the list is a string. If the first item
depending on the current setting of 'conceallevel'. The third is 1, the second item contains the text which will be
and final item in the list is a unique number representing the displayed in place of the concealed text, depending on the
specific syntax region matched. This allows detection of the current setting of 'conceallevel' and 'listchars'.
beginning of a new concealable region if there are two 3. The third and final item in the list is a unique number
consecutive regions with the same replacement character. representing the specific syntax region matched. This
For an example use see $VIMRUNTIME/syntax/2html.vim . allows detection of the beginning of a new concealable
region if there are two consecutive regions with the same
replacement character. For an example use see
$VIMRUNTIME/syntax/2html.vim .
synstack({lnum}, {col}) *synstack()* synstack({lnum}, {col}) *synstack()*

View File

@ -16274,8 +16274,8 @@ static void f_synconcealed(typval_T *argvars, typval_T *rettv, FunPtr fptr)
// get the conceal character // get the conceal character
if ((syntax_flags & HL_CONCEAL) && curwin->w_p_cole < 3) { if ((syntax_flags & HL_CONCEAL) && curwin->w_p_cole < 3) {
cchar = syn_get_sub_char(); cchar = syn_get_sub_char();
if (cchar == NUL && curwin->w_p_cole == 1 && lcs_conceal != NUL) { if (cchar == NUL && curwin->w_p_cole == 1) {
cchar = lcs_conceal; cchar = (lcs_conceal == NUL) ? ' ' : lcs_conceal;
} }
if (cchar != NUL) { if (cchar != NUL) {
utf_char2bytes(cchar, str); utf_char2bytes(cchar, str);

View File

@ -1,5 +1,7 @@
" Test for syntax and syntax iskeyword option " Test for syntax and syntax iskeyword option
source view_util.vim
func GetSyntaxItem(pat) func GetSyntaxItem(pat)
let c = '' let c = ''
let a = ['a', getreg('a'), getregtype('a')] let a = ['a', getreg('a'), getregtype('a')]
@ -340,3 +342,46 @@ func Test_invalid_name()
hi clear Nop hi clear Nop
hi clear @Wrong hi clear @Wrong
endfunc endfunc
func Test_conceal()
if !has('conceal')
return
endif
new
call setline(1, ['', '123456'])
syn match test23 "23" conceal cchar=X
syn match test45 "45" conceal
set conceallevel=0
call assert_equal('123456 ', ScreenLines(2, 7)[0])
call assert_equal([[0, ''], [0, ''], [0, ''], [0, ''], [0, ''], [0, '']], map(range(1, 6), 'synconcealed(2, v:val)[0:1]'))
set conceallevel=1
call assert_equal('1X 6 ', ScreenLines(2, 7)[0])
" FIXME: with conceallevel=1, I would expect that the portion "45" of
" the line to be replaced with a space since ":help 'conceallevel'
" states that if listchars is not set, then the default replacement
" should be a space. But synconcealed() gives an empty string in
" the 2nd value of the returned list. Bug?
" So for now, the following line is commented out:
call assert_equal([[0, ''], [1, 'X'], [1, 'X'], [1, ' '], [1, ' '], [0, '']], map(range(1, 6), 'synconcealed(2, v:val)[0:1]'))
set conceallevel=1
set listchars=conceal:Y
call assert_equal([[0, ''], [1, 'X'], [1, 'X'], [1, 'Y'], [1, 'Y'], [0, '']], map(range(1, 6), 'synconcealed(2, v:val)[0:1]'))
call assert_equal('1XY6 ', ScreenLines(2, 7)[0])
set conceallevel=2
call assert_match('1X6 ', ScreenLines(2, 7)[0])
call assert_equal([[0, ''], [1, 'X'], [1, 'X'], [1, ''], [1, ''], [0, '']], map(range(1, 6), 'synconcealed(2, v:val)[0:1]'))
set conceallevel=3
call assert_match('16 ', ScreenLines(2, 7)[0])
call assert_equal([[0, ''], [1, ''], [1, ''], [1, ''], [1, ''], [0, '']], map(range(1, 6), 'synconcealed(2, v:val)[0:1]'))
syn clear
set conceallevel&
bw!
endfunc