Chromium Code Reviews| Index: pkg/analysis_server/test/integration/analysis/navigation_test.dart |
| diff --git a/pkg/analysis_server/test/integration/analysis/navigation_test.dart b/pkg/analysis_server/test/integration/analysis/navigation_test.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..87481ee533c843e12ea1c3993db2a7aece434743 |
| --- /dev/null |
| +++ b/pkg/analysis_server/test/integration/analysis/navigation_test.dart |
| @@ -0,0 +1,102 @@ |
| +// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +library test.integration.analysis.navigation; |
| + |
| +import 'package:analysis_testing/reflective_tests.dart'; |
| +import 'package:unittest/unittest.dart'; |
| + |
| +import '../integration_tests.dart'; |
| + |
| +@ReflectiveTestCase() |
| +class AnalysisNavigationTest extends AbstractAnalysisServerIntegrationTest { |
| + test_navigation() { |
| + String pathname = sourcePath('test.dart'); |
| + String text = |
| + r''' |
| +import 'dart:async'; |
| + |
| +class Class<TypeParameter> { |
| + Class.constructor(); /* constructor declaration */ |
| + |
| + TypeParameter field; |
| + |
| + method() {} |
| +} |
| + |
| +typedef FunctionTypeAlias(); |
| + |
| +function(FunctionTypeAlias parameter) { |
| + print(parameter()); |
| +} |
| + |
| +int topLevelVariable; |
| + |
| +main() { |
| + Class<int> localVariable = new Class<int>.constructor(); |
| + function(() => localVariable.field); |
| + localVariable.method(); |
| + localVariable.field = 1; |
| +} |
| +'''; |
| + writeFile(pathname, text); |
| + standardAnalysisSetup(); |
| + sendAnalysisSetSubscriptions({'NAVIGATION': [pathname]}); |
| + List regions; |
| + onAnalysisNavigation.listen((params) { |
| + expect(params['file'], equals(pathname)); |
| + regions = params['regions']; |
| + }); |
| + return analysisFinished.then((_) { |
| + // There should be a single error, due to the fact that 'dart:async' is |
| + // not used. |
| + expect(currentAnalysisErrors[pathname], hasLength(1)); |
| + Map findTargetElement(int index) { |
| + for (Map region in regions) { |
| + if (region['offset'] <= index && index < region['offset'] + region['length']) { |
| + expect(region['targets'], hasLength(1)); |
| + return region['targets'][0]; |
| + } |
| + } |
| + fail('No element found for index $index'); |
| + return null; |
| + } |
| + void checkLocal(String source, String expectedTarget, String expectedKind) { |
| + int sourceIndex = text.indexOf(source); |
| + int targetIndex = text.indexOf(expectedTarget); |
| + Map element = findTargetElement(sourceIndex); |
| + expect(element['location']['file'], equals(pathname)); |
| + expect(element['location']['offset'], equals(targetIndex)); |
| + expect(element['kind'], equals(expectedKind)); |
| + } |
| + void checkRemote(String source, String expectedTargetRegexp, String expectedKind) { |
| + int sourceIndex = text.indexOf(source); |
| + Map element = findTargetElement(sourceIndex); |
| + expect(element['location']['file'], matches(expectedTargetRegexp)); |
| + expect(element['kind'], equals(expectedKind)); |
| + } |
| + // TODO(paulberry): will the following element types ever appear as a |
| + // navigation target? |
| + // - CLASS_TYPE_ALIAS |
| + // - COMPILATION_UNIT |
|
Brian Wilkerson
2014/08/14 20:53:44
I would expect compilation units to show up as nav
Paul Berry
2014/08/14 20:58:05
That was my guess too, but I have such a directive
Brian Wilkerson
2014/08/14 20:59:02
That makes sense for import and export, but not pa
Paul Berry
2014/08/14 21:06:14
Aha, that makes sense. I've added a part directiv
|
| + checkLocal('Class<int>', 'Class<TypeParameter>', 'CLASS'); |
| + checkLocal('new Class<int>.constructor', 'constructor(); /* constructor declaration */', 'CONSTRUCTOR'); |
| + checkLocal('field;', 'field;', 'FIELD'); |
| + checkLocal('function(() => localVariable.field)', 'function(FunctionTypeAlias parameter)', 'FUNCTION'); |
| + checkLocal('FunctionTypeAlias parameter', 'FunctionTypeAlias();', 'FUNCTION_TYPE_ALIAS'); |
| + checkLocal('field)', 'field;', 'GETTER'); |
| + checkRemote("import 'dart:async'", r'async\.dart$', 'LIBRARY'); |
| + checkLocal('localVariable.field', 'localVariable =', 'LOCAL_VARIABLE'); |
| + checkLocal('method();', 'method() {', 'METHOD'); |
| + checkLocal('parameter());', 'parameter) {', 'PARAMETER'); |
| + checkLocal('field = 1', 'field;', 'SETTER'); |
| + checkLocal('topLevelVariable;', 'topLevelVariable;', 'TOP_LEVEL_VARIABLE'); |
| + checkLocal('TypeParameter field;', 'TypeParameter>', 'TYPE_PARAMETER'); |
| + }); |
| + } |
| +} |
| + |
| +main() { |
| + runReflectiveTests(AnalysisNavigationTest); |
| +} |