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

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

Issue 2545753003: Compute top-level declarations in a file. (Closed)
Patch Set: 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/top_level_declarations.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';
11 import 'package:analyzer/src/dart/analysis/byte_store.dart'; 11 import 'package:analyzer/src/dart/analysis/byte_store.dart';
12 import 'package:analyzer/src/dart/analysis/driver.dart' show PerformanceLog; 12 import 'package:analyzer/src/dart/analysis/driver.dart' show PerformanceLog;
13 import 'package:analyzer/src/dart/analysis/file_state.dart'; 13 import 'package:analyzer/src/dart/analysis/file_state.dart';
14 import 'package:analyzer/src/dart/analysis/top_level_declarations.dart';
14 import 'package:analyzer/src/generated/engine.dart' 15 import 'package:analyzer/src/generated/engine.dart'
15 show AnalysisOptions, AnalysisOptionsImpl; 16 show AnalysisOptions, AnalysisOptionsImpl;
16 import 'package:analyzer/src/generated/source.dart'; 17 import 'package:analyzer/src/generated/source.dart';
17 import 'package:analyzer/src/util/fast_uri.dart'; 18 import 'package:analyzer/src/util/fast_uri.dart';
18 import 'package:convert/convert.dart'; 19 import 'package:convert/convert.dart';
19 import 'package:crypto/crypto.dart'; 20 import 'package:crypto/crypto.dart';
20 import 'package:test/test.dart'; 21 import 'package:test/test.dart';
21 import 'package:test_reflective_loader/test_reflective_loader.dart'; 22 import 'package:test_reflective_loader/test_reflective_loader.dart';
22 23
23 import '../../context/mock_sdk.dart'; 24 import '../../context/mock_sdk.dart';
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 print(222); 274 print(222);
274 } 275 }
275 } 276 }
276 '''); 277 ''');
277 bool apiSignatureChanged = file.refresh(); 278 bool apiSignatureChanged = file.refresh();
278 expect(apiSignatureChanged, isFalse); 279 expect(apiSignatureChanged, isFalse);
279 280
280 expect(file.apiSignature, signature); 281 expect(file.apiSignature, signature);
281 } 282 }
282 283
284 test_topLevelDeclarations() {
285 String path = _p('/aaa/lib/a.dart');
286 provider.newFile(
287 path,
288 r'''
289 class C {}
290 typedef F();
291 enum E {E1, E2}
292 void f() {}
293 var V1;
294 get V2 => null;
295 set V3(_) {}
296 get V4 => null;
297 set V4(_) {}
298 ''');
299 FileState file = fileSystemState.getFileForPath(path);
300
301 List<TopLevelDeclaration> topLevelDeclarations = file.topLevelDeclarations;
302
303 void assertHas(String name, TopLevelDeclarationKind kind) {
304 expect(
305 topLevelDeclarations,
306 contains(predicate(
307 (TopLevelDeclaration t) => t.name == name && t.kind == kind)));
308 }
309
310 expect(topLevelDeclarations.map((t) => t.name),
311 unorderedEquals(['C', 'F', 'E', 'f', 'V1', 'V2', 'V3', 'V4']));
312 assertHas('C', TopLevelDeclarationKind.type);
313 assertHas('F', TopLevelDeclarationKind.type);
314 assertHas('E', TopLevelDeclarationKind.type);
315 assertHas('f', TopLevelDeclarationKind.function);
316 assertHas('V1', TopLevelDeclarationKind.variable);
317 assertHas('V2', TopLevelDeclarationKind.variable);
318 assertHas('V3', TopLevelDeclarationKind.variable);
319 assertHas('V4', TopLevelDeclarationKind.variable);
320 }
321
283 test_transitiveFiles() { 322 test_transitiveFiles() {
284 String pa = _p('/aaa/lib/a.dart'); 323 String pa = _p('/aaa/lib/a.dart');
285 String pb = _p('/aaa/lib/b.dart'); 324 String pb = _p('/aaa/lib/b.dart');
286 String pc = _p('/aaa/lib/c.dart'); 325 String pc = _p('/aaa/lib/c.dart');
287 String pd = _p('/aaa/lib/d.dart'); 326 String pd = _p('/aaa/lib/d.dart');
288 327
289 FileState fa = fileSystemState.getFileForPath(pa); 328 FileState fa = fileSystemState.getFileForPath(pa);
290 FileState fb = fileSystemState.getFileForPath(pb); 329 FileState fb = fileSystemState.getFileForPath(pb);
291 FileState fc = fileSystemState.getFileForPath(pc); 330 FileState fc = fileSystemState.getFileForPath(pc);
292 FileState fd = fileSystemState.getFileForPath(pd); 331 FileState fd = fileSystemState.getFileForPath(pd);
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 void _assertTransitiveFiles(FileState file, List<FileState> expected) { 446 void _assertTransitiveFiles(FileState file, List<FileState> expected) {
408 expect(file.transitiveFiles, unorderedEquals(expected)); 447 expect(file.transitiveFiles, unorderedEquals(expected));
409 } 448 }
410 449
411 String _p(String path) => provider.convertPath(path); 450 String _p(String path) => provider.convertPath(path);
412 451
413 static String _md5(String content) { 452 static String _md5(String content) {
414 return hex.encode(md5.convert(UTF8.encode(content)).bytes); 453 return hex.encode(md5.convert(UTF8.encode(content)).bytes);
415 } 454 }
416 } 455 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/dart/analysis/top_level_declarations.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698