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

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

Issue 1649533005: Compute literal constant values. (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 c4692fca0db29d95d0bf1b2793fced8bedddd37c..0695bc2781d510ef5674f5ce575b870ebee33ad2 100644
--- a/pkg/analyzer/test/src/summary/resynthesize_test.dart
+++ b/pkg/analyzer/test/src/summary/resynthesize_test.dart
@@ -8,6 +8,7 @@ import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/type.dart';
import 'package:analyzer/src/dart/element/element.dart';
import 'package:analyzer/src/dart/element/type.dart';
+import 'package:analyzer/src/generated/constant.dart';
import 'package:analyzer/src/generated/element_handle.dart';
import 'package:analyzer/src/generated/engine.dart';
import 'package:analyzer/src/generated/resolver.dart'
@@ -29,6 +30,7 @@ main() {
@reflectiveTest
class ResynthTest extends ResolverTestCase {
Set<Source> otherLibrarySources = new Set<Source>();
+ bool shouldCompareConstValues = false;
/**
* Determine the analysis options that should be used for this test.
@@ -201,6 +203,40 @@ class ResynthTest extends ResolverTestCase {
// TODO(paulberry): test metadata and offsetToElementMap.
}
+ void compareConstantValues(
+ DartObject resynthesized, DartObject original, String desc) {
+ if (original == null) {
+ expect(resynthesized, isNull, reason: desc);
+ } else {
+ expect(resynthesized, isNotNull, reason: desc);
+ compareTypes(resynthesized.type, original.type, desc);
+ expect(resynthesized.hasKnownValue, original.hasKnownValue, reason: desc);
+ if (original.isNull) {
+ expect(resynthesized.isNull, isTrue, reason: desc);
+ } else if (original.toBoolValue() != null) {
+ expect(resynthesized.toBoolValue(), original.toBoolValue(),
+ reason: desc);
+ } else if (original.toIntValue() != null) {
+ expect(resynthesized.toIntValue(), original.toIntValue(), reason: desc);
+ } else if (original.toDoubleValue() != null) {
+ expect(resynthesized.toDoubleValue(), original.toDoubleValue(),
+ reason: desc);
+ } else if (original.toListValue() != null) {
+ fail('Not implemented');
+ } else if (original.toMapValue() != null) {
+ fail('Not implemented');
+ } else if (original.toStringValue() != null) {
+ expect(resynthesized.toStringValue(), original.toStringValue(),
+ reason: desc);
+ } else if (original.toSymbolValue() != null) {
+ fail('Not implemented');
+ } else if (original.toTypeValue() != null) {
+ fail('Not implemented');
+ }
+ // TODO(scheglov) implement
+ }
+ }
+
void compareConstructorElements(ConstructorElementImpl resynthesized,
ConstructorElementImpl original, String desc) {
compareExecutableElements(resynthesized, original, desc);
@@ -509,6 +545,10 @@ class ResynthTest extends ResolverTestCase {
VariableElementImpl original, String desc) {
compareElements(resynthesized, original, desc);
compareTypes(resynthesized.type, original.type, desc);
+ if (shouldCompareConstValues) {
+ compareConstantValues(
+ resynthesized.constantValue, original.constantValue, desc);
+ }
// TODO(paulberry): test initializer
}
@@ -912,6 +952,20 @@ class E {}''');
checkLibrary('class C {} class D {}');
}
+ test_const_topLevel_literal() {
+ shouldCompareConstValues = true;
+ checkLibrary(r'''
+const vNull = null;
+const vBoolFalse = false;
+const vBoolTrue = true;
+const vInt = 1;
+const vDouble = 2.3;
+const vString = 'abc';
+const vStringConcat = 'aaa' 'bbb';
+const vStringInterpolation = 'aaa ${true} ${42} bbb';
+''');
+ }
+
test_constructor_documented() {
checkLibrary('''
class C {
« 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