]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/test/lsp/test_lsp_connections.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 '56df844d3c39ec494dacc69eae34272b27db185a' as '.vim/bundle/asyncomplete'
[etc/vim.git] / .vim / bundle / ale / test / lsp / test_lsp_connections.vader
1 Before:
2   let g:ale_lsp_next_message_id = 1
3
4 After:
5   if exists('b:conn') && has_key(b:conn, 'id')
6     call ale#lsp#RemoveConnectionWithID(b:conn.id)
7   endif
8
9   unlet! b:data
10   unlet! b:conn
11
12 Execute(GetNextMessageID() should increment appropriately):
13   " We should get the initial ID, and increment a bit.
14   AssertEqual 1, ale#lsp#GetNextMessageID()
15   AssertEqual 2, ale#lsp#GetNextMessageID()
16   AssertEqual 3, ale#lsp#GetNextMessageID()
17
18   " Set the maximum ID.
19   let g:ale_lsp_next_message_id = 9223372036854775807
20
21   " When we hit the maximum ID, the next ID afterwards should be 1.
22   AssertEqual 9223372036854775807, ale#lsp#GetNextMessageID()
23   AssertEqual 1, ale#lsp#GetNextMessageID()
24
25 Execute(ale#lsp#CreateMessageData() should create an appropriate message):
26     " NeoVim outputs JSON with spaces, so the output is a little different.
27     if has('nvim')
28       " 79 is the size in bytes for UTF-8, not the number of characters.
29       AssertEqual
30       \ [
31       \   1,
32       \   "Content-Length: 79\r\n\r\n"
33       \   . '{"method": "someMethod", "jsonrpc": "2.0", "id": 1, "params": {"foo": "barÜ"}}',
34       \ ],
35       \ ale#lsp#CreateMessageData([0, 'someMethod', {'foo': 'barÜ'}])
36       " Check again to ensure that we use the next ID.
37       AssertEqual
38       \ [
39       \   2,
40       \   "Content-Length: 79\r\n\r\n"
41       \   . '{"method": "someMethod", "jsonrpc": "2.0", "id": 2, "params": {"foo": "barÜ"}}',
42       \ ],
43       \ ale#lsp#CreateMessageData([0, 'someMethod', {'foo': 'barÜ'}])
44     else
45       AssertEqual
46       \ [
47       \   1,
48       \   "Content-Length: 71\r\n\r\n"
49       \   . '{"method":"someMethod","jsonrpc":"2.0","id":1,"params":{"foo":"barÜ"}}',
50       \ ],
51       \ ale#lsp#CreateMessageData([0, 'someMethod', {'foo': 'barÜ'}])
52       AssertEqual
53       \ [
54       \   2,
55       \   "Content-Length: 71\r\n\r\n"
56       \   . '{"method":"someMethod","jsonrpc":"2.0","id":2,"params":{"foo":"barÜ"}}',
57       \ ],
58       \ ale#lsp#CreateMessageData([0, 'someMethod', {'foo': 'barÜ'}])
59     endif
60
61 Execute(ale#lsp#CreateMessageData() should create messages without params):
62     if has('nvim')
63       AssertEqual
64       \ [
65       \   1,
66       \   "Content-Length: 56\r\n\r\n"
67       \   . '{"method": "someOtherMethod", "jsonrpc": "2.0", "id": 1}',
68       \ ],
69       \ ale#lsp#CreateMessageData([0, 'someOtherMethod'])
70     else
71       AssertEqual
72       \ [
73       \   1,
74       \   "Content-Length: 51\r\n\r\n"
75       \   . '{"method":"someOtherMethod","jsonrpc":"2.0","id":1}',
76       \ ],
77       \ ale#lsp#CreateMessageData([0, 'someOtherMethod'])
78     endif
79
80 Execute(ale#lsp#CreateMessageData() should create notifications):
81     if has('nvim')
82       AssertEqual
83       \ [
84       \   0,
85       \   "Content-Length: 48\r\n\r\n"
86       \   . '{"method": "someNotification", "jsonrpc": "2.0"}',
87       \ ],
88       \ ale#lsp#CreateMessageData([1, 'someNotification'])
89       AssertEqual
90       \ [
91       \   0,
92       \   "Content-Length: 74\r\n\r\n"
93       \   . '{"method": "someNotification", "jsonrpc": "2.0", "params": {"foo": "bar"}}',
94       \ ],
95       \ ale#lsp#CreateMessageData([1, 'someNotification', {'foo': 'bar'}])
96     else
97       AssertEqual
98       \ [
99       \   0,
100       \   "Content-Length: 45\r\n\r\n"
101       \   . '{"method":"someNotification","jsonrpc":"2.0"}',
102       \ ],
103       \ ale#lsp#CreateMessageData([1, 'someNotification'])
104       AssertEqual
105       \ [
106       \   0,
107       \   "Content-Length: 68\r\n\r\n"
108       \   . '{"method":"someNotification","jsonrpc":"2.0","params":{"foo":"bar"}}',
109       \ ],
110       \ ale#lsp#CreateMessageData([1, 'someNotification', {'foo': 'bar'}])
111     endif
112
113 Execute(ale#lsp#CreateMessageData() should create tsserver notification messages):
114     if has('nvim')
115       AssertEqual
116       \ [
117       \   0,
118       \   '{"seq": null, "type": "request", "command": "someNotification"}'
119       \   . "\n",
120       \ ],
121       \ ale#lsp#CreateMessageData([1, 'ts@someNotification'])
122       AssertEqual
123       \ [
124       \   0,
125       \   '{"seq": null, "arguments": {"foo": "bar"}, "type": "request", "command": "someNotification"}'
126       \   . "\n",
127       \ ],
128       \ ale#lsp#CreateMessageData([1, 'ts@someNotification', {'foo': 'bar'}])
129     else
130       AssertEqual
131       \ [
132       \   0,
133       \   '{"seq":null,"type":"request","command":"someNotification"}'
134       \   . "\n",
135       \ ],
136       \ ale#lsp#CreateMessageData([1, 'ts@someNotification'])
137       AssertEqual
138       \ [
139       \   0,
140       \   '{"seq":null,"arguments":{"foo":"bar"},"type":"request","command":"someNotification"}'
141       \   . "\n",
142       \ ],
143       \ ale#lsp#CreateMessageData([1, 'ts@someNotification', {'foo': 'bar'}])
144     endif
145
146 Execute(ale#lsp#CreateMessageData() should create tsserver messages expecting responses):
147     if has('nvim')
148       AssertEqual
149       \ [
150       \   1,
151       \   '{"seq": 1, "type": "request", "command": "someMessage"}'
152       \   . "\n",
153       \ ],
154       \ ale#lsp#CreateMessageData([0, 'ts@someMessage'])
155       AssertEqual
156       \ [
157       \   2,
158       \   '{"seq": 2, "arguments": {"foo": "bar"}, "type": "request", "command": "someMessage"}'
159       \   . "\n",
160       \ ],
161       \ ale#lsp#CreateMessageData([0, 'ts@someMessage', {'foo': 'bar'}])
162     else
163       AssertEqual
164       \ [
165       \   1,
166       \   '{"seq":1,"type":"request","command":"someMessage"}'
167       \   . "\n",
168       \ ],
169       \ ale#lsp#CreateMessageData([0, 'ts@someMessage'])
170       AssertEqual
171       \ [
172       \   2,
173       \   '{"seq":2,"arguments":{"foo":"bar"},"type":"request","command":"someMessage"}'
174       \   . "\n",
175       \ ],
176       \ ale#lsp#CreateMessageData([0, 'ts@someMessage', {'foo': 'bar'}])
177     endif
178
179 Execute(ale#lsp#ReadMessageData() should read single whole messages):
180   AssertEqual
181   \  ['', [{'id': 2, 'jsonrpc': '2.0', 'result': {'foo': 'barÜ'}}]],
182   \ ale#lsp#ReadMessageData(
183   \   "Content-Length: 49\r\n\r\n"
184   \   . '{"id":2,"jsonrpc":"2.0","result":{"foo":"barÜ"}}'
185   \ )
186
187 Execute(ale#lsp#ReadMessageData() should ignore other headers):
188   AssertEqual
189   \  ['', [{'id': 2, 'jsonrpc': '2.0', 'result': {'foo': 'barÜ'}}]],
190   \ ale#lsp#ReadMessageData(
191   \   "First-Header: 49\r\n"
192   \   . "Content-Length: 49\r\n"
193   \   . "Other-Header: 49\r\n"
194   \   . "\r\n"
195   \   . '{"id":2,"jsonrpc":"2.0","result":{"foo":"barÜ"}}'
196   \ )
197
198 Execute(ale#lsp#ReadMessageData() should handle partial messages):
199   let b:data = "Content-Length: 49\r\n\r\n" . '{"id":2,"jsonrpc":"2.0","result":'
200
201   AssertEqual [b:data, []], ale#lsp#ReadMessageData(b:data)
202
203 Execute(ale#lsp#ReadMessageData() should handle multiple messages):
204   AssertEqual
205   \  ['', [
206   \   {'id': 2, 'jsonrpc': '2.0', 'result': {'foo': 'barÜ'}},
207   \   {'id': 2, 'jsonrpc': '2.0', 'result': {'foo123': 'barÜ'}},
208   \ ]],
209   \ ale#lsp#ReadMessageData(
210   \   "Content-Length: 49\r\n\r\n"
211   \   . '{"id":2,"jsonrpc":"2.0","result":{"foo":"barÜ"}}'
212   \   . "Content-Length: 52\r\n\r\n"
213   \   . '{"id":2,"jsonrpc":"2.0","result":{"foo123":"barÜ"}}'
214   \ )
215
216 Execute(ale#lsp#ReadMessageData() should handle a message with part of a second message):
217   let b:data = "Content-Length: 52\r\n\r\n" . '{"id":2,"jsonrpc":"2.'
218
219   AssertEqual
220   \  [b:data, [
221   \   {'id': 2, 'jsonrpc': '2.0', 'result': {'foo': 'barÜ'}},
222   \ ]],
223   \ ale#lsp#ReadMessageData(
224   \   "Content-Length: 49\r\n\r\n"
225   \   . '{"id":2,"jsonrpc":"2.0","result":{"foo":"barÜ"}}'
226   \   . b:data
227   \ )