Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 library test.integration.analysis.navigation; | |
| 6 | |
| 7 import 'package:analysis_testing/reflective_tests.dart'; | |
| 8 import 'package:unittest/unittest.dart'; | |
| 9 | |
| 10 import '../integration_tests.dart'; | |
| 11 | |
| 12 @ReflectiveTestCase() | |
| 13 class AnalysisNavigationTest extends AbstractAnalysisServerIntegrationTest { | |
| 14 test_navigation() { | |
| 15 String pathname = sourcePath('test.dart'); | |
| 16 String text = | |
| 17 r''' | |
| 18 import 'dart:async'; | |
| 19 | |
| 20 class Class<TypeParameter> { | |
| 21 Class.constructor(); /* constructor declaration */ | |
| 22 | |
| 23 TypeParameter field; | |
| 24 | |
| 25 method() {} | |
| 26 } | |
| 27 | |
| 28 typedef FunctionTypeAlias(); | |
| 29 | |
| 30 function(FunctionTypeAlias parameter) { | |
| 31 print(parameter()); | |
| 32 } | |
| 33 | |
| 34 int topLevelVariable; | |
| 35 | |
| 36 main() { | |
| 37 Class<int> localVariable = new Class<int>.constructor(); | |
| 38 function(() => localVariable.field); | |
| 39 localVariable.method(); | |
| 40 localVariable.field = 1; | |
| 41 } | |
| 42 '''; | |
| 43 writeFile(pathname, text); | |
| 44 standardAnalysisSetup(); | |
| 45 sendAnalysisSetSubscriptions({'NAVIGATION': [pathname]}); | |
| 46 List regions; | |
| 47 onAnalysisNavigation.listen((params) { | |
| 48 expect(params['file'], equals(pathname)); | |
| 49 regions = params['regions']; | |
| 50 }); | |
| 51 return analysisFinished.then((_) { | |
| 52 // There should be a single error, due to the fact that 'dart:async' is | |
| 53 // not used. | |
| 54 expect(currentAnalysisErrors[pathname], hasLength(1)); | |
| 55 Map findTargetElement(int index) { | |
| 56 for (Map region in regions) { | |
| 57 if (region['offset'] <= index && index < region['offset'] + region['le ngth']) { | |
| 58 expect(region['targets'], hasLength(1)); | |
| 59 return region['targets'][0]; | |
| 60 } | |
| 61 } | |
| 62 fail('No element found for index $index'); | |
| 63 return null; | |
| 64 } | |
| 65 void checkLocal(String source, String expectedTarget, String expectedKind) { | |
| 66 int sourceIndex = text.indexOf(source); | |
| 67 int targetIndex = text.indexOf(expectedTarget); | |
| 68 Map element = findTargetElement(sourceIndex); | |
| 69 expect(element['location']['file'], equals(pathname)); | |
| 70 expect(element['location']['offset'], equals(targetIndex)); | |
| 71 expect(element['kind'], equals(expectedKind)); | |
| 72 } | |
| 73 void checkRemote(String source, String expectedTargetRegexp, String expect edKind) { | |
| 74 int sourceIndex = text.indexOf(source); | |
| 75 Map element = findTargetElement(sourceIndex); | |
| 76 expect(element['location']['file'], matches(expectedTargetRegexp)); | |
| 77 expect(element['kind'], equals(expectedKind)); | |
| 78 } | |
| 79 // TODO(paulberry): will the following element types ever appear as a | |
| 80 // navigation target? | |
| 81 // - CLASS_TYPE_ALIAS | |
| 82 // - 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
| |
| 83 checkLocal('Class<int>', 'Class<TypeParameter>', 'CLASS'); | |
| 84 checkLocal('new Class<int>.constructor', 'constructor(); /* constructor de claration */', 'CONSTRUCTOR'); | |
| 85 checkLocal('field;', 'field;', 'FIELD'); | |
| 86 checkLocal('function(() => localVariable.field)', 'function(FunctionTypeAl ias parameter)', 'FUNCTION'); | |
| 87 checkLocal('FunctionTypeAlias parameter', 'FunctionTypeAlias();', 'FUNCTIO N_TYPE_ALIAS'); | |
| 88 checkLocal('field)', 'field;', 'GETTER'); | |
| 89 checkRemote("import 'dart:async'", r'async\.dart$', 'LIBRARY'); | |
| 90 checkLocal('localVariable.field', 'localVariable =', 'LOCAL_VARIABLE'); | |
| 91 checkLocal('method();', 'method() {', 'METHOD'); | |
| 92 checkLocal('parameter());', 'parameter) {', 'PARAMETER'); | |
| 93 checkLocal('field = 1', 'field;', 'SETTER'); | |
| 94 checkLocal('topLevelVariable;', 'topLevelVariable;', 'TOP_LEVEL_VARIABLE') ; | |
| 95 checkLocal('TypeParameter field;', 'TypeParameter>', 'TYPE_PARAMETER'); | |
| 96 }); | |
| 97 } | |
| 98 } | |
| 99 | |
| 100 main() { | |
| 101 runReflectiveTests(AnalysisNavigationTest); | |
| 102 } | |
| OLD | NEW |