Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: pkg/analyzer/test/src/dart/analysis/file_state_test.dart

Issue 2542883003: Compute exported top-level declarations. (Closed)
Patch Set: Fix to support export from the same library twice. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/analyzer/lib/src/dart/analysis/file_state.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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_exportedTopLevelDeclarations_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.exportedTopLevelDeclarations;
77 expect(declarations.map((t) => t.name), unorderedEquals(['A', 'B']));
78 }
79
80 test_exportedTopLevelDeclarations_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_exportedTopLevelDeclarations_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_exportedTopLevelDeclarations_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_exportedTopLevelDeclarations_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.exportedTopLevelDeclarations;
166 expect(declarations.map((t) => t.name), unorderedEquals(['V']));
167 expect(declarations.single.kind, TopLevelDeclarationKind.variable);
168 }
169
170 test_exportedTopLevelDeclarations_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_exportedTopLevelDeclarations_export_show2() {
189 String a = _p('/aaa/lib/a.dart');
190 String b = _p('/aaa/lib/b.dart');
191 String c = _p('/aaa/lib/c.dart');
192 String d = _p('/aaa/lib/d.dart');
193 provider.newFile(
194 a,
195 r'''
196 export 'b.dart' show Foo;
197 export 'c.dart' show Bar;
198 ''');
199 provider.newFile(
200 b,
201 r'''
202 export 'd.dart';
203 ''');
204 provider.newFile(
205 c,
206 r'''
207 export 'd.dart';
208 ''');
209 provider.newFile(
210 d,
211 r'''
212 class Foo {}
213 class Bar {}
214 ''');
215 _assertExportedTopLevelDeclarations(a, ['Foo', 'Bar']);
216 }
217
218 test_exportedTopLevelDeclarations_import() {
219 String a = _p('/aaa/lib/a.dart');
220 String b = _p('/aaa/lib/b.dart');
221 provider.newFile(
222 a,
223 r'''
224 class A {}
225 ''');
226 provider.newFile(
227 b,
228 r'''
229 import 'a.dart';
230 class B {}
231 ''');
232 _assertExportedTopLevelDeclarations(b, ['B']);
233 }
234
235 test_exportedTopLevelDeclarations_parts() {
236 String a = _p('/aaa/lib/a.dart');
237 String a2 = _p('/aaa/lib/a2.dart');
238 provider.newFile(
239 a,
240 r'''
241 library lib;
242 part 'a2.dart';
243 class A1 {}
244 ''');
245 provider.newFile(
246 a2,
247 r'''
248 part of lib;
249 class A2 {}
250 ''');
251 _assertExportedTopLevelDeclarations(a, ['A1', 'A2']);
252 }
253
61 test_getFileForPath_doesNotExist() { 254 test_getFileForPath_doesNotExist() {
62 String path = _p('/aaa/lib/a.dart'); 255 String path = _p('/aaa/lib/a.dart');
63 FileState file = fileSystemState.getFileForPath(path); 256 FileState file = fileSystemState.getFileForPath(path);
64 expect(file.path, path); 257 expect(file.path, path);
65 expect(file.uri, FastUri.parse('package:aaa/a.dart')); 258 expect(file.uri, FastUri.parse('package:aaa/a.dart'));
66 expect(file.content, ''); 259 expect(file.content, '');
67 expect(file.contentHash, _md5('')); 260 expect(file.contentHash, _md5(''));
68 expect(file.importedFiles, isEmpty); 261 expect(file.importedFiles, isEmpty);
69 expect(file.exportedFiles, isEmpty); 262 expect(file.exportedFiles, isEmpty);
70 expect(file.partedFiles, isEmpty); 263 expect(file.partedFiles, isEmpty);
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 fa.refresh(); 627 fa.refresh();
435 expect(fileSystemState.test.filesWithoutTransitiveFiles, isEmpty); 628 expect(fileSystemState.test.filesWithoutTransitiveFiles, isEmpty);
436 629
437 // Change a.dart API signature, also flush signatures of b.dart and c.dart, 630 // Change a.dart API signature, also flush signatures of b.dart and c.dart,
438 // but d.dart is still OK. 631 // but d.dart is still OK.
439 provider.newFile(pa, "class A2 {}"); 632 provider.newFile(pa, "class A2 {}");
440 fa.refresh(); 633 fa.refresh();
441 _assertFilesWithoutTransitiveSignatures([fa, fb, fc]); 634 _assertFilesWithoutTransitiveSignatures([fa, fb, fc]);
442 } 635 }
443 636
637 void _assertExportedTopLevelDeclarations(String path, List<String> expected) {
638 FileState file = fileSystemState.getFileForPath(path);
639 List<TopLevelDeclaration> declarations = file.exportedTopLevelDeclarations;
640 expect(declarations.map((t) => t.name), unorderedEquals(expected));
641 }
642
444 void _assertFilesWithoutTransitiveFiles(List<FileState> expected) { 643 void _assertFilesWithoutTransitiveFiles(List<FileState> expected) {
445 var actual = fileSystemState.test.filesWithoutTransitiveFiles; 644 var actual = fileSystemState.test.filesWithoutTransitiveFiles;
446 expect(actual, unorderedEquals(expected)); 645 expect(actual, unorderedEquals(expected));
447 } 646 }
448 647
449 void _assertFilesWithoutTransitiveSignatures(List<FileState> expected) { 648 void _assertFilesWithoutTransitiveSignatures(List<FileState> expected) {
450 var actual = fileSystemState.test.filesWithoutTransitiveSignature; 649 var actual = fileSystemState.test.filesWithoutTransitiveSignature;
451 expect(actual, unorderedEquals(expected)); 650 expect(actual, unorderedEquals(expected));
452 } 651 }
453 652
454 void _assertTransitiveFiles(FileState file, List<FileState> expected) { 653 void _assertTransitiveFiles(FileState file, List<FileState> expected) {
455 expect(file.transitiveFiles, unorderedEquals(expected)); 654 expect(file.transitiveFiles, unorderedEquals(expected));
456 } 655 }
457 656
458 String _p(String path) => provider.convertPath(path); 657 String _p(String path) => provider.convertPath(path);
459 658
460 static String _md5(String content) { 659 static String _md5(String content) {
461 return hex.encode(md5.convert(UTF8.encode(content)).bytes); 660 return hex.encode(md5.convert(UTF8.encode(content)).bytes);
462 } 661 }
463 } 662 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/dart/analysis/file_state.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698