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 import 'dart:convert'; | 5 import 'dart:convert'; |
6 import 'dart:typed_data'; | 6 import 'dart:typed_data'; |
7 | 7 |
8 import 'package:analyzer/file_system/file_system.dart'; | 8 import 'package:analyzer/file_system/file_system.dart'; |
9 import 'package:analyzer/file_system/memory_file_system.dart'; | 9 import 'package:analyzer/file_system/memory_file_system.dart'; |
10 import 'package:analyzer/source/package_map_resolver.dart'; | 10 import 'package:analyzer/source/package_map_resolver.dart'; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 'bbb': [provider.getFolder(_p('/bbb/lib'))], | 51 'bbb': [provider.getFolder(_p('/bbb/lib'))], |
52 }), | 52 }), |
53 new ResourceUriResolver(provider) | 53 new ResourceUriResolver(provider) |
54 ], null, provider); | 54 ], null, provider); |
55 AnalysisOptions analysisOptions = new AnalysisOptionsImpl() | 55 AnalysisOptions analysisOptions = new AnalysisOptionsImpl() |
56 ..strongMode = true; | 56 ..strongMode = true; |
57 fileSystemState = new FileSystemState(logger, byteStore, contentOverlay, | 57 fileSystemState = new FileSystemState(logger, byteStore, contentOverlay, |
58 provider, sourceFactory, analysisOptions, new Uint32List(0), ''); | 58 provider, sourceFactory, analysisOptions, new Uint32List(0), ''); |
59 } | 59 } |
60 | 60 |
| 61 test_exportTopLevelDeclarations_export() { |
| 62 String a = _p('/aaa/lib/a.dart'); |
| 63 String b = _p('/aaa/lib/b.dart'); |
| 64 provider.newFile( |
| 65 a, |
| 66 r''' |
| 67 class A {} |
| 68 '''); |
| 69 provider.newFile( |
| 70 b, |
| 71 r''' |
| 72 export 'a.dart'; |
| 73 class B {} |
| 74 '''); |
| 75 FileState file = fileSystemState.getFileForPath(b); |
| 76 List<TopLevelDeclaration> declarations = file.exportTopLevelDeclarations; |
| 77 expect(declarations.map((t) => t.name), unorderedEquals(['A', 'B'])); |
| 78 } |
| 79 |
| 80 test_exportTopLevelDeclarations_export2_show() { |
| 81 String a = _p('/aaa/lib/a.dart'); |
| 82 String b = _p('/aaa/lib/b.dart'); |
| 83 String c = _p('/aaa/lib/c.dart'); |
| 84 provider.newFile( |
| 85 a, |
| 86 r''' |
| 87 class A1 {} |
| 88 class A2 {} |
| 89 class A3 {} |
| 90 '''); |
| 91 provider.newFile( |
| 92 b, |
| 93 r''' |
| 94 export 'a.dart' show A1, A2; |
| 95 class B1 {} |
| 96 class B2 {} |
| 97 '''); |
| 98 provider.newFile( |
| 99 c, |
| 100 r''' |
| 101 export 'b.dart' show A2, A3, B1; |
| 102 class C {} |
| 103 '''); |
| 104 _assertExportedTopLevelDeclarations(c, ['A2', 'B1', 'C']); |
| 105 } |
| 106 |
| 107 test_exportTopLevelDeclarations_export_flushOnChange() { |
| 108 String a = _p('/aaa/lib/a.dart'); |
| 109 String b = _p('/aaa/lib/b.dart'); |
| 110 provider.newFile( |
| 111 a, |
| 112 r''' |
| 113 class A {} |
| 114 '''); |
| 115 provider.newFile( |
| 116 b, |
| 117 r''' |
| 118 export 'a.dart'; |
| 119 class B {} |
| 120 '''); |
| 121 |
| 122 // Initial exported declarations. |
| 123 _assertExportedTopLevelDeclarations(b, ['A', 'B']); |
| 124 |
| 125 // Update a.dart, so a.dart and b.dart exported declarations are flushed. |
| 126 provider.newFile(a, 'class A {} class A2 {}'); |
| 127 fileSystemState.getFileForPath(a).refresh(); |
| 128 _assertExportedTopLevelDeclarations(b, ['A', 'A2', 'B']); |
| 129 } |
| 130 |
| 131 test_exportTopLevelDeclarations_export_hide() { |
| 132 String a = _p('/aaa/lib/a.dart'); |
| 133 String b = _p('/aaa/lib/b.dart'); |
| 134 provider.newFile( |
| 135 a, |
| 136 r''' |
| 137 class A1 {} |
| 138 class A2 {} |
| 139 class A3 {} |
| 140 '''); |
| 141 provider.newFile( |
| 142 b, |
| 143 r''' |
| 144 export 'a.dart' hide A2; |
| 145 class B {} |
| 146 '''); |
| 147 _assertExportedTopLevelDeclarations(b, ['A1', 'A3', 'B']); |
| 148 } |
| 149 |
| 150 test_exportTopLevelDeclarations_export_preferLocal() { |
| 151 String a = _p('/aaa/lib/a.dart'); |
| 152 String b = _p('/aaa/lib/b.dart'); |
| 153 provider.newFile( |
| 154 a, |
| 155 r''' |
| 156 class V {} |
| 157 '''); |
| 158 provider.newFile( |
| 159 b, |
| 160 r''' |
| 161 export 'a.dart'; |
| 162 int V; |
| 163 '''); |
| 164 FileState file = fileSystemState.getFileForPath(b); |
| 165 List<TopLevelDeclaration> declarations = file.exportTopLevelDeclarations; |
| 166 expect(declarations.map((t) => t.name), unorderedEquals(['V'])); |
| 167 expect(declarations.single.kind, TopLevelDeclarationKind.variable); |
| 168 } |
| 169 |
| 170 test_exportTopLevelDeclarations_export_show() { |
| 171 String a = _p('/aaa/lib/a.dart'); |
| 172 String b = _p('/aaa/lib/b.dart'); |
| 173 provider.newFile( |
| 174 a, |
| 175 r''' |
| 176 class A1 {} |
| 177 class A2 {} |
| 178 '''); |
| 179 provider.newFile( |
| 180 b, |
| 181 r''' |
| 182 export 'a.dart' show A2; |
| 183 class B {} |
| 184 '''); |
| 185 _assertExportedTopLevelDeclarations(b, ['A2', 'B']); |
| 186 } |
| 187 |
| 188 test_exportTopLevelDeclarations_import() { |
| 189 String a = _p('/aaa/lib/a.dart'); |
| 190 String b = _p('/aaa/lib/b.dart'); |
| 191 provider.newFile( |
| 192 a, |
| 193 r''' |
| 194 class A {} |
| 195 '''); |
| 196 provider.newFile( |
| 197 b, |
| 198 r''' |
| 199 import 'a.dart'; |
| 200 class B {} |
| 201 '''); |
| 202 _assertExportedTopLevelDeclarations(b, ['B']); |
| 203 } |
| 204 |
| 205 test_exportTopLevelDeclarations_parts() { |
| 206 String a = _p('/aaa/lib/a.dart'); |
| 207 String a2 = _p('/aaa/lib/a2.dart'); |
| 208 provider.newFile( |
| 209 a, |
| 210 r''' |
| 211 library lib; |
| 212 part 'a2.dart'; |
| 213 class A1 {} |
| 214 '''); |
| 215 provider.newFile( |
| 216 a2, |
| 217 r''' |
| 218 part of lib; |
| 219 class A2 {} |
| 220 '''); |
| 221 _assertExportedTopLevelDeclarations(a, ['A1', 'A2']); |
| 222 } |
| 223 |
61 test_getFileForPath_doesNotExist() { | 224 test_getFileForPath_doesNotExist() { |
62 String path = _p('/aaa/lib/a.dart'); | 225 String path = _p('/aaa/lib/a.dart'); |
63 FileState file = fileSystemState.getFileForPath(path); | 226 FileState file = fileSystemState.getFileForPath(path); |
64 expect(file.path, path); | 227 expect(file.path, path); |
65 expect(file.uri, FastUri.parse('package:aaa/a.dart')); | 228 expect(file.uri, FastUri.parse('package:aaa/a.dart')); |
66 expect(file.content, ''); | 229 expect(file.content, ''); |
67 expect(file.contentHash, _md5('')); | 230 expect(file.contentHash, _md5('')); |
68 expect(file.importedFiles, isEmpty); | 231 expect(file.importedFiles, isEmpty); |
69 expect(file.exportedFiles, isEmpty); | 232 expect(file.exportedFiles, isEmpty); |
70 expect(file.partedFiles, isEmpty); | 233 expect(file.partedFiles, isEmpty); |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 fa.refresh(); | 589 fa.refresh(); |
427 expect(fileSystemState.test.filesWithoutTransitiveFiles, isEmpty); | 590 expect(fileSystemState.test.filesWithoutTransitiveFiles, isEmpty); |
428 | 591 |
429 // Change a.dart API signature, also flush signatures of b.dart and c.dart, | 592 // Change a.dart API signature, also flush signatures of b.dart and c.dart, |
430 // but d.dart is still OK. | 593 // but d.dart is still OK. |
431 provider.newFile(pa, "class A2 {}"); | 594 provider.newFile(pa, "class A2 {}"); |
432 fa.refresh(); | 595 fa.refresh(); |
433 _assertFilesWithoutTransitiveSignatures([fa, fb, fc]); | 596 _assertFilesWithoutTransitiveSignatures([fa, fb, fc]); |
434 } | 597 } |
435 | 598 |
| 599 void _assertExportedTopLevelDeclarations(String path, List<String> expected) { |
| 600 FileState file = fileSystemState.getFileForPath(path); |
| 601 List<TopLevelDeclaration> declarations = file.exportTopLevelDeclarations; |
| 602 expect(declarations.map((t) => t.name), unorderedEquals(expected)); |
| 603 } |
| 604 |
436 void _assertFilesWithoutTransitiveFiles(List<FileState> expected) { | 605 void _assertFilesWithoutTransitiveFiles(List<FileState> expected) { |
437 var actual = fileSystemState.test.filesWithoutTransitiveFiles; | 606 var actual = fileSystemState.test.filesWithoutTransitiveFiles; |
438 expect(actual, unorderedEquals(expected)); | 607 expect(actual, unorderedEquals(expected)); |
439 } | 608 } |
440 | 609 |
441 void _assertFilesWithoutTransitiveSignatures(List<FileState> expected) { | 610 void _assertFilesWithoutTransitiveSignatures(List<FileState> expected) { |
442 var actual = fileSystemState.test.filesWithoutTransitiveSignature; | 611 var actual = fileSystemState.test.filesWithoutTransitiveSignature; |
443 expect(actual, unorderedEquals(expected)); | 612 expect(actual, unorderedEquals(expected)); |
444 } | 613 } |
445 | 614 |
446 void _assertTransitiveFiles(FileState file, List<FileState> expected) { | 615 void _assertTransitiveFiles(FileState file, List<FileState> expected) { |
447 expect(file.transitiveFiles, unorderedEquals(expected)); | 616 expect(file.transitiveFiles, unorderedEquals(expected)); |
448 } | 617 } |
449 | 618 |
450 String _p(String path) => provider.convertPath(path); | 619 String _p(String path) => provider.convertPath(path); |
451 | 620 |
452 static String _md5(String content) { | 621 static String _md5(String content) { |
453 return hex.encode(md5.convert(UTF8.encode(content)).bytes); | 622 return hex.encode(md5.convert(UTF8.encode(content)).bytes); |
454 } | 623 } |
455 } | 624 } |
OLD | NEW |