| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library test.integration.analysis.navigation; | 5 library test.integration.analysis.navigation; |
| 6 | 6 |
| 7 import 'package:analysis_server/src/protocol.dart'; | 7 import 'package:analysis_server/src/protocol.dart'; |
| 8 import 'package:unittest/unittest.dart'; | 8 import 'package:unittest/unittest.dart'; |
| 9 | 9 |
| 10 import '../../reflective_tests.dart'; | 10 import '../../reflective_tests.dart'; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 String pathname2 = sourcePath('test2.dart'); | 51 String pathname2 = sourcePath('test2.dart'); |
| 52 String text2 = r''' | 52 String text2 = r''' |
| 53 part of foo; | 53 part of foo; |
| 54 '''; | 54 '''; |
| 55 writeFile(pathname2, text2); | 55 writeFile(pathname2, text2); |
| 56 standardAnalysisSetup(); | 56 standardAnalysisSetup(); |
| 57 sendAnalysisSetSubscriptions({ | 57 sendAnalysisSetSubscriptions({ |
| 58 AnalysisService.NAVIGATION: [pathname1] | 58 AnalysisService.NAVIGATION: [pathname1] |
| 59 }); | 59 }); |
| 60 List<NavigationRegion> regions; | 60 List<NavigationRegion> regions; |
| 61 List<NavigationTarget> targets; |
| 62 List<String> targetFiles; |
| 61 onAnalysisNavigation.listen((AnalysisNavigationParams params) { | 63 onAnalysisNavigation.listen((AnalysisNavigationParams params) { |
| 62 expect(params.file, equals(pathname1)); | 64 expect(params.file, equals(pathname1)); |
| 63 regions = params.regions; | 65 regions = params.regions; |
| 66 targets = params.targets; |
| 67 targetFiles = params.files; |
| 64 }); | 68 }); |
| 65 return analysisFinished.then((_) { | 69 return analysisFinished.then((_) { |
| 66 // There should be a single error, due to the fact that 'dart:async' is | 70 // There should be a single error, due to the fact that 'dart:async' is |
| 67 // not used. | 71 // not used. |
| 68 expect(currentAnalysisErrors[pathname1], hasLength(1)); | 72 expect(currentAnalysisErrors[pathname1], hasLength(1)); |
| 69 expect(currentAnalysisErrors[pathname2], isEmpty); | 73 expect(currentAnalysisErrors[pathname2], isEmpty); |
| 70 Element findTargetElement(int index) { | 74 NavigationTarget findTargetElement(int index) { |
| 71 for (NavigationRegion region in regions) { | 75 for (NavigationRegion region in regions) { |
| 72 if (region.offset <= index && index < region.offset + region.length) { | 76 if (region.offset <= index && index < region.offset + region.length) { |
| 73 expect(region.targets, hasLength(1)); | 77 expect(region.targets, hasLength(1)); |
| 74 return region.targets[0]; | 78 int targetIndex = region.targets[0]; |
| 79 return targets[targetIndex]; |
| 75 } | 80 } |
| 76 } | 81 } |
| 77 fail('No element found for index $index'); | 82 fail('No element found for index $index'); |
| 78 return null; | 83 return null; |
| 79 } | 84 } |
| 80 void checkLocal(String source, String expectedTarget, | 85 void checkLocal(String source, String expectedTarget, |
| 81 ElementKind expectedKind) { | 86 ElementKind expectedKind) { |
| 82 int sourceIndex = text1.indexOf(source); | 87 int sourceIndex = text1.indexOf(source); |
| 83 int targetIndex = text1.indexOf(expectedTarget); | 88 int targetIndex = text1.indexOf(expectedTarget); |
| 84 Element element = findTargetElement(sourceIndex); | 89 NavigationTarget element = findTargetElement(sourceIndex); |
| 85 expect(element.location.file, equals(pathname1)); | 90 expect(targetFiles[element.fileIndex], equals(pathname1)); |
| 86 expect(element.location.offset, equals(targetIndex)); | 91 expect(element.offset, equals(targetIndex)); |
| 87 expect(element.kind, equals(expectedKind)); | 92 expect(element.kind, equals(expectedKind)); |
| 88 } | 93 } |
| 89 void checkRemote(String source, String expectedTargetRegexp, | 94 void checkRemote(String source, String expectedTargetRegexp, |
| 90 ElementKind expectedKind) { | 95 ElementKind expectedKind) { |
| 91 int sourceIndex = text1.indexOf(source); | 96 int sourceIndex = text1.indexOf(source); |
| 92 Element element = findTargetElement(sourceIndex); | 97 NavigationTarget element = findTargetElement(sourceIndex); |
| 93 expect(element.location.file, matches(expectedTargetRegexp)); | 98 expect(targetFiles[element.fileIndex], matches(expectedTargetRegexp)); |
| 94 expect(element.kind, equals(expectedKind)); | 99 expect(element.kind, equals(expectedKind)); |
| 95 } | 100 } |
| 96 // TODO(paulberry): will the element type 'CLASS_TYPE_ALIAS' ever appear | 101 // TODO(paulberry): will the element type 'CLASS_TYPE_ALIAS' ever appear |
| 97 // as a navigation target? | 102 // as a navigation target? |
| 98 checkLocal('Class<int>', 'Class<TypeParameter>', ElementKind.CLASS); | 103 checkLocal('Class<int>', 'Class<TypeParameter>', ElementKind.CLASS); |
| 99 checkRemote( | 104 checkRemote( |
| 100 "part 'test2.dart';", | 105 "part 'test2.dart';", |
| 101 r'test2.dart$', | 106 r'test2.dart$', |
| 102 ElementKind.COMPILATION_UNIT); | 107 ElementKind.COMPILATION_UNIT); |
| 103 checkLocal( | 108 checkLocal( |
| (...skipping 22 matching lines...) Expand all Loading... |
| 126 'topLevelVariable;', | 131 'topLevelVariable;', |
| 127 'topLevelVariable;', | 132 'topLevelVariable;', |
| 128 ElementKind.TOP_LEVEL_VARIABLE); | 133 ElementKind.TOP_LEVEL_VARIABLE); |
| 129 checkLocal( | 134 checkLocal( |
| 130 'TypeParameter field;', | 135 'TypeParameter field;', |
| 131 'TypeParameter>', | 136 'TypeParameter>', |
| 132 ElementKind.TYPE_PARAMETER); | 137 ElementKind.TYPE_PARAMETER); |
| 133 }); | 138 }); |
| 134 } | 139 } |
| 135 } | 140 } |
| OLD | NEW |