OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2017, 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 import 'dart:async'; |
| 6 |
| 7 import 'package:analysis_server/protocol/protocol_generated.dart'; |
| 8 import 'package:test/test.dart'; |
| 9 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 10 |
| 11 import '../support/integration_tests.dart'; |
| 12 |
| 13 main() { |
| 14 defineReflectiveSuite(() { |
| 15 defineReflectiveTests(AnalysisGetImportedElementsIntegrationTest); |
| 16 }); |
| 17 } |
| 18 |
| 19 @reflectiveTest |
| 20 class AnalysisGetImportedElementsIntegrationTest |
| 21 extends AbstractAnalysisServerIntegrationTest { |
| 22 /** |
| 23 * Pathname of the file containing Dart code. |
| 24 */ |
| 25 String pathname; |
| 26 |
| 27 /** |
| 28 * Dart code under test. |
| 29 */ |
| 30 final String text = r''' |
| 31 main() {} |
| 32 '''; |
| 33 |
| 34 /** |
| 35 * Check that an analysis.getImportedElements request on the region starting |
| 36 * with the first character that matches [target] and having the given |
| 37 * [length] matches the given list of [expected] imported elements. |
| 38 */ |
| 39 checkElements( |
| 40 String target, int length, List<ImportedElements> expected) async { |
| 41 int offset = text.indexOf(target); |
| 42 AnalysisGetImportedElementsResult result = |
| 43 await sendAnalysisGetImportedElements(pathname, offset, length); |
| 44 |
| 45 expect(result.elements, hasLength(expected.length)); |
| 46 // TODO(brianwilkerson) Finish implementing this. |
| 47 } |
| 48 |
| 49 /** |
| 50 * Check that an analysis.getImportedElements request on the region matching |
| 51 * [target] produces an empty list of elements. |
| 52 */ |
| 53 Future<Null> checkNoElements(String target) async { |
| 54 int offset = text.indexOf(target); |
| 55 AnalysisGetImportedElementsResult result = |
| 56 await sendAnalysisGetImportedElements(pathname, offset, target.length); |
| 57 |
| 58 expect(result.elements, hasLength(0)); |
| 59 } |
| 60 |
| 61 setUp() { |
| 62 return super.setUp().then((_) { |
| 63 pathname = sourcePath('test.dart'); |
| 64 }); |
| 65 } |
| 66 |
| 67 test_getImportedElements() async { |
| 68 writeFile(pathname, text); |
| 69 standardAnalysisSetup(); |
| 70 await analysisFinished; |
| 71 |
| 72 List<Future> tests = []; |
| 73 tests.add(checkNoElements('main() {}')); |
| 74 return Future.wait(tests); |
| 75 } |
| 76 } |
OLD | NEW |