Skip to content

Commit 5b00c18

Browse files
committed
Add java tests for call hierarchies
1 parent a1a21b5 commit 5b00c18

File tree

3 files changed

+174
-4
lines changed

3 files changed

+174
-4
lines changed

ycmd/tests/java/subcommands_test.py

Lines changed: 154 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@
7474
'testing',
7575
'Tset.java' )
7676

77+
HIERARCHIES_JAVA = PathToTestFile( 'simple_eclipse_project',
78+
'src',
79+
'com',
80+
'test',
81+
'Hierarchies.java' )
82+
7783

7884
def RunTest( app, test, contents = None ):
7985
if not contents:
@@ -107,11 +113,12 @@ def RunTest( app, test, contents = None ):
107113
expect_errors = True
108114
)
109115

110-
assert_that( response.status_code,
111-
equal_to( test[ 'expect' ][ 'response' ] ) )
116+
if 'expect' in test:
117+
assert_that( response.status_code,
118+
equal_to( test[ 'expect' ][ 'response' ] ) )
112119

113-
assert_that( response.json, test[ 'expect' ][ 'data' ] )
114-
break
120+
assert_that( response.json, test[ 'expect' ][ 'data' ] )
121+
return response.json
115122
except AssertionError:
116123
if time.time() > expiry:
117124
print( 'completer response: '
@@ -122,6 +129,32 @@ def RunTest( app, test, contents = None ):
122129
time.sleep( 0.25 )
123130

124131

132+
def RunHierarchyTest( app, kind, direction, location, expected, code ):
133+
file, line, column = location
134+
request = {
135+
'completer_target' : 'filetype_default',
136+
'command': f'{ kind.title() }Hierarchy',
137+
'line_num' : line,
138+
'column_num' : column,
139+
'filepath' : file,
140+
}
141+
test = { 'request': request,
142+
'route': '/run_completer_command' }
143+
prepare_hierarchy_response = RunTest( app, test )
144+
request.update( {
145+
'command': f'Resolve{ kind.title() }HierarchyItem',
146+
'arguments': [
147+
prepare_hierarchy_response[ 0 ],
148+
direction
149+
]
150+
} )
151+
test[ 'expect' ] = {
152+
'response': code,
153+
'data': expected
154+
}
155+
RunTest( app, test )
156+
157+
125158
def RunFixItTest( app, description, filepath, line, col, fixits_for_line ):
126159
RunTest( app, {
127160
'description': description,
@@ -2632,3 +2665,120 @@ def test_Subcommands_ExecuteCommand( self, app ):
26322665
'data': ''
26332666
}
26342667
} )
2668+
2669+
2670+
@SharedYcmd
2671+
def test_Subcommands_OutgoingCallHierarchy( self, app ):
2672+
filepath = HIERARCHIES_JAVA
2673+
for location, response, code in [
2674+
[ ( filepath, 15, 14 ),
2675+
contains_inanyorder(
2676+
has_entries( {
2677+
'locations': contains_exactly(
2678+
LocationMatcher( filepath, 16, 13 ) ),
2679+
'kind': 'Method',
2680+
'name': 'g() : int'
2681+
} ),
2682+
has_entries( {
2683+
'locations': contains_exactly(
2684+
LocationMatcher( filepath, 17, 16 ) ),
2685+
'kind': 'Method',
2686+
'name': 'f() : int'
2687+
} )
2688+
),
2689+
requests.codes.ok ],
2690+
[ ( filepath, 11, 14 ),
2691+
contains_inanyorder(
2692+
has_entries( {
2693+
'locations': contains_exactly(
2694+
LocationMatcher( filepath, 12, 12 ),
2695+
LocationMatcher( filepath, 12, 18 ) ),
2696+
'kind': 'Method',
2697+
'name': 'f() : int'
2698+
} ),
2699+
has_entries( {
2700+
'locations': contains_exactly(
2701+
LocationMatcher( filepath, 12, 12 ),
2702+
LocationMatcher( filepath, 12, 18 ) ),
2703+
'kind': 'Method',
2704+
'name': 'f() : int'
2705+
} ),
2706+
),
2707+
requests.codes.ok ],
2708+
[ ( filepath, 7, 14 ),
2709+
ErrorMatcher( RuntimeError, 'No outgoing calls found.' ),
2710+
requests.codes.server_error ]
2711+
]:
2712+
with self.subTest( location = location, response = response ):
2713+
RunHierarchyTest( app, 'call', 'outgoing', location, response, code )
2714+
2715+
2716+
@SharedYcmd
2717+
def test_Subcommands_IncomingCallHierarchy( self, app ):
2718+
filepath = HIERARCHIES_JAVA
2719+
for location, response, code in [
2720+
[ ( filepath, 7, 14 ),
2721+
contains_inanyorder(
2722+
# Once again JDT repeats items...
2723+
has_entries( {
2724+
'locations': contains_exactly(
2725+
LocationMatcher( filepath, 12, 12 ),
2726+
LocationMatcher( filepath, 12, 18 ) ),
2727+
'root_location': LocationMatcher( filepath, 11, 3 ),
2728+
'name': 'g() : int',
2729+
'kind': 'Method'
2730+
} ),
2731+
has_entries( {
2732+
'locations': contains_exactly(
2733+
LocationMatcher( filepath, 12, 12 ),
2734+
LocationMatcher( filepath, 12, 18 ) ),
2735+
'root_location': LocationMatcher( filepath, 11, 3 ),
2736+
'name': 'g() : int',
2737+
'kind': 'Method'
2738+
} ),
2739+
has_entries( {
2740+
'locations': contains_exactly(
2741+
LocationMatcher( filepath, 17, 16 ) ),
2742+
'root_location': LocationMatcher( filepath, 15, 3 ),
2743+
'name': 'h() : int',
2744+
'kind': 'Method'
2745+
} ),
2746+
),
2747+
requests.codes.ok ],
2748+
[ ( filepath, 11, 14 ),
2749+
contains_inanyorder(
2750+
has_entries( {
2751+
'locations': contains_exactly(
2752+
LocationMatcher( filepath, 16, 13 ) ),
2753+
'root_location': LocationMatcher( filepath, 15, 3 ),
2754+
'name': 'h() : int',
2755+
'kind': 'Method'
2756+
} )
2757+
),
2758+
requests.codes.ok ],
2759+
[ ( filepath, 15, 14 ),
2760+
ErrorMatcher( RuntimeError, 'No incoming calls found.' ),
2761+
requests.codes.server_error ]
2762+
]:
2763+
with self.subTest( location = location, response = response ):
2764+
RunHierarchyTest( app, 'call', 'incoming', location, response, code )
2765+
2766+
2767+
@SharedYcmd
2768+
def test_Subcommands_NoHierarchyFound( self, app ):
2769+
filepath = HIERARCHIES_JAVA
2770+
request = {
2771+
'completer_target' : 'filetype_default',
2772+
'command': 'CallHierarchy',
2773+
'line_num' : 2,
2774+
'column_num' : 1,
2775+
'filepath' : filepath,
2776+
'filetype' : 'go'
2777+
}
2778+
test = { 'request': request,
2779+
'route': '/run_completer_command',
2780+
'expect': {
2781+
'response': requests.codes.server_error,
2782+
'data': ErrorMatcher(
2783+
RuntimeError, 'No call hierarchy found.' ) } }
2784+
RunTest( app, test )

ycmd/tests/java/testdata/lombok_project/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
build/
33

44
.classpath
5+
.factorypath
56
.project
67
.settings/
78
target/
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.test;
2+
3+
public class Hierarchies {
4+
5+
public Hierarchies() {}
6+
7+
public int f() {
8+
return 5;
9+
}
10+
11+
public int g() {
12+
return f() + f();
13+
}
14+
15+
public int h() {
16+
int x = g();
17+
return x + f();
18+
}
19+
}

0 commit comments

Comments
 (0)