Skip to content

Commit ad39d77

Browse files
committed
Moves reference unittests to separate file
1 parent 0b09133 commit ad39d77

File tree

2 files changed

+58
-48
lines changed

2 files changed

+58
-48
lines changed

test/test_server.py

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -333,51 +333,3 @@ def def_request(file_path, line, char):
333333
assert len(exp_results) + 1 == len(results)
334334
for i in range(len(exp_results)):
335335
check_return(results[i + 1], exp_results[i])
336-
337-
338-
def test_refs():
339-
def check_return(result_array, checks):
340-
def find_in_results(uri, sline):
341-
for (i, result) in enumerate(result_array):
342-
if (result["uri"] == uri) and (
343-
result["range"]["start"]["line"] == sline
344-
):
345-
del result_array[i]
346-
return result
347-
return None
348-
349-
assert len(result_array) == len(checks)
350-
for check in checks:
351-
result = find_in_results(path_to_uri(check[0]), check[1])
352-
assert result is not None
353-
assert result["range"]["start"]["character"] == check[2]
354-
assert result["range"]["end"]["character"] == check[3]
355-
356-
#
357-
string = write_rpc_request(1, "initialize", {"rootPath": str(test_dir)})
358-
file_path = test_dir / "test_prog.f08"
359-
string += write_rpc_request(
360-
2,
361-
"textDocument/references",
362-
{
363-
"textDocument": {"uri": str(file_path)},
364-
"position": {"line": 9, "character": 8},
365-
},
366-
)
367-
errcode, results = run_request(string)
368-
assert errcode == 0
369-
#
370-
free_path = str(test_dir / "subdir" / "test_free.f90")
371-
check_return(
372-
results[1],
373-
(
374-
[str(test_dir / "test_prog.f08"), 2, 21, 27],
375-
[str(test_dir / "test_prog.f08"), 9, 5, 11],
376-
[free_path, 8, 8, 14],
377-
[free_path, 16, 9, 15],
378-
[free_path, 18, 14, 20],
379-
[free_path, 36, 6, 12],
380-
[free_path, 44, 6, 12],
381-
[free_path, 78, 6, 12],
382-
),
383-
)

test/test_server_references.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
from setup_tests import (
2+
path_to_uri,
3+
run_request,
4+
test_dir,
5+
write_rpc_request,
6+
)
7+
8+
from pathlib import Path
9+
10+
11+
def validate_refs(result_array, checks):
12+
def find_in_results(uri, sline):
13+
for (i, result) in enumerate(result_array):
14+
if (result["uri"] == uri) and (result["range"]["start"]["line"] == sline):
15+
del result_array[i]
16+
return result
17+
return None
18+
19+
assert len(result_array) == len(checks)
20+
for check in checks:
21+
result = find_in_results(path_to_uri(check[0]), check[1])
22+
assert result is not None
23+
assert result["range"]["start"]["character"] == check[2]
24+
assert result["range"]["end"]["character"] == check[3]
25+
26+
27+
def ref_req(uri: Path, ln: int, ch: int):
28+
return write_rpc_request(
29+
2,
30+
"textDocument/references",
31+
{
32+
"textDocument": {"uri": str(uri)},
33+
"position": {"line": ln - 1, "character": ch - 1},
34+
},
35+
)
36+
37+
38+
def test_references():
39+
string = write_rpc_request(1, "initialize", {"rootPath": str(test_dir)})
40+
file_path = test_dir / "test_prog.f08"
41+
string += ref_req(file_path, 10, 9)
42+
errcode, results = run_request(string)
43+
assert errcode == 0
44+
#
45+
free_path = str(test_dir / "subdir" / "test_free.f90")
46+
validate_refs(
47+
results[1],
48+
(
49+
[str(test_dir / "test_prog.f08"), 2, 21, 27],
50+
[str(test_dir / "test_prog.f08"), 9, 5, 11],
51+
[free_path, 8, 8, 14],
52+
[free_path, 16, 9, 15],
53+
[free_path, 18, 14, 20],
54+
[free_path, 36, 6, 12],
55+
[free_path, 44, 6, 12],
56+
[free_path, 78, 6, 12],
57+
),
58+
)

0 commit comments

Comments
 (0)