~ubuntu-branches/debian/sid/neovim/sid

« back to all changes in this revision

Viewing changes to test/functional/legacy/match_conceal_spec.lua

  • Committer: Package Import Robot
  • Author(s): James McCoy
  • Date: 2016-04-18 21:42:19 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20160418214219-1e6d4o1fwqarzk46
Tags: 0.1.3-1
* New upstream release.  (Closes: #820562)
* debian/control:
  + Remove unnecessary luarocks Build-Depends
  + Add libkvm-dev Build-Depends for kfreebsd-*
  + Add python(3)-neovim to Recommends.  (Closes: #812737)
  + Declare compiance with policy 3.9.8, no changes needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
-- Test for matchadd() and conceal feature
 
2
 
 
3
local helpers = require('test.functional.helpers')
 
4
local clear = helpers.clear
 
5
local expect = helpers.expect
 
6
local source = helpers.source
 
7
 
 
8
describe('match_conceal', function()
 
9
  before_each(function()
 
10
    clear()
 
11
 
 
12
    source([[
 
13
      set wildchar=^E
 
14
      10new
 
15
      vsp
 
16
      vert resize 20
 
17
      put =\"\#\ This\ is\ a\ Test\"
 
18
      norm! mazt
 
19
      
 
20
      fu! ScreenChar(width, lines)
 
21
        let c=''
 
22
        for j in range(1,a:lines)
 
23
          for i in range(1,a:width)
 
24
            let c.=nr2char(screenchar(j, i))
 
25
          endfor
 
26
          let c.="\n"
 
27
        endfor
 
28
        return c
 
29
      endfu
 
30
      
 
31
      fu! ScreenAttr(line, pos, eval)
 
32
        let g:attr=[]
 
33
        for col in a:pos
 
34
          call add(g:attr, screenattr(a:line,col))
 
35
        endfor
 
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')
 
40
        if null || eval(str)
 
41
          let g:attr_test="OK: ". str
 
42
        else
 
43
          let g:attr_test="FAILED: ".str
 
44
          let g:attr_test.="\n". join(g:attr, ' ')
 
45
          let g:attr_test.="\n TERM: ". &term
 
46
        endif
 
47
      endfu
 
48
      
 
49
      fu! DoRecordScreen()
 
50
        wincmd l
 
51
        $put =printf(\"\n%s\", g:test)
 
52
        $put =g:line
 
53
        $put =g:attr_test
 
54
        wincmd p
 
55
      endfu
 
56
    ]])
 
57
  end)
 
58
 
 
59
  it('is working', function()
 
60
    source([=[
 
61
      let g:test ="Test 1: simple addmatch()"
 
62
      call matchadd('Conceal', '\%2l ')
 
63
      redraw!
 
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")
 
66
      call DoRecordScreen()
 
67
 
 
68
      let g:test ="Test 2: simple addmatch() and conceal (should be: #XThisXisXaXTest)"
 
69
      norm! 'azt
 
70
      call clearmatches()
 
71
      syntax on
 
72
      set concealcursor=n conceallevel=1
 
73
      call matchadd('Conceal', '\%2l ', 10, -1, {'conceal': 'X'})
 
74
      redraw!
 
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")
 
77
      call DoRecordScreen()
 
78
 
 
79
      let g:test ="Test 3: addmatch() and conceallevel=3 (should be: #ThisisaTest)"
 
80
      norm! 'azt
 
81
      set conceallevel=3
 
82
      call clearmatches()
 
83
      call matchadd('Conceal', '\%2l ', 10, -1, {'conceal': 'X'})
 
84
      redraw!
 
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")
 
87
      call DoRecordScreen()
 
88
 
 
89
      let g:test ="Test 4: more match() (should be: #Thisisa Test)"
 
90
      norm! 'azt
 
91
      call matchadd('ErrorMsg', '\%2l Test', 20, -1, {'conceal': 'X'})
 
92
      redraw!
 
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")
 
95
      call DoRecordScreen()
 
96
 
 
97
      let g:test ="Test 5/1: default conceal char (should be: # This is a Test)"
 
98
      norm! 'azt
 
99
      call clearmatches()
 
100
      set conceallevel=1
 
101
      call matchadd('Conceal', '\%2l ', 10, -1, {})
 
102
      redraw!
 
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)"
 
107
      norm! 'azt
 
108
      set listchars=conceal:+
 
109
      redraw!
 
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()
 
113
      set listchars&vi
 
114
 
 
115
      let g:test ="Test 6/1: syn and match conceal (should be: #ZThisZisZaZTest)"
 
116
      norm! 'azt
 
117
      call clearmatches()
 
118
      set conceallevel=1
 
119
      call matchadd('Conceal', '\%2l ', 10, -1, {'conceal': 'Z'})
 
120
      syn match MyConceal /\%2l / conceal containedin=ALL cchar=*
 
121
      redraw!
 
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)"
 
126
      norm! 'azt
 
127
      call clearmatches()
 
128
      redraw!
 
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()
 
132
 
 
133
      let g:test ="Test 7/1: clear matches"
 
134
      norm! 'azt
 
135
      syn on
 
136
      call matchadd('Conceal', '\%2l ', 10, -1, {'conceal': 'Z'})
 
137
      let a=getmatches()
 
138
      call clearmatches()
 
139
      redraw!
 
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()
 
143
      $put =a
 
144
      call setmatches(a)
 
145
      norm! 'azt
 
146
      let g:test ="Test 7/2: reset match using setmatches()"
 
147
      norm! 'azt
 
148
      redraw!
 
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()
 
152
 
 
153
      let g:test ="Test 8: using matchaddpos() (should be #Pis a Test"
 
154
      norm! 'azt
 
155
      call clearmatches()
 
156
      call matchaddpos('Conceal', [[2,2,6]], 10, -1, {'conceal': 'P'})
 
157
      let a=getmatches()
 
158
      redraw!
 
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()
 
162
      $put =a
 
163
 
 
164
      let g:test ="Test 9: match using multibyte conceal char (should be: #ˑThisˑisˑaˑTest)"
 
165
      norm! 'azt
 
166
      call clearmatches()
 
167
      call matchadd('Conceal', '\%2l ', 20, -1, {'conceal': "\u02d1"})
 
168
      redraw!
 
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()
 
172
    ]=])
 
173
 
 
174
    expect([=[
 
175
      
 
176
      # This is a Test
 
177
      
 
178
      Test 1: simple addmatch()
 
179
      # This is a Test    
 
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]
 
181
      
 
182
      Test 2: simple addmatch() and conceal (should be: #XThisXisXaXTest)
 
183
      #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]
 
185
      
 
186
      Test 3: addmatch() and conceallevel=3 (should be: #ThisisaTest)
 
187
      #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]
 
189
      
 
190
      Test 4: more match() (should be: #Thisisa Test)
 
191
      #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]
 
193
      
 
194
      Test 5/1: default conceal char (should be: # This is a Test)
 
195
      # 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]
 
197
      
 
198
      Test 5/2: default conceal char (should be: #+This+is+a+Test)
 
199
      #+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]
 
201
      
 
202
      Test 6/1: syn and match conceal (should be: #ZThisZisZaZTest)
 
203
      #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]
 
205
      
 
206
      Test 6/2: syn and match conceal (should be: #*This*is*a*Test)
 
207
      #*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]
 
209
      
 
210
      Test 7/1: clear matches
 
211
      # This is a Test    
 
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'}
 
214
      
 
215
      Test 7/2: reset match using setmatches()
 
216
      #ZThisZisZaZTest    
 
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]
 
218
      
 
219
      Test 8: using matchaddpos() (should be #Pis a Test
 
220
      #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'}
 
223
      
 
224
      Test 9: match using multibyte conceal char (should be: #ˑThisˑisˑaˑTest)
 
225
      #ˑ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]]=])
 
227
  end)
 
228
end)