Skip to content

Commit 07a4e70

Browse files
committed
Moves signature help unittest to separate file
1 parent 26c9d79 commit 07a4e70

File tree

2 files changed

+48
-41
lines changed

2 files changed

+48
-41
lines changed

test/test_server.py

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -209,44 +209,3 @@ def check_return(result_array):
209209
#
210210
assert errcode == 0
211211
check_return(results[1])
212-
213-
214-
def test_sig():
215-
def check_return(results, checks):
216-
assert results.get("activeParameter", -1) == checks[0]
217-
signatures = results.get("signatures")
218-
assert signatures[0].get("label") == checks[2]
219-
assert len(signatures[0].get("parameters")) == checks[1]
220-
221-
def sig_request(file_path, line, char):
222-
return write_rpc_request(
223-
1,
224-
"textDocument/signatureHelp",
225-
{
226-
"textDocument": {"uri": str(file_path)},
227-
"position": {"line": line, "character": char},
228-
},
229-
)
230-
231-
#
232-
string = write_rpc_request(1, "initialize", {"rootPath": str(test_dir)})
233-
file_path = test_dir / "test_prog.f08"
234-
string += sig_request(file_path, 25, 18)
235-
string += sig_request(file_path, 25, 20)
236-
string += sig_request(file_path, 25, 22)
237-
string += sig_request(file_path, 25, 27)
238-
string += sig_request(file_path, 25, 29)
239-
errcode, results = run_request(string)
240-
assert errcode == 0
241-
#
242-
sub_sig = "test_sig_Sub(arg1, arg2, opt1=opt1, opt2=opt2, opt3=opt3)"
243-
exp_results = (
244-
[0, 5, sub_sig],
245-
[1, 5, sub_sig],
246-
[2, 5, sub_sig],
247-
[3, 5, sub_sig],
248-
[4, 5, sub_sig],
249-
)
250-
assert len(exp_results) + 1 == len(results)
251-
for i in range(len(exp_results)):
252-
check_return(results[i + 1], exp_results[i])

test/test_server_signature_help.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from pathlib import Path
2+
3+
from setup_tests import run_request, test_dir, write_rpc_request
4+
5+
6+
def sigh_request(uri: Path, line: int, char: int):
7+
return write_rpc_request(
8+
1,
9+
"textDocument/signatureHelp",
10+
{
11+
"textDocument": {"uri": str(uri)},
12+
"position": {"line": line, "character": char},
13+
},
14+
)
15+
16+
17+
def validate_sigh(results, refs):
18+
assert results.get("activeParameter", -1) == refs[0]
19+
signatures = results.get("signatures")
20+
assert signatures[0].get("label") == refs[2]
21+
assert len(signatures[0].get("parameters")) == refs[1]
22+
23+
24+
def test_subroutine_signature_help():
25+
"""Test that the signature help is correctly resolved for all arguments and
26+
that the autocompletion is correct for the subroutine signature.
27+
"""
28+
string = write_rpc_request(1, "initialize", {"rootPath": str(test_dir)})
29+
file_path = test_dir / "test_prog.f08"
30+
string += sigh_request(file_path, 25, 18)
31+
string += sigh_request(file_path, 25, 20)
32+
string += sigh_request(file_path, 25, 22)
33+
string += sigh_request(file_path, 25, 27)
34+
string += sigh_request(file_path, 25, 29)
35+
errcode, results = run_request(string)
36+
assert errcode == 0
37+
38+
sub_sig = "test_sig_Sub(arg1, arg2, opt1=opt1, opt2=opt2, opt3=opt3)"
39+
ref = (
40+
[0, 5, sub_sig],
41+
[1, 5, sub_sig],
42+
[2, 5, sub_sig],
43+
[3, 5, sub_sig],
44+
[4, 5, sub_sig],
45+
)
46+
assert len(ref) == len(results) - 1
47+
for i in range(len(ref)):
48+
validate_sigh(results[i + 1], ref[i])

0 commit comments

Comments
 (0)