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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2015, the Dart Team. All rights reserved. Use of this
2 // source code is governed by a BSD-style license that can be found in
3 // the LICENSE file.
4
5 // File being transformed by the reflectable transformer.
6 // Uses `invoke`.
7
8 library reflectable.test.to_be_transformed.new_instance_default_values_test;
9
10 import 'package:reflectable/reflectable.dart';
11 import 'package:unittest/unittest.dart';
12
13 class MyReflectable extends Reflectable {
14 const MyReflectable() : super(newInstanceCapability);
15 }
16
17 const myReflectable = const MyReflectable();
18
19 @myReflectable
20 class A {
21 A() : f = 42;
22 A.positional(int x) : f = x - 42;
23 A.optional(int x, int y, [int z = 1, w])
24 : f = x + y + z * 42 + (w == null ? 10 : w);
25 A.argNamed(int x, int y, {int z: 42, int p})
26 : f = x + y - z - (p == null ? 10 : p);
27 int f = 0;
28 }
29
30 main() {
31 ClassMirror classMirror = myReflectable.reflectType(A);
32 test('newInstance unnamed constructor, no arguments', () {
33 expect((classMirror.newInstance("", []) as A).f, 42);
34 });
35 test('newInstance named constructor, simple argument list, one argument', () {
36 expect((classMirror.newInstance("positional", [84]) as A).f, 42);
37 });
38 test('newInstance optional arguments, all used', () {
39 expect((classMirror.newInstance("optional", [1, 2, 3, 4]) as A).f, 133);
40 });
41 test('newInstance optional arguments, none used', () {
42 expect((classMirror.newInstance("optional", [1, 2]) as A).f, 55);
43 });
44 test('newInstance optional arguments, some used', () {
45 expect((classMirror.newInstance("optional", [1, 2, 3]) as A).f, 139);
46 });
47 test('newInstance named arguments, all used', () {
48 expect((classMirror.newInstance("argNamed", [1, 2], {#z: 3, #p: 0}) as A).f,
49 0);
50 });
51 test('newInstance named arguments, some used', () {
52 expect((classMirror.newInstance("argNamed", [1, 2], {#z: 3}) as A).f, -10);
53 expect((classMirror.newInstance("argNamed", [1, 2], {#p: 3}) as A).f, -42);
54 });
55 test('newInstance named arguments, unused', () {
56 expect((classMirror.newInstance("argNamed", [1, 2]) as A).f, -49);
57 expect((classMirror.newInstance("argNamed", [1, 2], {}) as A).f, -49);
58 });
59 }
OLDNEW
« 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