summaryrefslogtreecommitdiff
path: root/test/test_list_formatting.vader
blob: d79a664b2dccd31ac041f6930b0ba8807e7f7c9e (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
Before:
  Save g:ale_set_loclist
  Save g:ale_set_quickfix
  Save g:ale_loclist_msg_format
  Save g:ale_open_list
  Save g:ale_buffer_info
  Save g:ale_set_lists_synchronously

  let g:ale_set_lists_synchronously = 1
  let g:ale_loclist_msg_format = '%code: %%s'
  let g:ale_open_list = 0
  let g:loclist = []
  let g:ale_buffer_info = {bufnr(''): {'loclist': g:loclist}}

  function! AddItem(data) abort
    let l:item = {
    \ 'bufnr': bufnr(''),
    \ 'lnum': 1,
    \ 'col': 1,
    \ 'type': 'E',
    \ 'linter_name': 'some_linter',
    \}

    call add(g:loclist, extend(l:item, a:data))
  endfunction

After:
  Restore

  unlet! g:loclist
  unlet! b:ale_loclist_msg_format

  delfunction AddItem

  call setloclist(0, [])
  call setqflist([])

Execute(Formatting with codes should work for the loclist):
  call AddItem({'text': "nocode\r"})
  call ale#list#SetLists(bufnr(''), g:loclist)

  AssertEqual
  \ [
  \   {
  \     'lnum': 1,
  \     'bufnr': bufnr(''),
  \     'col': 1,
  \     'valid': 1,
  \     'vcol': 0,
  \     'nr': 0,
  \     'type': 'E',
  \     'pattern': '',
  \     'text': 'nocode',
  \   },
  \ ],
  \ ale#test#GetLoclistWithoutModule()

  call remove(g:loclist, 0)
  call AddItem({'text': 'withcode', 'code': 'E123'})
  call ale#list#SetLists(bufnr(''), g:loclist)

  AssertEqual
  \ [
  \   {
  \     'lnum': 1,
  \     'bufnr': bufnr(''),
  \     'col': 1,
  \     'valid': 1,
  \     'vcol': 0,
  \     'nr': 0,
  \     'type': 'E',
  \     'pattern': '',
  \     'text': 'E123: withcode',
  \   },
  \ ],
  \ ale#test#GetLoclistWithoutModule()

Execute(Formatting with codes should work for the quickfix list):
  let g:ale_set_loclist = 0
  let g:ale_set_quickfix = 1

  call AddItem({'text': "nocode\r"})
  call ale#list#SetLists(bufnr(''), g:loclist)

  AssertEqual
  \ [
  \   {
  \     'lnum': 1,
  \     'bufnr': bufnr(''),
  \     'col': 1,
  \     'valid': 1,
  \     'vcol': 0,
  \     'nr': 0,
  \     'type': 'E',
  \     'pattern': '',
  \     'text': 'nocode',
  \   },
  \ ],
  \ ale#test#GetQflistWithoutModule()

  call remove(g:loclist, 0)
  call AddItem({'text': 'withcode', 'code': 'E123'})
  call ale#list#SetLists(bufnr(''), g:loclist)

  AssertEqual
  \ [
  \   {
  \     'lnum': 1,
  \     'bufnr': bufnr(''),
  \     'col': 1,
  \     'valid': 1,
  \     'vcol': 0,
  \     'nr': 0,
  \     'type': 'E',
  \     'pattern': '',
  \     'text': 'E123: withcode',
  \   },
  \ ],
  \ ale#test#GetQflistWithoutModule()

Execute(Formatting with the linter name should work for the loclist):
  let g:ale_loclist_msg_format = '(%linter%) %s'

  call AddItem({'text': 'whatever'})
  call ale#list#SetLists(bufnr(''), g:loclist)

  AssertEqual
  \ [
  \   {
  \     'lnum': 1,
  \     'bufnr': bufnr(''),
  \     'col': 1,
  \     'valid': 1,
  \     'vcol': 0,
  \     'nr': 0,
  \     'type': 'E',
  \     'pattern': '',
  \     'text': '(some_linter) whatever',
  \   },
  \ ],
  \ ale#test#GetLoclistWithoutModule()

Execute(Formatting with the linter name should work for the quickfix list):
  let g:ale_loclist_msg_format = '(%linter%) %s'
  let g:ale_set_loclist = 0
  let g:ale_set_quickfix = 1

  call AddItem({'text': 'whatever'})
  call ale#list#SetLists(bufnr(''), g:loclist)

  AssertEqual
  \ [
  \   {
  \     'lnum': 1,
  \     'bufnr': bufnr(''),
  \     'col': 1,
  \     'valid': 1,
  \     'vcol': 0,
  \     'nr': 0,
  \     'type': 'E',
  \     'pattern': '',
  \     'text': '(some_linter) whatever',
  \   },
  \ ],
  \ ale#test#GetQflistWithoutModule()

Execute(The buffer loclist format option should take precedence):
  let g:ale_loclist_msg_format = '(%linter%) %s'
  let b:ale_loclist_msg_format = 'FOO %s'

  call AddItem({'text': 'whatever'})
  call ale#list#SetLists(bufnr(''), g:loclist)

  AssertEqual
  \ [
  \   {
  \     'lnum': 1,
  \     'bufnr': bufnr(''),
  \     'col': 1,
  \     'valid': 1,
  \     'vcol': 0,
  \     'nr': 0,
  \     'type': 'E',
  \     'pattern': '',
  \     'text': 'FOO whatever',
  \   },
  \ ],
  \ ale#test#GetLoclistWithoutModule()