]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/test/test_list_opening.vader

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Merge commit '76265755a1add77121c8f9dabb3e9bb70fe9a972' as '.vim/bundle/ale'
[etc/vim.git] / .vim / bundle / ale / test / test_list_opening.vader
1 " Author: Yann Fery <yann@fery.me>
2 Before:
3   Save g:ale_set_loclist
4   Save g:ale_set_quickfix
5   Save g:ale_open_list
6   Save g:ale_keep_list_window_open
7   Save g:ale_list_window_size
8   Save g:ale_list_vertical
9   Save g:ale_buffer_info
10   Save g:ale_set_lists_synchronously
11
12   let g:ale_set_loclist = 1
13   let g:ale_set_quickfix = 0
14   let g:ale_open_list = 0
15   let g:ale_keep_list_window_open = 0
16   let g:ale_list_window_size = 10
17   let g:ale_list_vertical = 0
18   let g:ale_set_lists_synchronously = 1
19
20   let g:loclist = [
21   \ {'bufnr': bufnr(''), 'lnum': 5, 'col': 5, 'text': 'x'},
22   \ {'bufnr': bufnr(''), 'lnum': 5, 'col': 4, 'text': 'x'},
23   \ {'bufnr': bufnr(''), 'lnum': 2, 'col': 10, 'text': 'x'},
24   \ {'bufnr': bufnr(''), 'lnum': 3, 'col': 2, 'text': 'x'},
25   \]
26   let g:ale_buffer_info = {bufnr(''): {'loclist': g:loclist}}
27
28   function GetQuickfixHeight() abort
29     for l:win in range(1, winnr('$'))
30         if getwinvar(l:win, '&buftype') ==# 'quickfix'
31             return winheight(l:win)
32         endif
33     endfor
34
35     return 0
36   endfunction
37
38   " If the window is vertical, window size should match column size/width
39   function GetQuickfixIsVertical(cols) abort
40     for l:win in range(1, winnr('$'))
41         if getwinvar(l:win, '&buftype') is# 'quickfix'
42             return winwidth(l:win) == a:cols
43         endif
44     endfor
45
46     return 0
47   endfunction
48
49 After:
50   Restore
51
52   unlet! g:loclist
53   unlet! b:ale_list_vertical
54   unlet! b:ale_list_window_size
55   unlet! b:ale_open_list
56   unlet! b:ale_keep_list_window_open
57   unlet! b:ale_save_event_fired
58
59   delfunction GetQuickfixHeight
60   delfunction GetQuickfixIsVertical
61
62   " Close quickfix window after every execute block
63   lcl
64   ccl
65   call setloclist(0, [])
66   call setqflist([])
67
68 Execute(IsQuickfixOpen should return the right output):
69   AssertEqual 0, ale#list#IsQuickfixOpen()
70   call setloclist(0, g:loclist)
71   lopen
72   AssertEqual 1, ale#list#IsQuickfixOpen()
73   lcl
74   AssertEqual 0, ale#list#IsQuickfixOpen()
75   call setqflist(g:loclist)
76   copen
77   AssertEqual 1, ale#list#IsQuickfixOpen()
78   ccl
79   AssertEqual 0, ale#list#IsQuickfixOpen()
80
81 Execute(The quickfix window should not open by default for the loclist):
82   call ale#list#SetLists(bufnr('%'), g:loclist)
83   Assert !ale#list#IsQuickfixOpen()
84
85 Execute(The quickfix window should open for just the loclist):
86   let g:ale_open_list = 1
87
88   " It should not open for an empty list.
89   call ale#list#SetLists(bufnr('%'), [])
90   Assert !ale#list#IsQuickfixOpen()
91
92   " With a non-empty loclist, the window must open.
93   call ale#list#SetLists(bufnr('%'), g:loclist)
94   Assert ale#list#IsQuickfixOpen()
95
96   " Clear the list and it should close again.
97   call ale#list#SetLists(bufnr('%'), [])
98   Assert !ale#list#IsQuickfixOpen()
99
100 Execute(The quickfix window should open on the correct threshold):
101   " The window should open for a value lower than number of entries.
102   let g:ale_open_list = len(g:loclist) - 1
103   call ale#list#SetLists(bufnr('%'), g:loclist)
104   Assert ale#list#IsQuickfixOpen()
105
106   " Clear the list to be ready for a new value.
107   call ale#list#SetLists(bufnr('%'), [])
108   Assert !ale#list#IsQuickfixOpen()
109
110   " It should also open for a value equal to the number of entries.
111   let g:ale_open_list = len(g:loclist)
112   call ale#list#SetLists(bufnr('%'), g:loclist)
113   Assert ale#list#IsQuickfixOpen()
114
115   " Clear the list again, preparing for a final value.
116   call ale#list#SetLists(bufnr('%'), [])
117   Assert !ale#list#IsQuickfixOpen()
118
119   " Window should not open for values higher than number of loclist entries.
120   let g:ale_open_list = len(g:loclist) + 1
121   call ale#list#SetLists(bufnr('%'), g:loclist)
122   Assert !ale#list#IsQuickfixOpen()
123
124   " Clear the list just to clean up.
125   call ale#list#SetLists(bufnr('%'), [])
126   Assert !ale#list#IsQuickfixOpen()
127
128 Execute(The quickfix window height should be correct for the loclist):
129   let g:ale_open_list = 1
130   let g:ale_list_window_size = 7
131
132   call ale#list#SetLists(bufnr('%'), g:loclist)
133
134   AssertEqual 7, GetQuickfixHeight()
135
136 Execute(The quickfix window height should be correct for the loclist with buffer variables):
137   let g:ale_open_list = 1
138   let b:ale_list_window_size = 8
139
140   call ale#list#SetLists(bufnr('%'), g:loclist)
141
142   AssertEqual 8, GetQuickfixHeight()
143
144 Execute(The quickfix window should be vertical for the loclist with appropriate variables):
145   let g:ale_open_list = 1
146   let b:ale_list_window_size = 8
147   let b:ale_list_vertical = 1
148
149   call ale#list#SetLists(bufnr('%'), g:loclist)
150
151   AssertEqual 1, GetQuickfixIsVertical(8)
152
153 Execute(The quickfix window should be horizontal for the loclist with appropriate variables):
154   let g:ale_open_list = 1
155   let b:ale_list_window_size = 8
156   let b:ale_list_vertical = 0
157
158   call ale#list#SetLists(bufnr('%'), g:loclist)
159
160   AssertEqual 0, GetQuickfixIsVertical(8)
161
162 Execute(The quickfix window should stay open for just the loclist):
163   let g:ale_open_list = 1
164   let g:ale_keep_list_window_open = 1
165
166   " The window should stay open after even after it is made blank again.
167   call ale#list#SetLists(bufnr('%'), g:loclist)
168   call ale#list#SetLists(bufnr('%'), [])
169   Assert ale#list#IsQuickfixOpen()
170
171 Execute(The quickfix window should not open by default when quickfix is on):
172   let g:ale_set_quickfix = 1
173
174   call ale#list#SetLists(bufnr('%'), g:loclist)
175   Assert !ale#list#IsQuickfixOpen()
176
177 Execute(The quickfix window should open for the quickfix list):
178   let g:ale_set_quickfix = 1
179   let g:ale_open_list = 1
180
181   let g:ale_buffer_info[bufnr('') + 1] = {
182   \ 'loclist': [{'bufnr': -1, 'filename': '/foo/bar', 'lnum': 5, 'col': 5, 'text': 'x'}],
183   \}
184
185   " It should not open for an empty list.
186   call ale#list#SetLists(bufnr('%'), [])
187   Assert !ale#list#IsQuickfixOpen(), 'The quickfix window was opened when the list was empty'
188
189   " With a non-empty quickfix list, the window must open.
190   call ale#list#SetLists(bufnr('%'), g:loclist)
191   Assert ale#list#IsQuickfixOpen(), 'The quickfix window was closed when the list was not empty'
192
193   " Clear this List. The window should stay open, as there are other items.
194   let g:ale_buffer_info[bufnr('')].loclist = []
195   call ale#list#SetLists(bufnr('%'), [])
196   Assert ale#list#IsQuickfixOpen(), 'The quickfix window closed even though there are items in another buffer'
197
198   " Clear the other List now. Now the window should close.
199   call remove(g:ale_buffer_info, bufnr('') + 1)
200   call ale#list#SetLists(bufnr('%'), [])
201   Assert !ale#list#IsQuickfixOpen(), 'The quickfix window was not closed'
202
203 Execute(The quickfix window should stay open for the quickfix list):
204   let g:ale_set_quickfix = 1
205   let g:ale_open_list = 1
206   let g:ale_keep_list_window_open = 1
207
208   " The window should stay open after even after it is made blank again.
209   call ale#list#SetLists(bufnr('%'), g:loclist)
210   call ale#list#SetLists(bufnr('%'), [])
211   Assert ale#list#IsQuickfixOpen()
212
213 Execute(The quickfix window height should be correct for the quickfix list):
214   let g:ale_set_quickfix = 1
215   let g:ale_open_list = 1
216   let g:ale_list_window_size = 7
217
218   call ale#list#SetLists(bufnr('%'), g:loclist)
219
220   AssertEqual 7, GetQuickfixHeight()
221
222 Execute(The quickfix window height should be correct for the quickfix list with buffer variables):
223   let g:ale_set_quickfix = 1
224   let g:ale_open_list = 1
225   let b:ale_list_window_size = 8
226
227   call ale#list#SetLists(bufnr('%'), g:loclist)
228
229   AssertEqual 8, GetQuickfixHeight()
230
231 Execute(The quickfix window should be vertical for the quickfix with appropriate variables):
232   let g:ale_open_list = 1
233   let b:ale_list_window_size = 8
234   let b:ale_list_vertical = 1
235
236   call ale#list#SetLists(bufnr('%'), g:loclist)
237
238   AssertEqual 1, GetQuickfixIsVertical(8)
239
240 Execute(The quickfix window should be horizontal for the quickfix with appropriate variables):
241   let g:ale_open_list = 1
242   let b:ale_list_window_size = 8
243   let b:ale_list_vertical = 0
244
245   call ale#list#SetLists(bufnr('%'), g:loclist)
246
247   AssertEqual 0, GetQuickfixIsVertical(8)
248
249 Execute(buffer-local options should be respected):
250   let b:ale_open_list = 1
251   let b:ale_keep_list_window_open = 1
252
253   call ale#list#SetLists(bufnr('%'), g:loclist)
254   call ale#list#SetLists(bufnr('%'), [])
255
256   Assert ale#list#IsQuickfixOpen()
257
258 Execute(The ale_open_list='on_save' option should work):
259   let b:ale_open_list = 'on_save'
260
261   call ale#list#SetLists(bufnr('%'), g:loclist)
262   " The list shouldn't open yet, the event wasn't fired.
263   Assert !ale#list#IsQuickfixOpen()
264
265   " Turn this option off, to ensure that we update lists immediately when we
266   " save buffers.
267   let g:ale_set_lists_synchronously = 0
268   let b:ale_save_event_fired = 1
269
270   call ale#list#SetLists(bufnr('%'), g:loclist)
271   " Now the list should have opened.
272   Assert ale#list#IsQuickfixOpen()
273
274   call ale#list#SetLists(bufnr('%'), [])
275   " The window should close again when the loclist is empty.
276   Assert !ale#list#IsQuickfixOpen()
277
278 Execute(The window shouldn't open on save when ale_open_list=0):
279   let b:ale_open_list = 0
280   let b:ale_save_event_fired = 1
281
282   call ale#list#SetLists(bufnr('%'), g:loclist)
283   " Now the list should have opened.
284   Assert !ale#list#IsQuickfixOpen()