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

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

Issue 1668983002: Resynthesize 'String.length' getter references in constants. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: 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 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 9e062abed7d3b1944f44ea63221e4ee0409d7a3b..b229219a22be7336c5b7931884c448e3c84f8cfe 100644
--- a/pkg/analyzer/test/src/summary/resynthesize_test.dart
+++ b/pkg/analyzer/test/src/summary/resynthesize_test.dart
@@ -268,12 +268,17 @@ class ResynthTest extends ResolverTestCase {
// We don't resynthesize parenthesis, so just ignore it.
compareConstantExpressions(r, o.expression, desc);
} else if (o is SimpleIdentifier && r is SimpleIdentifier) {
- expect(r.name, o.name);
+ expect(r.name, o.name, reason: desc);
compareElements(r.staticElement, o.staticElement, desc);
} else if (o is PrefixedIdentifier && r is SimpleIdentifier) {
// We don't resynthesize prefixed identifiers.
// We use simple identifiers with correct elements.
compareConstantExpressions(r, o.identifier, desc);
+ } else if (o is PropertyAccess && r is PropertyAccess) {
+ compareConstantExpressions(r.target, o.target, desc);
+ expect(r.propertyName.name, o.propertyName.name, reason: desc);
+ compareElements(
+ r.propertyName.staticElement, o.propertyName.staticElement, desc);
} else if (o is PropertyAccess && r is SimpleIdentifier) {
// We don't resynthesize property access.
// We use simple identifiers with correct elements.
@@ -1237,6 +1242,97 @@ const V = const p.C();
''');
}
+ test_const_length_ofClassConstField() {
+ shouldCompareConstValues = true;
+ checkLibrary(r'''
+class C {
+ static const String F = '';
+}
+const int v = C.F.length;
+''');
+ }
+
+ test_const_length_ofClassConstField_imported() {
+ shouldCompareConstValues = true;
+ addLibrarySource(
+ '/a.dart',
+ r'''
+class C {
+ static const String F = '';
+}
+''');
+ checkLibrary(r'''
+import 'a.dart';
+const int v = C.F.length;
+''');
+ }
+
+ test_const_length_ofClassConstField_imported_withPrefix() {
+ shouldCompareConstValues = true;
+ addLibrarySource(
+ '/a.dart',
+ r'''
+class C {
+ static const String F = '';
+}
+''');
+ checkLibrary(r'''
+import 'a.dart' as p;
+const int v = p.C.F.length;
+''');
+ }
+
+ test_const_length_ofStringLiteral() {
+ shouldCompareConstValues = true;
+ checkLibrary(r'''
+const v = 'abc'.length;
+''');
+ }
+
+ test_const_length_ofTopLevelVariable() {
+ shouldCompareConstValues = true;
+ checkLibrary(r'''
+const String S = 'abc';
+const v = S.length;
+''');
+ }
+
+ test_const_length_ofTopLevelVariable_imported() {
+ shouldCompareConstValues = true;
+ addLibrarySource(
+ '/a.dart',
+ r'''
+const String S = 'abc';
+''');
+ checkLibrary(r'''
+import 'a.dart';
+const v = S.length;
+''');
+ }
+
+ test_const_length_ofTopLevelVariable_imported_withPrefix() {
+ shouldCompareConstValues = true;
+ addLibrarySource(
+ '/a.dart',
+ r'''
+const String S = 'abc';
+''');
+ checkLibrary(r'''
+import 'a.dart' as p;
+const v = p.S.length;
+''');
+ }
+
+ test_const_length_staticMethod() {
+ shouldCompareConstValues = true;
+ checkLibrary(r'''
+class C {
+ static int length() => 42;
+}
+const v = C.length;
+''');
+ }
+
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