| 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.search.top_level_declarations; | 5 library test.search.top_level_declarations; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/plugin/protocol/protocol.dart'; | 9 import 'package:analysis_server/plugin/protocol/protocol.dart'; |
| 10 import 'package:test/test.dart'; |
| 10 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 11 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 11 import 'package:unittest/unittest.dart'; | |
| 12 | 12 |
| 13 import '../utils.dart'; | 13 import '../utils.dart'; |
| 14 import 'abstract_search_domain.dart'; | 14 import 'abstract_search_domain.dart'; |
| 15 | 15 |
| 16 main() { | 16 main() { |
| 17 initializeTestEnvironment(); | 17 initializeTestEnvironment(); |
| 18 defineReflectiveTests(TopLevelDeclarationsTest); | 18 defineReflectiveSuite(() { |
| 19 defineReflectiveTests(TopLevelDeclarationsTest); |
| 20 }); |
| 19 } | 21 } |
| 20 | 22 |
| 21 @reflectiveTest | 23 @reflectiveTest |
| 22 class TopLevelDeclarationsTest extends AbstractSearchDomainTest { | 24 class TopLevelDeclarationsTest extends AbstractSearchDomainTest { |
| 23 void assertHasDeclaration(ElementKind kind, String name) { | 25 void assertHasDeclaration(ElementKind kind, String name) { |
| 24 result = findTopLevelResult(kind, name); | 26 result = findTopLevelResult(kind, name); |
| 25 if (result == null) { | 27 if (result == null) { |
| 26 fail('Not found: kind=$kind name="$name"\nin\n' + results.join('\n')); | 28 fail('Not found: kind=$kind name="$name"\nin\n' + results.join('\n')); |
| 27 } | 29 } |
| 28 } | 30 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 50 SearchResult findTopLevelResult(ElementKind kind, String name) { | 52 SearchResult findTopLevelResult(ElementKind kind, String name) { |
| 51 for (SearchResult result in results) { | 53 for (SearchResult result in results) { |
| 52 Element element = result.path[0]; | 54 Element element = result.path[0]; |
| 53 if (element.kind == kind && element.name == name) { | 55 if (element.kind == kind && element.name == name) { |
| 54 return result; | 56 return result; |
| 55 } | 57 } |
| 56 } | 58 } |
| 57 return null; | 59 return null; |
| 58 } | 60 } |
| 59 | 61 |
| 62 test_invalidRegex() async { |
| 63 var result = await findTopLevelDeclarations('[A'); |
| 64 expect(result, new isInstanceOf<RequestError>()); |
| 65 } |
| 66 |
| 60 test_startEndPattern() async { | 67 test_startEndPattern() async { |
| 61 addTestFile(''' | 68 addTestFile(''' |
| 62 class A {} // A | 69 class A {} // A |
| 63 class B = Object with A; | 70 class B = Object with A; |
| 64 typedef C(); | 71 typedef C(); |
| 65 D() {} | 72 D() {} |
| 66 var E = null; | 73 var E = null; |
| 67 class ABC {} | 74 class ABC {} |
| 68 '''); | 75 '''); |
| 69 await findTopLevelDeclarations('^[A-E]\$'); | 76 await findTopLevelDeclarations('^[A-E]\$'); |
| 70 assertHasDeclaration(ElementKind.CLASS, 'A'); | 77 assertHasDeclaration(ElementKind.CLASS, 'A'); |
| 71 assertHasDeclaration(ElementKind.CLASS, 'B'); | 78 assertHasDeclaration(ElementKind.CLASS, 'B'); |
| 72 assertHasDeclaration(ElementKind.FUNCTION_TYPE_ALIAS, 'C'); | 79 assertHasDeclaration(ElementKind.FUNCTION_TYPE_ALIAS, 'C'); |
| 73 assertHasDeclaration(ElementKind.FUNCTION, 'D'); | 80 assertHasDeclaration(ElementKind.FUNCTION, 'D'); |
| 74 assertHasDeclaration(ElementKind.TOP_LEVEL_VARIABLE, 'E'); | 81 assertHasDeclaration(ElementKind.TOP_LEVEL_VARIABLE, 'E'); |
| 75 assertNoDeclaration(ElementKind.CLASS, 'ABC'); | 82 assertNoDeclaration(ElementKind.CLASS, 'ABC'); |
| 76 } | 83 } |
| 77 | |
| 78 test_invalidRegex() async { | |
| 79 var result = await findTopLevelDeclarations('[A'); | |
| 80 expect(result, new isInstanceOf<RequestError>()); | |
| 81 } | |
| 82 } | 84 } |
| OLD | NEW |