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

« back to all changes in this revision

Viewing changes to test/functional/ui/bufhl_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
local helpers = require('test.functional.helpers')
 
2
local Screen = require('test.functional.ui.screen')
 
3
local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert
 
4
local execute, request, neq = helpers.execute, helpers.request, helpers.neq
 
5
 
 
6
 
 
7
describe('Buffer highlighting', function()
 
8
  local screen
 
9
  local curbuf
 
10
 
 
11
  local hl_colors = {
 
12
    NonText = Screen.colors.Blue,
 
13
    Question = Screen.colors.SeaGreen,
 
14
    String = Screen.colors.Fuchsia,
 
15
    Statement = Screen.colors.Brown,
 
16
    Special = Screen.colors.SlateBlue,
 
17
    Identifier = Screen.colors.DarkCyan
 
18
  }
 
19
 
 
20
  before_each(function()
 
21
    clear()
 
22
    execute("syntax on")
 
23
    screen = Screen.new(40, 8)
 
24
    screen:attach()
 
25
    screen:set_default_attr_ignore( {{bold=true, foreground=hl_colors.NonText}} )
 
26
    screen:set_default_attr_ids({
 
27
      [1] = {foreground = hl_colors.String},
 
28
      [2] = {foreground = hl_colors.Statement, bold = true},
 
29
      [3] = {foreground = hl_colors.Special},
 
30
      [4] = {bold = true, foreground = hl_colors.Special},
 
31
      [5] = {foreground = hl_colors.Identifier},
 
32
      [6] = {bold = true},
 
33
      [7] = {underline = true, bold = true, foreground = hl_colors.Special},
 
34
      [8] = {foreground = hl_colors.Special, underline = true}
 
35
    })
 
36
    curbuf = request('vim_get_current_buffer')
 
37
  end)
 
38
 
 
39
  after_each(function()
 
40
    screen:detach()
 
41
  end)
 
42
 
 
43
  local function add_hl(...)
 
44
    return request('buffer_add_highlight', curbuf, ...)
 
45
  end
 
46
 
 
47
  local function clear_hl(...)
 
48
    return request('buffer_clear_highlight', curbuf, ...)
 
49
  end
 
50
 
 
51
 
 
52
  it('works', function()
 
53
    insert([[
 
54
      these are some lines
 
55
      with colorful text]])
 
56
    feed('+')
 
57
 
 
58
    screen:expect([[
 
59
      these are some lines                    |
 
60
      with colorful tex^t                      |
 
61
      ~                                       |
 
62
      ~                                       |
 
63
      ~                                       |
 
64
      ~                                       |
 
65
      ~                                       |
 
66
                                              |
 
67
    ]])
 
68
 
 
69
    add_hl(-1, "String", 0 , 10, 14)
 
70
    add_hl(-1, "Statement", 1 , 5, -1)
 
71
 
 
72
    screen:expect([[
 
73
      these are {1:some} lines                    |
 
74
      with {2:colorful tex^t}                      |
 
75
      ~                                       |
 
76
      ~                                       |
 
77
      ~                                       |
 
78
      ~                                       |
 
79
      ~                                       |
 
80
                                              |
 
81
    ]])
 
82
 
 
83
    feed("ggo<esc>")
 
84
    screen:expect([[
 
85
      these are {1:some} lines                    |
 
86
      ^                                        |
 
87
      with {2:colorful text}                      |
 
88
      ~                                       |
 
89
      ~                                       |
 
90
      ~                                       |
 
91
      ~                                       |
 
92
                                              |
 
93
    ]])
 
94
 
 
95
    clear_hl(-1, 0 , -1)
 
96
    screen:expect([[
 
97
      these are some lines                    |
 
98
      ^                                        |
 
99
      with colorful text                      |
 
100
      ~                                       |
 
101
      ~                                       |
 
102
      ~                                       |
 
103
      ~                                       |
 
104
                                              |
 
105
    ]])
 
106
  end)
 
107
 
 
108
  describe('support adding multiple sources', function()
 
109
    local id1, id2
 
110
    before_each(function()
 
111
      insert([[
 
112
        a longer example
 
113
        in order to demonstrate
 
114
        combining highlights
 
115
        from different sources]])
 
116
 
 
117
      execute("hi ImportantWord gui=bold cterm=bold")
 
118
      id1 = add_hl(0, "ImportantWord", 0, 2, 8)
 
119
      add_hl(id1, "ImportantWord", 1, 12, -1)
 
120
      add_hl(id1, "ImportantWord", 2, 0, 9)
 
121
      add_hl(id1, "ImportantWord", 3, 5, 14)
 
122
 
 
123
      id2 = add_hl(0, "Special", 0, 2, 8)
 
124
      add_hl(id2, "Identifier", 1, 3, 8)
 
125
      add_hl(id2, "Special", 1, 14, 20)
 
126
      add_hl(id2, "Underlined", 2, 6, 12)
 
127
      add_hl(id2, "Underlined", 3, 0, 9)
 
128
      neq(id1, id2)
 
129
 
 
130
      screen:expect([[
 
131
        a {4:longer} example                        |
 
132
        in {5:order} to {6:de}{4:monstr}{6:ate}                 |
 
133
        {6:combin}{7:ing}{8: hi}ghlights                    |
 
134
        {8:from }{7:diff}{6:erent} source^s                  |
 
135
        ~                                       |
 
136
        ~                                       |
 
137
        ~                                       |
 
138
        :hi ImportantWord gui=bold cterm=bold   |
 
139
      ]])
 
140
    end)
 
141
 
 
142
    it('and clearing the first added', function()
 
143
      clear_hl(id1, 0, -1)
 
144
      screen:expect([[
 
145
        a {3:longer} example                        |
 
146
        in {5:order} to de{3:monstr}ate                 |
 
147
        combin{8:ing hi}ghlights                    |
 
148
        {8:from diff}erent source^s                  |
 
149
        ~                                       |
 
150
        ~                                       |
 
151
        ~                                       |
 
152
        :hi ImportantWord gui=bold cterm=bold   |
 
153
      ]])
 
154
    end)
 
155
 
 
156
    it('and clearing the second added', function()
 
157
      clear_hl(id2, 0, -1)
 
158
      screen:expect([[
 
159
        a {6:longer} example                        |
 
160
        in order to {6:demonstrate}                 |
 
161
        {6:combining} highlights                    |
 
162
        from {6:different} source^s                  |
 
163
        ~                                       |
 
164
        ~                                       |
 
165
        ~                                       |
 
166
        :hi ImportantWord gui=bold cterm=bold   |
 
167
      ]])
 
168
    end)
 
169
 
 
170
    it('and clearing line ranges', function()
 
171
      clear_hl(-1, 0, 1)
 
172
      clear_hl(id1, 1, 2)
 
173
      clear_hl(id2, 2, -1)
 
174
      screen:expect([[
 
175
        a longer example                        |
 
176
        in {5:order} to de{3:monstr}ate                 |
 
177
        {6:combining} highlights                    |
 
178
        from {6:different} source^s                  |
 
179
        ~                                       |
 
180
        ~                                       |
 
181
        ~                                       |
 
182
        :hi ImportantWord gui=bold cterm=bold   |
 
183
      ]])
 
184
    end)
 
185
 
 
186
    it('and renumbering lines', function()
 
187
      feed('3Gddggo<esc>')
 
188
      screen:expect([[
 
189
        a {4:longer} example                        |
 
190
        ^                                        |
 
191
        in {5:order} to {6:de}{4:monstr}{6:ate}                 |
 
192
        {8:from }{7:diff}{6:erent} sources                  |
 
193
        ~                                       |
 
194
        ~                                       |
 
195
        ~                                       |
 
196
                                                |
 
197
      ]])
 
198
 
 
199
      execute(':3move 4')
 
200
      screen:expect([[
 
201
        a {4:longer} example                        |
 
202
                                                |
 
203
        {8:from }{7:diff}{6:erent} sources                  |
 
204
        ^in {5:order} to {6:de}{4:monstr}{6:ate}                 |
 
205
        ~                                       |
 
206
        ~                                       |
 
207
        ~                                       |
 
208
        ::3move 4                               |
 
209
      ]])
 
210
    end)
 
211
  end)
 
212
 
 
213
  it('prioritizes latest added highlight', function()
 
214
    insert([[
 
215
      three overlapping colors]])
 
216
    add_hl(0, "Identifier", 0, 6, 17)
 
217
    add_hl(0, "String", 0, 14, 23)
 
218
    local id = add_hl(0, "Special", 0, 0, 9)
 
219
 
 
220
    screen:expect([[
 
221
      {3:three ove}{5:rlapp}{1:ing color}^s                |
 
222
      ~                                       |
 
223
      ~                                       |
 
224
      ~                                       |
 
225
      ~                                       |
 
226
      ~                                       |
 
227
      ~                                       |
 
228
                                              |
 
229
    ]])
 
230
 
 
231
    clear_hl(id, 0, 1)
 
232
    screen:expect([[
 
233
      three {5:overlapp}{1:ing color}^s                |
 
234
      ~                                       |
 
235
      ~                                       |
 
236
      ~                                       |
 
237
      ~                                       |
 
238
      ~                                       |
 
239
      ~                                       |
 
240
                                              |
 
241
    ]])
 
242
  end)
 
243
 
 
244
  it('works with multibyte text', function()
 
245
    insert([[
 
246
      Ta båten över sjön!]])
 
247
    add_hl(-1, "Identifier", 0, 3, 9)
 
248
    add_hl(-1, "String", 0, 16, 21)
 
249
 
 
250
    screen:expect([[
 
251
      Ta {5:båten} över {1:sjön}^!                     |
 
252
      ~                                       |
 
253
      ~                                       |
 
254
      ~                                       |
 
255
      ~                                       |
 
256
      ~                                       |
 
257
      ~                                       |
 
258
                                              |
 
259
    ]])
 
260
  end)
 
261
end)