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

Unified Diff: pkg/analyzer/test/src/dart/constant/evaluation_test.dart

Issue 2772943002: store constructor and arguments for constant values (Closed)
Patch Set: clean up import Created 3 years, 9 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
« pkg/analyzer/pubspec.yaml ('K') | « pkg/analyzer/pubspec.yaml ('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/dart/constant/evaluation_test.dart
diff --git a/pkg/analyzer/test/src/dart/constant/evaluation_test.dart b/pkg/analyzer/test/src/dart/constant/evaluation_test.dart
index 2be471d17a7f437fc8a6a329c9557773767ac698..f789be8340f91fa0dd0d56ebd0269f86db4e214c 100644
--- a/pkg/analyzer/test/src/dart/constant/evaluation_test.dart
+++ b/pkg/analyzer/test/src/dart/constant/evaluation_test.dart
@@ -1181,6 +1181,69 @@ const A a = const A();
expect(value.toSymbolValue(), "void");
}
+ test_getConstructor_withArgs() async {
+ CompilationUnit compilationUnit = await resolveSource(r'''
+class A {
+ final int i;
+ const A(this.i);
+}
+
+class C {
+ @A(5)
+ f() {}
+}
+''');
+ EvaluationResultImpl result =
+ _evaluateAnnotation(compilationUnit, "C", "f");
+ DartObjectImpl value = result.value;
+ expect(value.getConstructor(), isNotNull);
+ expect(value.getPositionalArguments(), hasLength(1));
+ expect(value.getPositionalArguments().single.toIntValue(), 5);
+ expect(value.getNamedArguments(), isEmpty);
+ }
+
+ test_getConstructor_withNamedArgs() async {
+ CompilationUnit compilationUnit = await resolveSource(r'''
+class A {
+ final int i;
+ const A({this.i});
+}
+
+class C {
+ @A(i: 5)
+ f() {}
+}
+''');
+ EvaluationResultImpl result =
+ _evaluateAnnotation(compilationUnit, "C", "f");
+ DartObjectImpl value = result.value;
+ expect(value.getConstructor(), isNotNull);
+ expect(value.getPositionalArguments(), isEmpty);
+ expect(value.getNamedArguments(), isNotEmpty);
+ expect(value.getNamedArguments()['i'].toIntValue(), 5);
+ }
+
+ test_getConstructor_redirectingFactory() async {
+ CompilationUnit compilationUnit = await resolveSource(r'''
+class A {
+ factory const A() = B;
+}
+
+class B implements A {
+ const B();
+}
+
+class C {
+ @A()
+ f() {}
+}
+''');
+ EvaluationResultImpl result =
+ _evaluateAnnotation(compilationUnit, "C", "f");
+ DartObjectImpl value = result.value;
+ expect(value.getConstructor().isFactory, isTrue);
+ }
+
Map<String, DartObjectImpl> _assertFieldType(
Map<String, DartObjectImpl> fields,
String fieldName,
« pkg/analyzer/pubspec.yaml ('K') | « pkg/analyzer/pubspec.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698