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

Unified Diff: test_reflectable/test/new_instance_test.dart

Issue 1181413005: Implement newInstance in the transformer. (Closed) Base URL: https://github.com/dart-lang/reflectable.git@master
Patch Set: Address review Created 5 years, 6 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 | « test_reflectable/test/new_instance_default_values_test.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test_reflectable/test/new_instance_test.dart
diff --git a/test_reflectable/test/new_instance_test.dart b/test_reflectable/test/new_instance_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..3bc80266a11eb4ae4dc7e9eb0d98ba5cc8e5256d
--- /dev/null
+++ b/test_reflectable/test/new_instance_test.dart
@@ -0,0 +1,59 @@
+// Copyright (c) 2015, the Dart Team. All rights reserved. Use of this
+// source code is governed by a BSD-style license that can be found in
+// the LICENSE file.
+
+// File being transformed by the reflectable transformer.
+// Uses `invoke`.
+
+library reflectable.test.to_be_transformed.new_instance_default_values_test;
+
+import 'package:reflectable/reflectable.dart';
+import 'package:unittest/unittest.dart';
+
+class MyReflectable extends Reflectable {
+ const MyReflectable() : super(newInstanceCapability);
+}
+
+const myReflectable = const MyReflectable();
+
+@myReflectable
+class A {
+ A() : f = 42;
+ A.positional(int x) : f = x - 42;
+ A.optional(int x, int y, [int z = 1, w])
+ : f = x + y + z * 42 + (w == null ? 10 : w);
+ A.argNamed(int x, int y, {int z: 42, int p})
+ : f = x + y - z - (p == null ? 10 : p);
+ int f = 0;
+}
+
+main() {
+ ClassMirror classMirror = myReflectable.reflectType(A);
+ test('newInstance unnamed constructor, no arguments', () {
+ expect((classMirror.newInstance("", []) as A).f, 42);
+ });
+ test('newInstance named constructor, simple argument list, one argument', () {
+ expect((classMirror.newInstance("positional", [84]) as A).f, 42);
+ });
+ test('newInstance optional arguments, all used', () {
+ expect((classMirror.newInstance("optional", [1, 2, 3, 4]) as A).f, 133);
+ });
+ test('newInstance optional arguments, none used', () {
+ expect((classMirror.newInstance("optional", [1, 2]) as A).f, 55);
+ });
+ test('newInstance optional arguments, some used', () {
+ expect((classMirror.newInstance("optional", [1, 2, 3]) as A).f, 139);
+ });
+ test('newInstance named arguments, all used', () {
+ expect((classMirror.newInstance("argNamed", [1, 2], {#z: 3, #p: 0}) as A).f,
+ 0);
+ });
+ test('newInstance named arguments, some used', () {
+ expect((classMirror.newInstance("argNamed", [1, 2], {#z: 3}) as A).f, -10);
+ expect((classMirror.newInstance("argNamed", [1, 2], {#p: 3}) as A).f, -42);
+ });
+ test('newInstance named arguments, unused', () {
+ expect((classMirror.newInstance("argNamed", [1, 2]) as A).f, -49);
+ expect((classMirror.newInstance("argNamed", [1, 2], {}) as A).f, -49);
+ });
+}
« no previous file with comments | « test_reflectable/test/new_instance_default_values_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698