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/plugin/protocol/protocol.dart'; | 7 import 'package:analysis_server/plugin/protocol/protocol.dart'; |
| 8 import 'package:test/test.dart'; |
8 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 9 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
9 import 'package:unittest/unittest.dart'; | |
10 | 10 |
11 import '../../utils.dart'; | 11 import '../../utils.dart'; |
12 import '../integration_tests.dart'; | 12 import '../integration_tests.dart'; |
13 | 13 |
14 main() { | 14 main() { |
15 initializeTestEnvironment(); | 15 initializeTestEnvironment(); |
16 defineReflectiveTests(AnalysisNavigationTest); | 16 defineReflectiveSuite(() { |
| 17 defineReflectiveTests(AnalysisNavigationTest); |
| 18 }); |
17 } | 19 } |
18 | 20 |
19 @reflectiveTest | 21 @reflectiveTest |
20 class AnalysisNavigationTest extends AbstractAnalysisServerIntegrationTest { | 22 class AnalysisNavigationTest extends AbstractAnalysisServerIntegrationTest { |
21 test_navigation() { | 23 test_navigation() { |
22 String pathname1 = sourcePath('test1.dart'); | 24 String pathname1 = sourcePath('test1.dart'); |
23 String text1 = r''' | 25 String text1 = r''' |
24 library foo; | 26 library foo; |
25 | 27 |
26 import 'dart:async'; | 28 import 'dart:async'; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 for (NavigationRegion region in regions) { | 79 for (NavigationRegion region in regions) { |
78 if (region.offset <= index && index < region.offset + region.length) { | 80 if (region.offset <= index && index < region.offset + region.length) { |
79 expect(region.targets, hasLength(1)); | 81 expect(region.targets, hasLength(1)); |
80 int targetIndex = region.targets[0]; | 82 int targetIndex = region.targets[0]; |
81 return targets[targetIndex]; | 83 return targets[targetIndex]; |
82 } | 84 } |
83 } | 85 } |
84 fail('No element found for index $index'); | 86 fail('No element found for index $index'); |
85 return null; | 87 return null; |
86 } | 88 } |
| 89 |
87 void checkLocal( | 90 void checkLocal( |
88 String source, String expectedTarget, ElementKind expectedKind) { | 91 String source, String expectedTarget, ElementKind expectedKind) { |
89 int sourceIndex = text1.indexOf(source); | 92 int sourceIndex = text1.indexOf(source); |
90 int targetIndex = text1.indexOf(expectedTarget); | 93 int targetIndex = text1.indexOf(expectedTarget); |
91 NavigationTarget element = findTargetElement(sourceIndex); | 94 NavigationTarget element = findTargetElement(sourceIndex); |
92 expect(targetFiles[element.fileIndex], equals(pathname1)); | 95 expect(targetFiles[element.fileIndex], equals(pathname1)); |
93 expect(element.offset, equals(targetIndex)); | 96 expect(element.offset, equals(targetIndex)); |
94 expect(element.kind, equals(expectedKind)); | 97 expect(element.kind, equals(expectedKind)); |
95 } | 98 } |
| 99 |
96 void checkRemote(String source, String expectedTargetRegexp, | 100 void checkRemote(String source, String expectedTargetRegexp, |
97 ElementKind expectedKind) { | 101 ElementKind expectedKind) { |
98 int sourceIndex = text1.indexOf(source); | 102 int sourceIndex = text1.indexOf(source); |
99 NavigationTarget element = findTargetElement(sourceIndex); | 103 NavigationTarget element = findTargetElement(sourceIndex); |
100 expect(targetFiles[element.fileIndex], matches(expectedTargetRegexp)); | 104 expect(targetFiles[element.fileIndex], matches(expectedTargetRegexp)); |
101 expect(element.kind, equals(expectedKind)); | 105 expect(element.kind, equals(expectedKind)); |
102 } | 106 } |
| 107 |
103 // TODO(paulberry): will the element type 'CLASS_TYPE_ALIAS' ever appear | 108 // TODO(paulberry): will the element type 'CLASS_TYPE_ALIAS' ever appear |
104 // as a navigation target? | 109 // as a navigation target? |
105 checkLocal('Class<int>', 'Class<TypeParameter>', ElementKind.CLASS); | 110 checkLocal('Class<int>', 'Class<TypeParameter>', ElementKind.CLASS); |
106 checkRemote( | 111 checkRemote( |
107 "'test2.dart';", r'test2.dart$', ElementKind.COMPILATION_UNIT); | 112 "'test2.dart';", r'test2.dart$', ElementKind.COMPILATION_UNIT); |
108 checkLocal( | 113 checkLocal( |
109 'Class<int>.constructor', | 114 'Class<int>.constructor', |
110 'constructor(); /* constructor declaration */', | 115 'constructor(); /* constructor declaration */', |
111 ElementKind.CONSTRUCTOR); | 116 ElementKind.CONSTRUCTOR); |
112 checkLocal( | 117 checkLocal( |
(...skipping 12 matching lines...) Expand all Loading... |
125 checkLocal('method();', 'method() {', ElementKind.METHOD); | 130 checkLocal('method();', 'method() {', ElementKind.METHOD); |
126 checkLocal('parameter());', 'parameter) {', ElementKind.PARAMETER); | 131 checkLocal('parameter());', 'parameter) {', ElementKind.PARAMETER); |
127 checkLocal('field = 1', 'field;', ElementKind.SETTER); | 132 checkLocal('field = 1', 'field;', ElementKind.SETTER); |
128 checkLocal('topLevelVariable;', 'topLevelVariable;', | 133 checkLocal('topLevelVariable;', 'topLevelVariable;', |
129 ElementKind.TOP_LEVEL_VARIABLE); | 134 ElementKind.TOP_LEVEL_VARIABLE); |
130 checkLocal( | 135 checkLocal( |
131 'TypeParameter field;', 'TypeParameter>', ElementKind.TYPE_PARAMETER); | 136 'TypeParameter field;', 'TypeParameter>', ElementKind.TYPE_PARAMETER); |
132 }); | 137 }); |
133 } | 138 } |
134 } | 139 } |
OLD | NEW |