blob: aa32b8582bbf3706b0f98ad2bd6f211cc68f7887 [file] [log] [blame]
Bram Moolenaar6561d522015-07-21 15:48:27 +02001Test for matchadd() and conceal feature
2
3STARTTEST
4:so small.vim
5:if !has("conceal") | e! test.ok | w! test.out | qa! | endif
6:set term=ansi
7:so mbyte.vim
8:if &enc !=? 'utf-8'|:e! test.ok|:w! test.out|qa!|endif
9:10new|:vsp|:vert resize 20
10:put =\"\#\ This\ is\ a\ Test\"
11:norm! mazt
12:fu! ScreenChar(width, lines)
13: let c=''
14: for j in range(1,a:lines)
15: for i in range(1,a:width)
16: let c.=nr2char(screenchar(j, i))
17: endfor
18: let c.="\n"
19: endfor
20: return c
21:endfu
22:fu! ScreenAttr(line, pos, eval)
23: let g:attr=[]
24: for col in a:pos
25: call add(g:attr, screenattr(a:line,col))
26: endfor
27: " In case all values are zero, probably the terminal
28: " isn't set correctly, so catch that case
29: let null = (eval(join(g:attr, '+')) == 0)
30: let str=substitute(a:eval, '\d\+', 'g:attr[&]', 'g')
31: if null || eval(str)
32: :let g:attr_test="OK: ". str
33: else
34: :let g:attr_test="FAILED: ".str
35: :let g:attr_test.="\n". join(g:attr, ' ')
36: :let g:attr_test.="\n TERM: ". &term
37: endif
38:endfu
39:fu! DoRecordScreen()
40: wincmd l
41: $put =printf(\"\n%s\", g:test)
42: $put =g:line
43: $put =g:attr_test
44: wincmd p
45:endfu
46:let g:test ="Test 1: simple addmatch()"
47:call matchadd('Conceal', '\%2l ')
48:redraw!
49:let line=ScreenChar(winwidth(0),1)
50:call ScreenAttr(1,[1,2,7,10,12,16], "0!=1 && 1==2 && 1==3 && 1==4 && 0==5")
51:call DoRecordScreen()
52:
53:let g:test ="Test 2: simple addmatch() and conceal (should be: #XThisXisXaXTest)"
54:norm! 'azt
55:call clearmatches()
56:syntax on
57:set concealcursor=n conceallevel=1
58:call matchadd('Conceal', '\%2l ', 10, -1, {'conceal': 'X'})
59:redraw!
60:let line=ScreenChar(winwidth(0),1)
61:call ScreenAttr(1,[1,2,7,10,12,16], "0!=1 && 1==2 && 1==3 && 1==4 && 0==5")
62:call DoRecordScreen()
63:
64:let g:test ="Test 3: addmatch() and conceallevel=3 (should be: #ThisisaTest)"
65:norm! 'azt
66:set conceallevel=3
67:call clearmatches()
68:call matchadd('Conceal', '\%2l ', 10, -1, {'conceal': 'X'})
69:redraw!
70:let line=ScreenChar(winwidth(0),1)
71:call ScreenAttr(1,[1,2,7,10,12,16], "0==1 && 1==2 && 1==3 && 1==4 && 0!=5")
72:call DoRecordScreen()
73:
74:let g:test ="Test 4: more match() (should be: #Thisisa Test)"
75:norm! 'azt
76:call matchadd('ErrorMsg', '\%2l Test', 20, -1, {'conceal': 'X'})
77:redraw!
78:let line=ScreenChar(winwidth(0),1)
79:call ScreenAttr(1,[1,2,7,10,12,16], "0==1 && 1==2 && 0!=3 && 3==4 && 0!=5 && 3!=5")
80:call DoRecordScreen()
81:
82:let g:test ="Test 5/1: default conceal char (should be: # This is a Test)"
83:norm! 'azt
84:call clearmatches()
85:set conceallevel=1
86:call matchadd('Conceal', '\%2l ', 10, -1, {})
87:redraw!
88:let line=ScreenChar(winwidth(0),1)
89:call ScreenAttr(1,[1,2,7,10,12,16], "0!=1 && 1==2 && 1==3 && 1==4 && 0==5")
90:call DoRecordScreen()
91:let g:test ="Test 5/2: default conceal char (should be: #+This+is+a+Test)"
92:norm! 'azt
93:set listchars=conceal:+
94:let line=ScreenChar(winwidth(0),1)
95:call ScreenAttr(1,[1,2,7,10,12,16], "0!=1 && 1==2 && 1==3 && 1==4 && 0==5")
96:call DoRecordScreen()
97:set listchars&vim
98:
99:let g:test ="Test 6/1: syn and match conceal (should be: #ZThisZisZaZTest)"
100:norm! 'azt
101:call clearmatches()
102:set conceallevel=1
103:call matchadd('Conceal', '\%2l ', 10, -1, {'conceal': 'Z'})
104:syn match MyConceal /\%2l / conceal containedin=ALL cchar=*
105:redraw!
106:let line=ScreenChar(winwidth(0),1)
107:call ScreenAttr(1,[1,2,7,10,12,16], "0!=1 && 1==2 && 1==3 && 1==4 && 0==5")
108:call DoRecordScreen()
109:let g:test ="Test 6/2: syn and match conceal (should be: #*This*is*a*Test)"
110:norm! 'azt
111:call clearmatches()
112:let line=ScreenChar(winwidth(0),1)
113:call ScreenAttr(1,[1,2,7,10,12,16], "0!=1 && 1==2 && 1==3 && 1==4 && 0==5")
114:call DoRecordScreen()
115:
116:let g:test ="Test 7/1: clear matches"
117:norm! 'azt
118:syn on
119:call matchadd('Conceal', '\%2l ', 10, -1, {'conceal': 'Z'})
120:let a=getmatches()
121:call clearmatches()
122:redraw!
123:let line=ScreenChar(winwidth(0),1)
124:call ScreenAttr(1,[1,2,7,10,12,16], "0==1 && 0==2 && 0==3 && 0==4 && 0==5")
125:call DoRecordScreen()
126:$put =a
127:call setmatches(a)
128:norm! 'azt
129:let g:test ="Test 7/2: reset match using setmatches()"
130:norm! 'azt
131:let line=ScreenChar(winwidth(0),1)
132:call ScreenAttr(1,[1,2,7,10,12,16], "0!=1 && 1==2 && 1==3 && 1==4 && 0==5")
133:call DoRecordScreen()
134:
135:let g:test ="Test 8: using matchaddpos() (should be #Pis a Test"
136:norm! 'azt
137:call clearmatches()
138:call matchaddpos('Conceal', [[2,2,6]], 10, -1, {'conceal': 'P'})
139:let a=getmatches()
140:redraw!
141:let line=ScreenChar(winwidth(0),1)
142:call ScreenAttr(1,[1,2,7,10,12,16], "0!=1 && 1!=2 && 0==2 && 0==3 && 0!=4 && 0!=5 && 4==5")
143:call DoRecordScreen()
144:$put =a
145:
146:let g:test ="Test 9: match using multibyte conceal char (should be: #ˑThisˑisˑaˑTest)"
147:norm! 'azt
148:call clearmatches()
149:call matchadd('Conceal', '\%2l ', 20, -1, {'conceal': "\u02d1"})
150:redraw!
151:let line=ScreenChar(winwidth(0),1)
152:call ScreenAttr(1,[1,2,7,10,12,16], "0!=1 && 1==2 && 1==3 && 1==4 && 0==5")
153:call DoRecordScreen()
154:
155:"sleep 10
156:%w! test.out
157:qa!
158ENDTEST
159dummy text