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

Side by Side Diff: pkg/analyzer/test/src/summary/resynthesize_test.dart

Issue 1699243003: Serialize and resynthesize unresolved constant instance creations. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Add more tests. Created 4 years, 10 months 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
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 test.src.serialization.elements_test; 5 library test.src.serialization.elements_test;
6 6
7 import 'dart:convert'; 7 import 'dart:convert';
8 8
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/element/element.dart'; 10 import 'package:analyzer/dart/element/element.dart';
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 expect(o.elementAnnotation, isNull); 470 expect(o.elementAnnotation, isNull);
471 expect(r.elementAnnotation, isNull); 471 expect(r.elementAnnotation, isNull);
472 } else { 472 } else {
473 fail('Not implemented for ${r.runtimeType} vs. ${o.runtimeType}'); 473 fail('Not implemented for ${r.runtimeType} vs. ${o.runtimeType}');
474 } 474 }
475 } 475 }
476 } 476 }
477 477
478 void compareConstructorElements(ConstructorElement resynthesized, 478 void compareConstructorElements(ConstructorElement resynthesized,
479 ConstructorElement original, String desc) { 479 ConstructorElement original, String desc) {
480 if (original == null && resynthesized == null) {
481 return;
482 }
480 compareExecutableElements(resynthesized, original, desc); 483 compareExecutableElements(resynthesized, original, desc);
481 if (original.isConst) { 484 if (original.isConst) {
482 ConstructorElementImpl resynthesizedImpl = 485 ConstructorElementImpl resynthesizedImpl =
483 getActualElement(resynthesized, desc); 486 getActualElement(resynthesized, desc);
484 ConstructorElementImpl originalImpl = getActualElement(original, desc); 487 ConstructorElementImpl originalImpl = getActualElement(original, desc);
485 compareConstAstLists(resynthesizedImpl.constantInitializers, 488 compareConstAstLists(resynthesizedImpl.constantInitializers,
486 originalImpl.constantInitializers, desc); 489 originalImpl.constantInitializers, desc);
487 } 490 }
488 if (original.redirectedConstructor == null) { 491 if (original.redirectedConstructor == null) {
489 expect(resynthesized.redirectedConstructor, isNull, reason: desc); 492 expect(resynthesized.redirectedConstructor, isNull, reason: desc);
(...skipping 17 matching lines...) Expand all
507 expect(resynthesized.annotationAst, isNotNull, reason: desc); 510 expect(resynthesized.annotationAst, isNotNull, reason: desc);
508 compareConstAsts(resynthesized.annotationAst, original.annotationAst, desc); 511 compareConstAsts(resynthesized.annotationAst, original.annotationAst, desc);
509 } 512 }
510 513
511 void compareElements(Element resynthesized, Element original, String desc) { 514 void compareElements(Element resynthesized, Element original, String desc) {
512 ElementImpl rImpl = getActualElement(resynthesized, desc); 515 ElementImpl rImpl = getActualElement(resynthesized, desc);
513 ElementImpl oImpl = getActualElement(original, desc); 516 ElementImpl oImpl = getActualElement(original, desc);
514 if (oImpl == null && rImpl == null) { 517 if (oImpl == null && rImpl == null) {
515 return; 518 return;
516 } 519 }
520 if (oImpl is PrefixElement) {
521 // TODO(scheglov) prefixes cannot be resynthesized
522 return;
523 }
517 expect(original, isNotNull); 524 expect(original, isNotNull);
518 expect(resynthesized, isNotNull); 525 expect(resynthesized, isNotNull);
519 expect(rImpl.runtimeType, oImpl.runtimeType); 526 expect(rImpl.runtimeType, oImpl.runtimeType);
520 expect(resynthesized.kind, original.kind); 527 expect(resynthesized.kind, original.kind);
521 expect(resynthesized.location, original.location, reason: desc); 528 expect(resynthesized.location, original.location, reason: desc);
522 expect(resynthesized.name, original.name); 529 expect(resynthesized.name, original.name);
523 expect(resynthesized.nameOffset, original.nameOffset, reason: desc); 530 expect(resynthesized.nameOffset, original.nameOffset, reason: desc);
524 expect(resynthesized.documentationComment, original.documentationComment, 531 expect(resynthesized.documentationComment, original.documentationComment,
525 reason: desc); 532 reason: desc);
526 expect(resynthesized.docRange, original.docRange, reason: desc); 533 expect(resynthesized.docRange, original.docRange, reason: desc);
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 } 833 }
827 } 834 }
828 expect(resynthesized.typeFormals.length, original.typeFormals.length, 835 expect(resynthesized.typeFormals.length, original.typeFormals.length,
829 reason: desc); 836 reason: desc);
830 for (int i = 0; i < resynthesized.typeFormals.length; i++) { 837 for (int i = 0; i < resynthesized.typeFormals.length; i++) {
831 compareTypeParameterElements(resynthesized.typeFormals[i], 838 compareTypeParameterElements(resynthesized.typeFormals[i],
832 original.typeFormals[i], '$desc bound type parameter $i'); 839 original.typeFormals[i], '$desc bound type parameter $i');
833 } 840 }
834 } else if (resynthesized is VoidTypeImpl && original is VoidTypeImpl) { 841 } else if (resynthesized is VoidTypeImpl && original is VoidTypeImpl) {
835 expect(resynthesized, same(original)); 842 expect(resynthesized, same(original));
843 } else if (resynthesized is DynamicTypeImpl &&
844 original is UndefinedTypeImpl) {
845 // TODO(scheglov) In the strong mode constant variable like
846 // `var V = new Unresolved()` gets `UndefinedTypeImpl`, and it gets
847 // `DynamicTypeImpl` in the spec mode.
836 } else if (resynthesized.runtimeType != original.runtimeType) { 848 } else if (resynthesized.runtimeType != original.runtimeType) {
837 fail('Type mismatch: expected ${original.runtimeType},' 849 fail('Type mismatch: expected ${original.runtimeType},'
838 ' got ${resynthesized.runtimeType} ($desc)'); 850 ' got ${resynthesized.runtimeType} ($desc)');
839 } else { 851 } else {
840 fail('Unimplemented comparison for ${original.runtimeType}'); 852 fail('Unimplemented comparison for ${original.runtimeType}');
841 } 853 }
842 } 854 }
843 855
844 void compareUriReferencedElements(UriReferencedElementImpl resynthesized, 856 void compareUriReferencedElements(UriReferencedElementImpl resynthesized,
845 UriReferencedElementImpl original, String desc) { 857 UriReferencedElementImpl original, String desc) {
(...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after
1450 class C { 1462 class C {
1451 const C.named(); 1463 const C.named();
1452 } 1464 }
1453 '''); 1465 ''');
1454 checkLibrary(r''' 1466 checkLibrary(r'''
1455 import 'a.dart' as p; 1467 import 'a.dart' as p;
1456 const V = const p.C.named(); 1468 const V = const p.C.named();
1457 '''); 1469 ''');
1458 } 1470 }
1459 1471
1472 test_const_invokeConstructor_named_unresolved() {
1473 checkLibrary(
1474 r'''
1475 class C {}
1476 const V = const C.named();
1477 ''',
1478 allowErrors: true);
1479 }
1480
1481 test_const_invokeConstructor_named_unresolved2() {
1482 checkLibrary(
1483 r'''
1484 const V = const C.named();
1485 ''',
1486 allowErrors: true);
1487 }
1488
1489 test_const_invokeConstructor_named_unresolved3() {
1490 addLibrarySource(
1491 '/a.dart',
1492 r'''
1493 class C {
1494 }
1495 ''');
1496 checkLibrary(
1497 r'''
1498 import 'a.dart' as p;
1499 const V = const p.C.named();
1500 ''',
1501 allowErrors: true);
1502 }
1503
1504 test_const_invokeConstructor_named_unresolved4() {
1505 addLibrarySource('/a.dart', '');
1506 checkLibrary(
1507 r'''
1508 import 'a.dart' as p;
1509 const V = const p.C.named();
1510 ''',
1511 allowErrors: true);
1512 }
1513
1514 test_const_invokeConstructor_named_unresolved5() {
1515 checkLibrary(
1516 r'''
1517 const V = const p.C.named();
1518 ''',
1519 allowErrors: true);
1520 }
1521
1460 test_const_invokeConstructor_unnamed() { 1522 test_const_invokeConstructor_unnamed() {
1461 checkLibrary(r''' 1523 checkLibrary(r'''
1462 class C { 1524 class C {
1463 const C(); 1525 const C();
1464 } 1526 }
1465 const V = const C(); 1527 const V = const C();
1466 '''); 1528 ''');
1467 } 1529 }
1468 1530
1469 test_const_invokeConstructor_unnamed_imported() { 1531 test_const_invokeConstructor_unnamed_imported() {
(...skipping 17 matching lines...) Expand all
1487 class C { 1549 class C {
1488 const C(); 1550 const C();
1489 } 1551 }
1490 '''); 1552 ''');
1491 checkLibrary(r''' 1553 checkLibrary(r'''
1492 import 'a.dart' as p; 1554 import 'a.dart' as p;
1493 const V = const p.C(); 1555 const V = const p.C();
1494 '''); 1556 ''');
1495 } 1557 }
1496 1558
1559 test_const_invokeConstructor_unnamed_unresolved() {
1560 checkLibrary(
1561 r'''
1562 const V = const C();
1563 ''',
1564 allowErrors: true);
1565 }
1566
1567 test_const_invokeConstructor_unnamed_unresolved2() {
1568 addLibrarySource('/a.dart', '');
1569 checkLibrary(
1570 r'''
1571 import 'a.dart' as p;
1572 const V = const p.C();
1573 ''',
1574 allowErrors: true);
1575 }
1576
1577 test_const_invokeConstructor_unnamed_unresolved3() {
1578 checkLibrary(
1579 r'''
1580 const V = const p.C();
1581 ''',
1582 allowErrors: true);
1583 }
1584
1497 test_const_length_ofClassConstField() { 1585 test_const_length_ofClassConstField() {
1498 checkLibrary(r''' 1586 checkLibrary(r'''
1499 class C { 1587 class C {
1500 static const String F = ''; 1588 static const String F = '';
1501 } 1589 }
1502 const int v = C.F.length; 1590 const int v = C.F.length;
1503 '''); 1591 ''');
1504 } 1592 }
1505 1593
1506 test_const_length_ofClassConstField_imported() { 1594 test_const_length_ofClassConstField_imported() {
(...skipping 2039 matching lines...) Expand 10 before | Expand all | Expand 10 after
3546 fail('Unexpectedly tried to get unlinked summary for $uri'); 3634 fail('Unexpectedly tried to get unlinked summary for $uri');
3547 } 3635 }
3548 return serializedUnit; 3636 return serializedUnit;
3549 } 3637 }
3550 3638
3551 @override 3639 @override
3552 bool hasLibrarySummary(String uri) { 3640 bool hasLibrarySummary(String uri) {
3553 return true; 3641 return true;
3554 } 3642 }
3555 } 3643 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/summarize_elements.dart ('k') | pkg/analyzer/test/src/summary/summary_common.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698