|
18 | 18 | from hamcrest import ( assert_that, |
19 | 19 | has_items, |
20 | 20 | contains_exactly, |
| 21 | + contains_inanyorder, |
21 | 22 | contains_string, |
22 | 23 | equal_to, |
23 | 24 | has_entries, |
@@ -98,6 +99,39 @@ def RunGoToTest_all( app, folder, command, test ): |
98 | 99 | } ) |
99 | 100 |
|
100 | 101 |
|
| 102 | +def RunHierarchyTest( app, |
| 103 | + kind, |
| 104 | + direction, |
| 105 | + location, |
| 106 | + expected, |
| 107 | + code ): |
| 108 | + file, line, column = location |
| 109 | + contents = ReadFile( file ) |
| 110 | + request = { |
| 111 | + 'completer_target' : 'filetype_default', |
| 112 | + 'command_arguments': [ f'{ kind.title() }Hierarchy' ], |
| 113 | + 'line_num' : line, |
| 114 | + 'column_num' : column, |
| 115 | + 'filepath' : file, |
| 116 | + 'contents' : contents, |
| 117 | + 'filetype' : 'cpp' |
| 118 | + } |
| 119 | + test = { 'request': request, |
| 120 | + 'route': '/run_completer_command' } |
| 121 | + prepare_hierarchy_response = RunAfterInitialized( app, test ) |
| 122 | + request[ 'command_arguments' ] = [ |
| 123 | + f'Resolve{ kind.title() }HierarchyItem', |
| 124 | + prepare_hierarchy_response[ 0 ], |
| 125 | + direction |
| 126 | + ] |
| 127 | + test[ 'expect' ] = { |
| 128 | + 'response': code, |
| 129 | + 'data': expected |
| 130 | + } |
| 131 | + RunAfterInitialized( app, test ) |
| 132 | + |
| 133 | + |
| 134 | + |
101 | 135 | def RunGetSemanticTest( app, |
102 | 136 | filepath, |
103 | 137 | filetype, |
@@ -605,6 +639,8 @@ def test_Subcommands_ServerNotInitialized( self, app ): |
605 | 639 | 'GoToType', |
606 | 640 | 'RefactorRename', |
607 | 641 | 'GoToAlternateFile', |
| 642 | + 'CallHierarchy', |
| 643 | + 'TypeHierarchy', |
608 | 644 | ]: |
609 | 645 | with self.subTest( cmd = cmd ): |
610 | 646 | completer = handlers._server_state.GetFiletypeCompleter( [ 'cpp' ] ) |
@@ -1285,3 +1321,122 @@ def test_Subcommands_RefactorRename( self, app ): |
1285 | 1321 | 'route': '/run_completer_command' |
1286 | 1322 | } |
1287 | 1323 | RunAfterInitialized( app, test ) |
| 1324 | + |
| 1325 | + |
| 1326 | + @SharedYcmd |
| 1327 | + def test_Subcommands_SupertypeHierarchy( self, app ): |
| 1328 | + filepath = PathToTestFile( 'hierarchies.cc' ) |
| 1329 | + for location, response, code in [ |
| 1330 | + [ ( filepath, 16, 8 ), |
| 1331 | + contains_inanyorder( |
| 1332 | + has_entry( 'locations', |
| 1333 | + contains_exactly( |
| 1334 | + LocationMatcher( filepath, 13, 8 ) |
| 1335 | + ) ), |
| 1336 | + has_entry( 'locations', |
| 1337 | + contains_exactly( |
| 1338 | + LocationMatcher( filepath, 12, 8 ) |
| 1339 | + ) ), |
| 1340 | + ), |
| 1341 | + requests.codes.ok ], |
| 1342 | + [ ( filepath, 13, 8 ), |
| 1343 | + contains_inanyorder( |
| 1344 | + has_entry( 'locations', |
| 1345 | + contains_exactly( |
| 1346 | + LocationMatcher( filepath, 12, 8 ) |
| 1347 | + ) ), |
| 1348 | + ), |
| 1349 | + requests.codes.ok ], |
| 1350 | + [ ( filepath, 12, 8 ), |
| 1351 | + ErrorMatcher( RuntimeError, 'No supertypes found.' ), |
| 1352 | + requests.codes.server_error ] |
| 1353 | + ]: |
| 1354 | + with self.subTest( location = location, response = response ): |
| 1355 | + RunHierarchyTest( app, 'type', 'supertypes', location, response, code ) |
| 1356 | + |
| 1357 | + |
| 1358 | + @SharedYcmd |
| 1359 | + def test_Subcommands_SubtypeHierarchy( self, app ): |
| 1360 | + filepath = PathToTestFile( 'hierarchies.cc' ) |
| 1361 | + for location, response, code in [ |
| 1362 | + [ ( filepath, 12, 8 ), |
| 1363 | + contains_inanyorder( |
| 1364 | + has_entry( 'locations', |
| 1365 | + contains_exactly( |
| 1366 | + LocationMatcher( filepath, 13, 8 ) |
| 1367 | + ) ), |
| 1368 | + has_entry( 'locations', |
| 1369 | + contains_exactly( |
| 1370 | + LocationMatcher( filepath, 15, 8 ) |
| 1371 | + ) ), |
| 1372 | + has_entry( 'locations', |
| 1373 | + contains_exactly( |
| 1374 | + LocationMatcher( filepath, 16, 8 ) |
| 1375 | + ) ) ), |
| 1376 | + requests.codes.ok ], |
| 1377 | + [ ( filepath, 13, 8 ), |
| 1378 | + contains_inanyorder( |
| 1379 | + has_entry( 'locations', |
| 1380 | + contains_exactly( |
| 1381 | + LocationMatcher( filepath, 16, 8 ) |
| 1382 | + ) ) ), |
| 1383 | + requests.codes.ok ], |
| 1384 | + [ ( filepath, 16, 8 ), |
| 1385 | + ErrorMatcher( RuntimeError, 'No subtypes found.' ), |
| 1386 | + requests.codes.server_error ] |
| 1387 | + ]: |
| 1388 | + with self.subTest( location = location, response = response ): |
| 1389 | + RunHierarchyTest( app, 'type', 'subtypes', location, response, code ) |
| 1390 | + |
| 1391 | + |
| 1392 | + @SharedYcmd |
| 1393 | + def test_Subcommands_IncomingCallHierarchy( self, app ): |
| 1394 | + filepath = PathToTestFile( 'hierarchies.cc' ) |
| 1395 | + for location, response, code in [ |
| 1396 | + [ ( filepath, 1, 5 ), |
| 1397 | + contains_inanyorder( |
| 1398 | + has_entry( 'locations', |
| 1399 | + contains_exactly( |
| 1400 | + LocationMatcher( filepath, 4, 12 ), |
| 1401 | + LocationMatcher( filepath, 4, 18 ) |
| 1402 | + ) ), |
| 1403 | + has_entry( 'locations', |
| 1404 | + contains_exactly( |
| 1405 | + LocationMatcher( filepath, 9, 12 ) |
| 1406 | + ) ) ), |
| 1407 | + requests.codes.ok ], |
| 1408 | + [ ( filepath, 3, 5 ), |
| 1409 | + contains_inanyorder( |
| 1410 | + has_entry( 'locations', |
| 1411 | + contains_exactly( |
| 1412 | + LocationMatcher( filepath, 8, 13 ) |
| 1413 | + ) ) ), |
| 1414 | + requests.codes.ok ], |
| 1415 | + [ ( filepath, 7, 5 ), |
| 1416 | + ErrorMatcher( RuntimeError, 'No incoming calls found.' ), |
| 1417 | + requests.codes.server_error ] |
| 1418 | + ]: |
| 1419 | + with self.subTest( location = location, response = response ): |
| 1420 | + RunHierarchyTest( app, 'call', 'incoming', location, response, code ) |
| 1421 | + |
| 1422 | + |
| 1423 | + @SharedYcmd |
| 1424 | + def test_Subcommands_NoHierarchyFound( self, app ): |
| 1425 | + for kind in [ 'call', 'type' ]: |
| 1426 | + with self.subTest( kind = kind ): |
| 1427 | + filepath = PathToTestFile( 'hierarchies.cc' ) |
| 1428 | + request = { |
| 1429 | + 'completer_target' : 'filetype_default', |
| 1430 | + 'command_arguments': [ f'{ kind.title() }Hierarchy' ], |
| 1431 | + 'line_num' : 2, |
| 1432 | + 'column_num' : 1, |
| 1433 | + 'filepath' : filepath, |
| 1434 | + 'filetype' : 'cpp' |
| 1435 | + } |
| 1436 | + test = { 'request': request, |
| 1437 | + 'route': '/run_completer_command', |
| 1438 | + 'expect': { |
| 1439 | + 'response': requests.codes.server_error, |
| 1440 | + 'data': ErrorMatcher( RuntimeError, |
| 1441 | + f'No { kind } hierarchy found.' ) } } |
| 1442 | + RunAfterInitialized( app, test ) |
0 commit comments