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

Unified Diff: pkg/analyzer/test/src/summary/resynthesize_test.dart

Issue 1657033002: Resynthesize instance creation expressions. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analyzer/lib/src/summary/resynthesize.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/test/src/summary/resynthesize_test.dart
diff --git a/pkg/analyzer/test/src/summary/resynthesize_test.dart b/pkg/analyzer/test/src/summary/resynthesize_test.dart
index 07b7bc0a10c96e7c0911fa293a503e8251420fd4..5a4d0bc3b8756eee089c8d8a07d4c676bee53ffd 100644
--- a/pkg/analyzer/test/src/summary/resynthesize_test.dart
+++ b/pkg/analyzer/test/src/summary/resynthesize_test.dart
@@ -273,6 +273,9 @@ class ResynthTest extends ResolverTestCase {
expect(r.components.map((t) => t.lexeme).join('.'),
o.components.map((t) => t.lexeme).join('.'),
reason: desc);
+ } else if (o is NamedExpression && r is NamedExpression) {
+ expect(r.name.label.name, o.name.label.name, reason: desc);
+ compareConstantExpressions(r.expression, o.expression, desc);
} else if (o is BinaryExpression && r is BinaryExpression) {
expect(r.operator.lexeme, o.operator.lexeme, reason: desc);
compareConstantExpressions(r.leftOperand, o.leftOperand, desc);
@@ -290,6 +293,24 @@ class ResynthTest extends ResolverTestCase {
} else if (o is MapLiteral && r is MapLiteral) {
compareLists(r.typeArguments?.arguments, o.typeArguments?.arguments);
compareLists(r.entries, o.entries);
+ } else if (o is InstanceCreationExpression &&
+ r is InstanceCreationExpression) {
+ compareElements(r.staticElement, o.staticElement, desc);
+ ConstructorName oConstructor = o.constructorName;
+ ConstructorName rConstructor = r.constructorName;
+ expect(oConstructor, isNotNull, reason: desc);
+ expect(rConstructor, isNotNull, reason: desc);
+ compareElements(
+ rConstructor.staticElement, oConstructor.staticElement, desc);
+ TypeName oType = oConstructor.type;
+ TypeName rType = rConstructor.type;
+ expect(oType, isNotNull, reason: desc);
+ expect(rType, isNotNull, reason: desc);
+ compareConstantExpressions(rType.name, oType.name, desc);
+ compareConstantExpressions(rConstructor.name, oConstructor.name, desc);
+ compareLists(r.argumentList.arguments, o.argumentList.arguments);
+ } else if (o is ConstructorName && r is ConstructorName) {
+ fail('Not implemented for ${r.runtimeType} vs. ${o.runtimeType}');
} else {
fail('Not implemented for ${r.runtimeType} vs. ${o.runtimeType}');
}
@@ -1013,6 +1034,86 @@ class E {}''');
checkLibrary('class C {} class D {}');
}
+ test_const_invokeConstructor_named() {
+ shouldCompareConstValues = true;
+ checkLibrary(r'''
+class C {
+ const C.named(bool a, int b, int c, {String d, double e});
+}
+const V = const C.named(true, 1, 2, d: 'ccc', e: 3.4);
+''');
+ }
+
+ test_const_invokeConstructor_named_imported() {
+ shouldCompareConstValues = true;
+ addLibrarySource(
+ '/a.dart',
+ r'''
+class C {
+ const C.named();
+}
+''');
+ checkLibrary(r'''
+import 'a.dart';
+const V = const C.named();
+''');
+ }
+
+ test_const_invokeConstructor_named_imported_withPrefix() {
+ shouldCompareConstValues = true;
+ addLibrarySource(
+ '/a.dart',
+ r'''
+class C {
+ const C.named();
+}
+''');
+ checkLibrary(r'''
+import 'a.dart' as p;
+const V = const p.C.named();
+''');
+ }
+
+ test_const_invokeConstructor_unnamed() {
+ shouldCompareConstValues = true;
+ checkLibrary(r'''
+class C {
+ const C();
+}
+const V = const C();
+''');
+ }
+
+ test_const_invokeConstructor_unnamed_imported() {
+ shouldCompareConstValues = true;
+ addLibrarySource(
+ '/a.dart',
+ r'''
+class C {
+ const C();
+}
+''');
+ checkLibrary(r'''
+import 'a.dart';
+const V = const C();
+''');
+ }
+
+ test_const_invokeConstructor_unnamed_imported_withPrefix() {
+ shouldCompareConstValues = true;
+ addLibrarySource(
+ '/a.dart',
+ r'''
+class C {
+ const C();
+}
+''');
+ checkLibrary(r'''
+import 'a.dart' as p;
+const V = const p.C();
+''');
+ }
+
test_const_reference_staticField() {
shouldCompareConstValues = true;
checkLibrary(r'''
« no previous file with comments | « pkg/analyzer/lib/src/summary/resynthesize.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698