1
-- Test for matchadd() and conceal feature
3
local helpers = require('test.functional.helpers')
4
local clear = helpers.clear
5
local expect = helpers.expect
6
local source = helpers.source
8
describe('match_conceal', function()
17
put =\"\#\ This\ is\ a\ Test\"
20
fu! ScreenChar(width, lines)
22
for j in range(1,a:lines)
23
for i in range(1,a:width)
24
let c.=nr2char(screenchar(j, i))
31
fu! ScreenAttr(line, pos, eval)
34
call add(g:attr, screenattr(a:line,col))
36
" In case all values are zero, probably the terminal
37
" isn't set correctly, so catch that case
38
let null = (eval(join(g:attr, '+')) == 0)
39
let str=substitute(a:eval, '\d\+', 'g:attr[&]', 'g')
41
let g:attr_test="OK: ". str
43
let g:attr_test="FAILED: ".str
44
let g:attr_test.="\n". join(g:attr, ' ')
45
let g:attr_test.="\n TERM: ". &term
51
$put =printf(\"\n%s\", g:test)
59
it('is working', function()
61
let g:test ="Test 1: simple addmatch()"
62
call matchadd('Conceal', '\%2l ')
64
let line=ScreenChar(winwidth(0),1)
65
call ScreenAttr(1,[1,2,7,10,12,16], "0!=1 && 1==2 && 1==3 && 1==4 && 0==5")
68
let g:test ="Test 2: simple addmatch() and conceal (should be: #XThisXisXaXTest)"
72
set concealcursor=n conceallevel=1
73
call matchadd('Conceal', '\%2l ', 10, -1, {'conceal': 'X'})
75
let line=ScreenChar(winwidth(0),1)
76
call ScreenAttr(1,[1,2,7,10,12,16], "0!=1 && 1==2 && 1==3 && 1==4 && 0==5")
79
let g:test ="Test 3: addmatch() and conceallevel=3 (should be: #ThisisaTest)"
83
call matchadd('Conceal', '\%2l ', 10, -1, {'conceal': 'X'})
85
let line=ScreenChar(winwidth(0),1)
86
call ScreenAttr(1,[1,2,7,10,12,16], "0==1 && 1==2 && 1==3 && 1==4 && 0!=5")
89
let g:test ="Test 4: more match() (should be: #Thisisa Test)"
91
call matchadd('ErrorMsg', '\%2l Test', 20, -1, {'conceal': 'X'})
93
let line=ScreenChar(winwidth(0),1)
94
call ScreenAttr(1,[1,2,7,10,12,16], "0==1 && 1==2 && 0!=3 && 3==4 && 0!=5 && 3!=5")
97
let g:test ="Test 5/1: default conceal char (should be: # This is a Test)"
101
call matchadd('Conceal', '\%2l ', 10, -1, {})
103
let line=ScreenChar(winwidth(0),1)
104
call ScreenAttr(1,[1,2,7,10,12,16], "0!=1 && 1==2 && 1==3 && 1==4 && 0==5")
105
call DoRecordScreen()
106
let g:test ="Test 5/2: default conceal char (should be: #+This+is+a+Test)"
108
set listchars=conceal:+
110
let line=ScreenChar(winwidth(0),1)
111
call ScreenAttr(1,[1,2,7,10,12,16], "0!=1 && 1==2 && 1==3 && 1==4 && 0==5")
112
call DoRecordScreen()
115
let g:test ="Test 6/1: syn and match conceal (should be: #ZThisZisZaZTest)"
119
call matchadd('Conceal', '\%2l ', 10, -1, {'conceal': 'Z'})
120
syn match MyConceal /\%2l / conceal containedin=ALL cchar=*
122
let line=ScreenChar(winwidth(0),1)
123
call ScreenAttr(1,[1,2,7,10,12,16], "0!=1 && 1==2 && 1==3 && 1==4 && 0==5")
124
call DoRecordScreen()
125
let g:test ="Test 6/2: syn and match conceal (should be: #*This*is*a*Test)"
129
let line=ScreenChar(winwidth(0),1)
130
call ScreenAttr(1,[1,2,7,10,12,16], "0!=1 && 1==2 && 1==3 && 1==4 && 0==5")
131
call DoRecordScreen()
133
let g:test ="Test 7/1: clear matches"
136
call matchadd('Conceal', '\%2l ', 10, -1, {'conceal': 'Z'})
140
let line=ScreenChar(winwidth(0),1)
141
call ScreenAttr(1,[1,2,7,10,12,16], "0==1 && 0==2 && 0==3 && 0==4 && 0==5")
142
call DoRecordScreen()
146
let g:test ="Test 7/2: reset match using setmatches()"
149
let line=ScreenChar(winwidth(0),1)
150
call ScreenAttr(1,[1,2,7,10,12,16], "0!=1 && 1==2 && 1==3 && 1==4 && 0==5")
151
call DoRecordScreen()
153
let g:test ="Test 8: using matchaddpos() (should be #Pis a Test"
156
call matchaddpos('Conceal', [[2,2,6]], 10, -1, {'conceal': 'P'})
159
let line=ScreenChar(winwidth(0),1)
160
call ScreenAttr(1,[1,2,7,10,12,16], "0!=1 && 1!=2 && 0==2 && 0==3 && 0!=4 && 0!=5 && 4==5")
161
call DoRecordScreen()
164
let g:test ="Test 9: match using multibyte conceal char (should be: #ˑThisˑisˑaˑTest)"
167
call matchadd('Conceal', '\%2l ', 20, -1, {'conceal': "\u02d1"})
169
let line=ScreenChar(winwidth(0),1)
170
call ScreenAttr(1,[1,2,7,10,12,16], "0!=1 && 1==2 && 1==3 && 1==4 && 0==5")
171
call DoRecordScreen()
178
Test 1: simple addmatch()
180
OK: g:attr[0]!=g:attr[1] && g:attr[1]==g:attr[2] && g:attr[1]==g:attr[3] && g:attr[1]==g:attr[4] && g:attr[0]==g:attr[5]
182
Test 2: simple addmatch() and conceal (should be: #XThisXisXaXTest)
184
OK: g:attr[0]!=g:attr[1] && g:attr[1]==g:attr[2] && g:attr[1]==g:attr[3] && g:attr[1]==g:attr[4] && g:attr[0]==g:attr[5]
186
Test 3: addmatch() and conceallevel=3 (should be: #ThisisaTest)
188
OK: g:attr[0]==g:attr[1] && g:attr[1]==g:attr[2] && g:attr[1]==g:attr[3] && g:attr[1]==g:attr[4] && g:attr[0]!=g:attr[5]
190
Test 4: more match() (should be: #Thisisa Test)
192
OK: g:attr[0]==g:attr[1] && g:attr[1]==g:attr[2] && g:attr[0]!=g:attr[3] && g:attr[3]==g:attr[4] && g:attr[0]!=g:attr[5] && g:attr[3]!=g:attr[5]
194
Test 5/1: default conceal char (should be: # This is a Test)
196
OK: g:attr[0]!=g:attr[1] && g:attr[1]==g:attr[2] && g:attr[1]==g:attr[3] && g:attr[1]==g:attr[4] && g:attr[0]==g:attr[5]
198
Test 5/2: default conceal char (should be: #+This+is+a+Test)
200
OK: g:attr[0]!=g:attr[1] && g:attr[1]==g:attr[2] && g:attr[1]==g:attr[3] && g:attr[1]==g:attr[4] && g:attr[0]==g:attr[5]
202
Test 6/1: syn and match conceal (should be: #ZThisZisZaZTest)
204
OK: g:attr[0]!=g:attr[1] && g:attr[1]==g:attr[2] && g:attr[1]==g:attr[3] && g:attr[1]==g:attr[4] && g:attr[0]==g:attr[5]
206
Test 6/2: syn and match conceal (should be: #*This*is*a*Test)
208
OK: g:attr[0]!=g:attr[1] && g:attr[1]==g:attr[2] && g:attr[1]==g:attr[3] && g:attr[1]==g:attr[4] && g:attr[0]==g:attr[5]
210
Test 7/1: clear matches
212
OK: g:attr[0]==g:attr[1] && g:attr[0]==g:attr[2] && g:attr[0]==g:attr[3] && g:attr[0]==g:attr[4] && g:attr[0]==g:attr[5]
213
{'group': 'Conceal', 'pattern': '\%2l ', 'priority': 10, 'id': 10, 'conceal': 'Z'}
215
Test 7/2: reset match using setmatches()
217
OK: g:attr[0]!=g:attr[1] && g:attr[1]==g:attr[2] && g:attr[1]==g:attr[3] && g:attr[1]==g:attr[4] && g:attr[0]==g:attr[5]
219
Test 8: using matchaddpos() (should be #Pis a Test
221
OK: g:attr[0]!=g:attr[1] && g:attr[1]!=g:attr[2] && g:attr[0]==g:attr[2] && g:attr[0]==g:attr[3] && g:attr[0]!=g:attr[4] && g:attr[0]!=g:attr[5] && g:attr[4]==g:attr[5]
222
{'group': 'Conceal', 'id': 11, 'priority': 10, 'pos1': [2, 2, 6], 'conceal': 'P'}
224
Test 9: match using multibyte conceal char (should be: #ˑThisˑisˑaˑTest)
226
OK: g:attr[0]!=g:attr[1] && g:attr[1]==g:attr[2] && g:attr[1]==g:attr[3] && g:attr[1]==g:attr[4] && g:attr[0]==g:attr[5]]=])