OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 analyzer.test.driver; | 5 library analyzer.test.driver; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:convert'; | 8 import 'dart:convert'; |
9 | 9 |
10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
11 import 'package:analyzer/dart/element/element.dart'; | 11 import 'package:analyzer/dart/element/element.dart'; |
12 import 'package:analyzer/error/error.dart'; | 12 import 'package:analyzer/error/error.dart'; |
13 import 'package:analyzer/file_system/file_system.dart'; | 13 import 'package:analyzer/file_system/file_system.dart'; |
14 import 'package:analyzer/file_system/memory_file_system.dart'; | 14 import 'package:analyzer/file_system/memory_file_system.dart'; |
15 import 'package:analyzer/src/dart/analysis/byte_store.dart'; | 15 import 'package:analyzer/src/dart/analysis/byte_store.dart'; |
16 import 'package:analyzer/src/dart/analysis/driver.dart'; | 16 import 'package:analyzer/src/dart/analysis/driver.dart'; |
17 import 'package:analyzer/src/dart/analysis/file_state.dart'; | 17 import 'package:analyzer/src/dart/analysis/file_state.dart'; |
18 import 'package:analyzer/src/dart/analysis/status.dart'; | 18 import 'package:analyzer/src/dart/analysis/status.dart'; |
| 19 import 'package:analyzer/src/dart/analysis/top_level_declaration.dart'; |
19 import 'package:analyzer/src/error/codes.dart'; | 20 import 'package:analyzer/src/error/codes.dart'; |
20 import 'package:analyzer/src/generated/engine.dart' show AnalysisOptionsImpl; | 21 import 'package:analyzer/src/generated/engine.dart' show AnalysisOptionsImpl; |
21 import 'package:analyzer/src/generated/source.dart'; | 22 import 'package:analyzer/src/generated/source.dart'; |
22 import 'package:analyzer/src/summary/idl.dart'; | 23 import 'package:analyzer/src/summary/idl.dart'; |
23 import 'package:convert/convert.dart'; | 24 import 'package:convert/convert.dart'; |
24 import 'package:crypto/crypto.dart'; | 25 import 'package:crypto/crypto.dart'; |
25 import 'package:test/test.dart'; | 26 import 'package:test/test.dart'; |
26 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 27 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
27 | 28 |
28 import '../../context/mock_sdk.dart'; | 29 import '../../context/mock_sdk.dart'; |
(...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
726 Future<AnalysisResult> future2 = driver.getResult(testFile); | 727 Future<AnalysisResult> future2 = driver.getResult(testFile); |
727 | 728 |
728 // Both futures complete, with the same result. | 729 // Both futures complete, with the same result. |
729 AnalysisResult result1 = await future1; | 730 AnalysisResult result1 = await future1; |
730 AnalysisResult result2 = await future2; | 731 AnalysisResult result2 = await future2; |
731 expect(result2, same(result1)); | 732 expect(result2, same(result1)); |
732 expect(result1.path, testFile); | 733 expect(result1.path, testFile); |
733 expect(result1.unit, isNotNull); | 734 expect(result1.unit, isNotNull); |
734 } | 735 } |
735 | 736 |
| 737 test_getTopLevelNameDeclarations() async { |
| 738 var a = _p('/test/lib/a.dart'); |
| 739 var b = _p('/test/lib/b.dart'); |
| 740 var c = _p('/test/lib/c.dart'); |
| 741 var d = _p('/test/lib/d.dart'); |
| 742 |
| 743 provider.newFile(a, 'class A {}'); |
| 744 provider.newFile(b, 'export "a.dart", class B {}'); |
| 745 provider.newFile(c, 'import "d.dart"; class C {}'); |
| 746 provider.newFile(d, 'class D {}'); |
| 747 |
| 748 driver.addFile(a); |
| 749 driver.addFile(b); |
| 750 driver.addFile(c); |
| 751 // Don't add d.dart, it is referenced implicitly. |
| 752 |
| 753 void assertLibraryPaths( |
| 754 List<TopLevelDeclarationInSource> declarations, List<String> expected) { |
| 755 expect(declarations.map((l) => l.source.fullName), |
| 756 unorderedEquals(expected)); |
| 757 } |
| 758 |
| 759 assertLibraryPaths(await driver.getTopLevelNameDeclarations('A'), [a, b]); |
| 760 |
| 761 assertLibraryPaths(await driver.getTopLevelNameDeclarations('B'), [b]); |
| 762 |
| 763 assertLibraryPaths(await driver.getTopLevelNameDeclarations('C'), [c]); |
| 764 |
| 765 assertLibraryPaths(await driver.getTopLevelNameDeclarations('D'), [d]); |
| 766 |
| 767 assertLibraryPaths(await driver.getTopLevelNameDeclarations('X'), []); |
| 768 } |
| 769 |
736 test_knownFiles() async { | 770 test_knownFiles() async { |
737 var a = _p('/test/lib/a.dart'); | 771 var a = _p('/test/lib/a.dart'); |
738 var b = _p('/test/lib/b.dart'); | 772 var b = _p('/test/lib/b.dart'); |
739 | 773 |
740 provider.newFile( | 774 provider.newFile( |
741 a, | 775 a, |
742 r''' | 776 r''' |
743 import 'b.dart'; | 777 import 'b.dart'; |
744 '''); | 778 '''); |
745 | 779 |
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1226 String _p(String path) => provider.convertPath(path); | 1260 String _p(String path) => provider.convertPath(path); |
1227 | 1261 |
1228 Future<Null> _waitForIdle() async { | 1262 Future<Null> _waitForIdle() async { |
1229 await idleStatusMonitor.signal; | 1263 await idleStatusMonitor.signal; |
1230 } | 1264 } |
1231 | 1265 |
1232 static String _md5(String content) { | 1266 static String _md5(String content) { |
1233 return hex.encode(md5.convert(UTF8.encode(content)).bytes); | 1267 return hex.encode(md5.convert(UTF8.encode(content)).bytes); |
1234 } | 1268 } |
1235 } | 1269 } |
OLD | NEW |