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

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

Issue 2575683002: Fix for searching top-level declarations in parts. (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/driver.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 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';
(...skipping 878 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 provider.newFile(a, 'class A {}'); 889 provider.newFile(a, 'class A {}');
890 provider.newFile(b, 'export "a.dart", class B {}'); 890 provider.newFile(b, 'export "a.dart", class B {}');
891 provider.newFile(c, 'import "d.dart"; class C {}'); 891 provider.newFile(c, 'import "d.dart"; class C {}');
892 provider.newFile(d, 'class D {}'); 892 provider.newFile(d, 'class D {}');
893 893
894 driver.addFile(a); 894 driver.addFile(a);
895 driver.addFile(b); 895 driver.addFile(b);
896 driver.addFile(c); 896 driver.addFile(c);
897 // Don't add d.dart, it is referenced implicitly. 897 // Don't add d.dart, it is referenced implicitly.
898 898
899 void assertDeclarations(List<TopLevelDeclarationInSource> declarations, 899 _assertTopLevelDeclarations(
900 List<String> expectedFiles, List<bool> expectedIsExported) {
901 expect(expectedFiles, hasLength(expectedIsExported.length));
902 for (int i = 0; i < expectedFiles.length; i++) {
903 expect(declarations,
904 contains(predicate((TopLevelDeclarationInSource declaration) {
905 return declaration.source.fullName == expectedFiles[i] &&
906 declaration.isExported == expectedIsExported[i];
907 })));
908 }
909 }
910
911 assertDeclarations(
912 await driver.getTopLevelNameDeclarations('A'), [a, b], [false, true]); 900 await driver.getTopLevelNameDeclarations('A'), [a, b], [false, true]);
913 901
914 assertDeclarations( 902 _assertTopLevelDeclarations(
915 await driver.getTopLevelNameDeclarations('B'), [b], [false]); 903 await driver.getTopLevelNameDeclarations('B'), [b], [false]);
916 904
917 assertDeclarations( 905 _assertTopLevelDeclarations(
918 await driver.getTopLevelNameDeclarations('C'), [c], [false]); 906 await driver.getTopLevelNameDeclarations('C'), [c], [false]);
919 907
920 assertDeclarations( 908 _assertTopLevelDeclarations(
921 await driver.getTopLevelNameDeclarations('D'), [d], [false]); 909 await driver.getTopLevelNameDeclarations('D'), [d], [false]);
922 910
923 assertDeclarations(await driver.getTopLevelNameDeclarations('X'), [], []); 911 _assertTopLevelDeclarations(
912 await driver.getTopLevelNameDeclarations('X'), [], []);
913 }
914
915 test_getTopLevelNameDeclarations_parts() async {
916 var a = _p('/test/lib/a.dart');
917 var b = _p('/test/lib/b.dart');
918 var c = _p('/test/lib/c.dart');
919
920 provider.newFile(
921 a,
922 r'''
923 library lib;
924 part 'b.dart';
925 part 'c.dart';
926 class A {}
927 ''');
928 provider.newFile(b, 'part of lib; class B {}');
929 provider.newFile(c, 'part of lib; class C {}');
930
931 driver.addFile(a);
932 driver.addFile(b);
933 driver.addFile(c);
934
935 _assertTopLevelDeclarations(
936 await driver.getTopLevelNameDeclarations('A'), [a], [false]);
937
938 _assertTopLevelDeclarations(
939 await driver.getTopLevelNameDeclarations('B'), [a], [false]);
940
941 _assertTopLevelDeclarations(
942 await driver.getTopLevelNameDeclarations('C'), [a], [false]);
943
944 _assertTopLevelDeclarations(
945 await driver.getTopLevelNameDeclarations('X'), [], []);
924 } 946 }
925 947
926 test_getUnitElement() async { 948 test_getUnitElement() async {
927 String content = r''' 949 String content = r'''
928 foo(int p) {} 950 foo(int p) {}
929 main() { 951 main() {
930 foo(42); 952 foo(42);
931 } 953 }
932 '''; 954 ''';
933 addTestFile(content); 955 addTestFile(content);
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
1423 addTestFile('int f() => 42;'); 1445 addTestFile('int f() => 42;');
1424 await _waitForIdle(); 1446 await _waitForIdle();
1425 1447
1426 expect(allStatuses, hasLength(2)); 1448 expect(allStatuses, hasLength(2));
1427 expect(allStatuses[0].isAnalyzing, isTrue); 1449 expect(allStatuses[0].isAnalyzing, isTrue);
1428 expect(allStatuses[0].isIdle, isFalse); 1450 expect(allStatuses[0].isIdle, isFalse);
1429 expect(allStatuses[1].isAnalyzing, isFalse); 1451 expect(allStatuses[1].isAnalyzing, isFalse);
1430 expect(allStatuses[1].isIdle, isTrue); 1452 expect(allStatuses[1].isIdle, isTrue);
1431 } 1453 }
1432 1454
1455 void _assertTopLevelDeclarations(
1456 List<TopLevelDeclarationInSource> declarations,
1457 List<String> expectedFiles,
1458 List<bool> expectedIsExported) {
1459 expect(expectedFiles, hasLength(expectedIsExported.length));
1460 for (int i = 0; i < expectedFiles.length; i++) {
1461 expect(declarations,
1462 contains(predicate((TopLevelDeclarationInSource declaration) {
1463 return declaration.source.fullName == expectedFiles[i] &&
1464 declaration.isExported == expectedIsExported[i];
1465 })));
1466 }
1467 }
1468
1433 ClassDeclaration _getClass(CompilationUnit unit, String name) { 1469 ClassDeclaration _getClass(CompilationUnit unit, String name) {
1434 for (CompilationUnitMember declaration in unit.declarations) { 1470 for (CompilationUnitMember declaration in unit.declarations) {
1435 if (declaration is ClassDeclaration) { 1471 if (declaration is ClassDeclaration) {
1436 if (declaration.name.name == name) { 1472 if (declaration.name.name == name) {
1437 return declaration; 1473 return declaration;
1438 } 1474 }
1439 } 1475 }
1440 } 1476 }
1441 fail('Cannot find the class $name in\n$unit'); 1477 fail('Cannot find the class $name in\n$unit');
1442 return null; 1478 return null;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1527 String _p(String path) => provider.convertPath(path); 1563 String _p(String path) => provider.convertPath(path);
1528 1564
1529 Future<Null> _waitForIdle() async { 1565 Future<Null> _waitForIdle() async {
1530 await idleStatusMonitor.signal; 1566 await idleStatusMonitor.signal;
1531 } 1567 }
1532 1568
1533 static String _md5(String content) { 1569 static String _md5(String content) {
1534 return hex.encode(md5.convert(UTF8.encode(content)).bytes); 1570 return hex.encode(md5.convert(UTF8.encode(content)).bytes);
1535 } 1571 }
1536 } 1572 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/dart/analysis/driver.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698