18
18
)
19
19
20
20
21
+ def split (
22
+ result : Union [Location , LocationLink , List [Location ], List [LocationLink ], None ]
23
+ ) -> Union [Location , LocationLink , List [Location ], List [LocationLink ], None ]:
24
+ if result is None :
25
+ return None
26
+ if isinstance (result , Location ):
27
+ return Location ((Uri (result .uri ).to_path ().name ), result .range )
28
+ if isinstance (result , LocationLink ):
29
+ return LocationLink (
30
+ result .origin_selection_range ,
31
+ (Uri (result .target_uri ).to_path ().name ),
32
+ result .target_range ,
33
+ result .target_selection_range ,
34
+ )
35
+ if isinstance (result , list ) and len (result ) > 0 and isinstance (result [0 ], LocationLink ):
36
+ return cast ("List[LocationLink]" , [split (v ) for v in result ])
37
+
38
+ if isinstance (result , list ) and len (result ) > 0 and isinstance (result [0 ], Location ):
39
+ return cast ("List[Location]" , [split (v ) for v in result ])
40
+
41
+ return result
42
+
43
+
21
44
@pytest .mark .parametrize (
22
45
("test_document" , "data" ),
23
46
generate_tests_from_source_document (Path (Path (__file__ ).parent , "data/goto.robot" )),
26
49
)
27
50
@pytest .mark .usefixtures ("protocol" )
28
51
@pytest .mark .asyncio
29
- async def test (
52
+ async def test_definition (
30
53
data_regression : DataRegressionFixture ,
31
54
protocol : RobotLanguageServerProtocol ,
32
55
test_document : TextDocument ,
@@ -39,26 +62,28 @@ async def test(
39
62
Position (line = data .line , character = data .character ),
40
63
)
41
64
42
- def split (
43
- result : Union [Location , LocationLink , List [Location ], List [LocationLink ], None ]
44
- ) -> Union [Location , LocationLink , List [Location ], List [LocationLink ], None ]:
45
- if result is None :
46
- return None
47
- if isinstance (result , Location ):
48
- return Location ((Uri (result .uri ).to_path ().name ), result .range )
49
- if isinstance (result , LocationLink ):
50
- return LocationLink (
51
- result .origin_selection_range ,
52
- (Uri (result .target_uri ).to_path ().name ),
53
- result .target_range ,
54
- result .target_selection_range ,
55
- )
56
- if isinstance (result , list ) and len (result ) > 0 and isinstance (result [0 ], LocationLink ):
57
- return cast ("List[LocationLink]" , [split (v ) for v in result ])
65
+ data_regression .check ({"data" : data , "result" : split (result )})
58
66
59
- if isinstance (result , list ) and len (result ) > 0 and isinstance (result [0 ], Location ):
60
- return cast ("List[Location]" , [split (v ) for v in result ])
61
67
62
- return result
68
+ @pytest .mark .parametrize (
69
+ ("test_document" , "data" ),
70
+ generate_tests_from_source_document (Path (Path (__file__ ).parent , "data/goto.robot" )),
71
+ indirect = ["test_document" ],
72
+ ids = generate_test_id ,
73
+ )
74
+ @pytest .mark .usefixtures ("protocol" )
75
+ @pytest .mark .asyncio
76
+ async def test_implementation (
77
+ data_regression : DataRegressionFixture ,
78
+ protocol : RobotLanguageServerProtocol ,
79
+ test_document : TextDocument ,
80
+ data : GeneratedTestData ,
81
+ ) -> None :
82
+
83
+ result = await protocol .robot_goto .collect_implementation (
84
+ protocol .robot_goto ,
85
+ test_document ,
86
+ Position (line = data .line , character = data .character ),
87
+ )
63
88
64
89
data_regression .check ({"data" : data , "result" : split (result )})
0 commit comments