summaryrefslogtreecommitdiff
path: root/test/test_list_opening.vader
blob: 7dc5a79be3be877b8c2e195abeaf59301090f712 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
" Author: Yann Fery <yann@fery.me>
Before:
  Save g:ale_set_loclist
  Save g:ale_set_quickfix
  Save g:ale_open_list
  Save g:ale_keep_list_window_open
  Save g:ale_list_window_size
  Save g:ale_buffer_info
  Save g:ale_set_lists_synchronously

  let g:ale_set_loclist = 1
  let g:ale_set_quickfix = 0
  let g:ale_open_list = 0
  let g:ale_keep_list_window_open = 0
  let g:ale_list_window_size = 10
  let g:ale_set_lists_synchronously = 1

  let g:loclist = [
  \ {'bufnr': bufnr(''), 'lnum': 5, 'col': 5, 'text': 'x'},
  \ {'bufnr': bufnr(''), 'lnum': 5, 'col': 4, 'text': 'x'},
  \ {'bufnr': bufnr(''), 'lnum': 2, 'col': 10, 'text': 'x'},
  \ {'bufnr': bufnr(''), 'lnum': 3, 'col': 2, 'text': 'x'},
  \]
  let g:ale_buffer_info = {bufnr(''): {'loclist': g:loclist}}

  function GetQuickfixHeight() abort
    for l:win in range(1, winnr('$'))
        if getwinvar(l:win, '&buftype') ==# 'quickfix'
            return winheight(l:win)
        endif
    endfor

    return 0
  endfunction

After:
  Restore

  unlet! g:loclist
  unlet! b:ale_list_window_size
  unlet! b:ale_open_list
  unlet! b:ale_keep_list_window_open
  unlet! b:ale_save_event_fired

  delfunction GetQuickfixHeight

  " Close quickfix window after every execute block
  lcl
  ccl
  call setloclist(0, [])
  call setqflist([])

Execute(IsQuickfixOpen should return the right output):
  AssertEqual 0, ale#list#IsQuickfixOpen()
  call setloclist(0, g:loclist)
  lopen
  AssertEqual 1, ale#list#IsQuickfixOpen()
  lcl
  AssertEqual 0, ale#list#IsQuickfixOpen()
  call setqflist(g:loclist)
  copen
  AssertEqual 1, ale#list#IsQuickfixOpen()
  ccl
  AssertEqual 0, ale#list#IsQuickfixOpen()

Execute(The quickfix window should not open by default for the loclist):
  call ale#list#SetLists(bufnr('%'), g:loclist)
  Assert !ale#list#IsQuickfixOpen()

Execute(The quickfix window should open for just the loclist):
  let g:ale_open_list = 1

  " It should not open for an empty list.
  call ale#list#SetLists(bufnr('%'), [])
  Assert !ale#list#IsQuickfixOpen()

  " With a non-empty loclist, the window must open.
  call ale#list#SetLists(bufnr('%'), g:loclist)
  Assert ale#list#IsQuickfixOpen()

  " Clear the list and it should close again.
  call ale#list#SetLists(bufnr('%'), [])
  Assert !ale#list#IsQuickfixOpen()

Execute(The quickfix window height should be correct for the loclist):
  let g:ale_open_list = 1
  let g:ale_list_window_size = 7

  call ale#list#SetLists(bufnr('%'), g:loclist)

  AssertEqual 7, GetQuickfixHeight()

Execute(The quickfix window height should be correct for the loclist with buffer variables):
  let g:ale_open_list = 1
  let b:ale_list_window_size = 8

  call ale#list#SetLists(bufnr('%'), g:loclist)

  AssertEqual 8, GetQuickfixHeight()

Execute(The quickfix window should stay open for just the loclist):
  let g:ale_open_list = 1
  let g:ale_keep_list_window_open = 1

  " The window should stay open after even after it is made blank again.
  call ale#list#SetLists(bufnr('%'), g:loclist)
  call ale#list#SetLists(bufnr('%'), [])
  Assert ale#list#IsQuickfixOpen()

Execute(The quickfix window should not open by default when quickfix is on):
  let g:ale_set_quickfix = 1

  call ale#list#SetLists(bufnr('%'), g:loclist)
  Assert !ale#list#IsQuickfixOpen()

Execute(The quickfix window should open for the quickfix list):
  let g:ale_set_quickfix = 1
  let g:ale_open_list = 1

  let g:ale_buffer_info[bufnr('') + 1] = {
  \ 'loclist': [{'bufnr': -1, 'filename': '/foo/bar', 'lnum': 5, 'col': 5, 'text': 'x'}],
  \}

  " It should not open for an empty list.
  call ale#list#SetLists(bufnr('%'), [])
  Assert !ale#list#IsQuickfixOpen(), 'The quickfix window was opened when the list was empty'

  " With a non-empty quickfix list, the window must open.
  call ale#list#SetLists(bufnr('%'), g:loclist)
  Assert ale#list#IsQuickfixOpen(), 'The quickfix window was closed when the list was not empty'

  " Clear this List. The window should stay open, as there are other items.
  let g:ale_buffer_info[bufnr('')].loclist = []
  call ale#list#SetLists(bufnr('%'), [])
  Assert ale#list#IsQuickfixOpen(), 'The quickfix window closed even though there are items in another buffer'

  " Clear the other List now. Now the window should close.
  call remove(g:ale_buffer_info, bufnr('') + 1)
  call ale#list#SetLists(bufnr('%'), [])
  Assert !ale#list#IsQuickfixOpen(), 'The quickfix window was not closed'

Execute(The quickfix window should stay open for the quickfix list):
  let g:ale_set_quickfix = 1
  let g:ale_open_list = 1
  let g:ale_keep_list_window_open = 1

  " The window should stay open after even after it is made blank again.
  call ale#list#SetLists(bufnr('%'), g:loclist)
  call ale#list#SetLists(bufnr('%'), [])
  Assert ale#list#IsQuickfixOpen()

Execute(The quickfix window height should be correct for the quickfix list):
  let g:ale_set_quickfix = 1
  let g:ale_open_list = 1
  let g:ale_list_window_size = 7

  call ale#list#SetLists(bufnr('%'), g:loclist)

  AssertEqual 7, GetQuickfixHeight()

Execute(The quickfix window height should be correct for the quickfix list with buffer variables):
  let g:ale_set_quickfix = 1
  let g:ale_open_list = 1
  let b:ale_list_window_size = 8

  call ale#list#SetLists(bufnr('%'), g:loclist)

  AssertEqual 8, GetQuickfixHeight()

Execute(The buffer ale_open_list option should be respected):
  let b:ale_open_list = 1

  call ale#list#SetLists(bufnr('%'), g:loclist)
  Assert ale#list#IsQuickfixOpen()

Execute(The buffer ale_keep_list_window_open option should be respected):
  let b:ale_open_list = 1
  let b:ale_keep_list_window_open = 1

  call ale#list#SetLists(bufnr('%'), g:loclist)
  call ale#list#SetLists(bufnr('%'), [])

  Assert ale#list#IsQuickfixOpen()

Execute(The ale_open_list='on_save' option should work):
  let b:ale_open_list = 'on_save'

  call ale#list#SetLists(bufnr('%'), g:loclist)
  " The list shouldn't open yet, the event wasn't fired.
  Assert !ale#list#IsQuickfixOpen()

  let b:ale_save_event_fired = 1

  call ale#list#SetLists(bufnr('%'), g:loclist)
  " Now the list should have opened.
  Assert ale#list#IsQuickfixOpen()

Execute(The window shouldn't open on save when ale_open_list=0):
  let b:ale_open_list = 0
  let b:ale_save_event_fired = 1

  call ale#list#SetLists(bufnr('%'), g:loclist)
  " Now the list should have opened.
  Assert !ale#list#IsQuickfixOpen()