]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/test/test_virtualtext.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 'a39f715c13be3352193ffd9c5b7536b8786eff64' as '.vim/bundle/vim-lsp'
[etc/vim.git] / .vim / bundle / ale / test / test_virtualtext.vader
1 Before:
2   Save g:ale_buffer_info
3   Save g:ale_virtualtext_cursor
4   Save g:ale_virtualtext_delay
5   Save g:ale_virtualtext_single
6   Save g:ale_virtualtext_prefix
7   Save b:ale_virtualtext_prefix
8   Save g:ale_use_neovim_diagnostics_api
9
10   call ale#virtualtext#ResetDataForTests()
11
12   let g:setting = ''
13   let g:ale_virtualtext_prefix = '%comment% %type%: '
14   let g:ale_virtualtext_delay = 0
15   let g:ale_virtualtext_single = 0
16   let g:ale_buffer_info = {
17   \ bufnr(''): {
18   \   'loclist': [
19   \     {
20   \       'bufnr': bufnr(''),
21   \       'type': 'E',
22   \       'lnum': 1,
23   \       'col': 5,
24   \       'text': 'Line 1 error',
25   \     },
26   \     {
27   \       'bufnr': bufnr(''),
28   \       'type': 'W',
29   \       'lnum': 2,
30   \       'col': 1,
31   \       'text': 'Line 2 warning 1',
32   \     },
33   \     {
34   \       'bufnr': bufnr(''),
35   \       'type': 'W',
36   \       'lnum': 2,
37   \       'col': 5,
38   \       'text': 'Line 2 warning 2',
39   \     },
40   \     {
41   \       'bufnr': bufnr(''),
42   \       'type': 'W',
43   \       'lnum': 3,
44   \       'col': 3,
45   \       'text': 'Line 3 warning 1',
46   \     },
47   \     {
48   \       'bufnr': bufnr(''),
49   \       'type': 'E',
50   \       'lnum': 3,
51   \       'col': 5,
52   \       'text': 'Line 3 error 1',
53   \     },
54   \     {
55   \       'bufnr': bufnr(''),
56   \       'type': 'E',
57   \       'lnum': 3,
58   \       'col': 6,
59   \       'text': 'Line 3 error 2',
60   \     },
61   \   ],
62   \ },
63   \}
64   let g:ale_use_neovim_diagnostics_api = 0
65
66 After:
67   Restore
68
69   unlet! g:setting
70   unlet! g:ns_id
71
72 Execute(The correct highlight groups should be loaded for virtual-text):
73   AssertEqual 'ALEVirtualTextError', ale#virtualtext#GetGroup({})
74   AssertEqual 'ALEVirtualTextError', ale#virtualtext#GetGroup({'type': 'E'})
75   AssertEqual 'ALEVirtualTextStyleError',
76   \ ale#virtualtext#GetGroup({'type': 'E', 'sub_type': 'style'})
77   AssertEqual 'ALEVirtualTextWarning', ale#virtualtext#GetGroup({'type': 'W'})
78   AssertEqual 'ALEVirtualTextStyleWarning',
79   \ ale#virtualtext#GetGroup({'type': 'W', 'sub_type': 'style'})
80   AssertEqual 'ALEVirtualTextInfo', ale#virtualtext#GetGroup({'type': 'I'})
81
82 Given python (An empty Python file):
83 Execute(Comment text should be detected correctly for Python files):
84   if has('patch-9.0.0297') || has('nvim-0.8.0')
85     AssertEqual '#', ale#virtualtext#GetComment(bufnr(''))
86   endif
87
88 Given java (An empty Java file):
89 Execute(Comment text should be detected correctly for Java files):
90   if has('patch-9.0.0297') || has('nvim-0.8.0')
91     AssertEqual '//', ale#virtualtext#GetComment(bufnr(''))
92   endif
93
94 Given html (An empty HTML file):
95 Execute(Comment text should be detected correctly for HTML files):
96   if has('patch-9.0.0297') || has('nvim-0.8.0')
97     AssertEqual "\<!--", ale#virtualtext#GetComment(bufnr(''))
98   endif
99
100 Given python(An example Python file):
101   # line 1
102   # line 2
103   # line 3
104
105 Execute(We should not show virtualtext when disabled):
106   if has('patch-9.0.0297') || has('nvim-0.8.0')
107     for g:setting in ['disabled', '0', 0]
108       call ale#virtualtext#ResetDataForTests()
109
110       let g:ale_virtualtext_cursor = g:setting
111       call cursor(1, 1)
112       call ale#virtualtext#ShowCursorWarningWithDelay()
113       " Tick the timer.
114       sleep 1ms
115
116       AssertEqual '', ale#virtualtext#GetLastMessageForTests()
117     endfor
118   endif
119
120 Execute(We should find a virtualtext error on line 1):
121   if has('patch-9.0.0297') || has('nvim-0.8.0')
122     for g:setting in ['current', '1', 1]
123       call ale#virtualtext#ResetDataForTests()
124
125       let g:ale_virtualtext_cursor = 'current'
126       call cursor(1, 1)
127       call ale#virtualtext#ShowCursorWarningWithDelay()
128       " Tick the timer.
129       sleep 1ms
130
131       AssertEqual '# E: Line 1 error', ale#virtualtext#GetLastMessageForTests()
132
133       if has('patch-9.0.0297')
134         AssertEqual ['ALEVirtualTextError'], map(prop_list(1), {_, v -> v.type})
135         AssertEqual [], prop_list(2)
136       endif
137     endfor
138   endif
139
140 Execute(We should find a virtualtext error on line 2):
141   if has('patch-9.0.0297') || has('nvim-0.8.0')
142     let g:ale_virtualtext_cursor = 'current'
143     call cursor(2, 5)
144     call ale#virtualtext#ShowCursorWarningWithDelay()
145     " Tick the timer.
146     sleep 1ms
147
148     AssertEqual '# W: Line 2 warning 2', ale#virtualtext#GetLastMessageForTests()
149
150     if has('patch-9.0.0297')
151       AssertEqual [], prop_list(1)
152       AssertEqual ['ALEVirtualTextWarning'], map(prop_list(2), {_, v -> v.type})
153     endif
154   endif
155
156 Execute(We should be able to change the virtualtext prefix globally):
157   let g:ale_virtualtext_prefix = '%severity%: '
158
159   if has('patch-9.0.0297') || has('nvim-0.8.0')
160     let g:ale_virtualtext_cursor = 'current'
161     call cursor(1, 1)
162     call ale#virtualtext#ShowCursorWarningWithDelay()
163     " Tick the timer.
164     sleep 1ms
165
166     AssertEqual 'Error: Line 1 error', ale#virtualtext#GetLastMessageForTests()
167   endif
168
169 Execute(We should be able to change the virtualtext prefix per-buffer):
170   let b:ale_virtualtext_prefix = 'B> '
171
172   if has('patch-9.0.0297') || has('nvim-0.8.0')
173     let g:ale_virtualtext_cursor = 'current'
174     call cursor(1, 1)
175     call ale#virtualtext#ShowCursorWarningWithDelay()
176     " Tick the timer.
177     sleep 1ms
178
179     AssertEqual 'B> Line 1 error', ale#virtualtext#GetLastMessageForTests()
180   endif
181
182 Execute(We should be able to set messages across all lines):
183   if has('patch-9.0.0297') || has('nvim-0.8.0')
184     call ale#virtualtext#SetTexts(bufnr(''), g:ale_buffer_info[bufnr('')].loclist)
185
186     AssertEqual '# E: Line 3 error 2', ale#virtualtext#GetLastMessageForTests()
187
188     if has('patch-9.0.0297')
189       AssertEqual ['ALEVirtualTextError'], map(prop_list(1), {_, v -> v.type})
190       AssertEqual ['ALEVirtualTextWarning', 'ALEVirtualTextWarning'],
191       \ map(prop_list(2), {_, v -> v.type})
192     endif
193   endif
194
195 Execute(We should be able to limit virtual messages to the first one only):
196   let g:ale_virtualtext_single = 1
197
198   if has('patch-9.0.0297') || has('nvim-0.8.0')
199     call ale#virtualtext#SetTexts(bufnr(''), g:ale_buffer_info[bufnr('')].loclist)
200
201     AssertEqual '# E: Line 3 error 1', ale#virtualtext#GetLastMessageForTests()
202
203     if has('patch-9.0.0297')
204       AssertEqual ['ALEVirtualTextError'], map(prop_list(1), {_, v -> v.type})
205       AssertEqual ['ALEVirtualTextWarning'], map(prop_list(2), {_, v -> v.type})
206       AssertEqual ['ALEVirtualTextError'], map(prop_list(3), {_, v -> v.type})
207     endif
208   endif
209
210 Execute(We should not set cursor messages when Neovim diagnostics are enabled):
211   let g:ale_use_neovim_diagnostics_api = 1
212
213   if has('patch-9.0.0297') || has('nvim-0.8.0')
214     let g:ale_virtualtext_cursor = 'current'
215     call cursor(1, 1)
216     call ale#virtualtext#ShowCursorWarningWithDelay()
217     " Tick the timer.
218     sleep 1ms
219
220     AssertEqual '', ale#virtualtext#GetLastMessageForTests()
221   endif