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

Side by Side Diff: test/codegen/lib/mirrors/invoke_call_through_getter_test.dart

Issue 2265533002: Add mirrors tests (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Created 4 years, 4 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
OLDNEW
(Empty)
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 library test.invoke_call_through_getter;
6
7 import 'dart:mirrors';
8
9 import 'package:expect/expect.dart';
10
11 class FakeFunctionCall {
12 call(x, y) => '1 $x $y';
13 }
14 class FakeFunctionNSM {
15 noSuchMethod(msg) => msg.positionalArguments.join(', ');
16 }
17
18 class C {
19 get fakeFunctionCall => new FakeFunctionCall();
20 get fakeFunctionNSM => new FakeFunctionNSM();
21 get closure => (x, y) => '2 $this $x $y';
22 get closureOpt => (x, y, [z, w]) => '3 $this $x $y $z $w';
23 get closureNamed => (x, y, {z, w}) => '4 $this $x $y $z $w';
24 get notAClosure => 'Not a closure';
25 noSuchMethod(msg) => 'DNU';
26
27 toString() => 'C';
28 }
29
30 testInstanceBase() {
31 var c = new C();
32
33 Expect.equals('1 5 6', c.fakeFunctionCall(5, 6));
34 Expect.equals('7, 8', c.fakeFunctionNSM(7, 8));
35 Expect.equals('2 C 9 10', c.closure(9, 10));
36 Expect.equals('3 C 11 12 13 null', c.closureOpt(11, 12, 13));
37 Expect.equals('4 C 14 15 null 16', c.closureNamed(14, 15, w: 16));
38 Expect.equals('DNU', c.doesNotExist(17, 18));
39 Expect.throws(() => c.closure('wrong arity'), (e) => e is NoSuchMethodError);
40 Expect.throws(() => c.notAClosure(), (e) => e is NoSuchMethodError);
41 }
42
43 testInstanceReflective() {
44 InstanceMirror im = reflect(new C());
45
46 Expect.equals('1 5 6',
47 im.invoke(#fakeFunctionCall, [5, 6]).reflectee);
48 Expect.equals('7, 8',
49 im.invoke(#fakeFunctionNSM, [7, 8]).reflectee);
50 Expect.equals('2 C 9 10',
51 im.invoke(#closure, [9, 10]).reflectee);
52 Expect.equals('3 C 11 12 13 null',
53 im.invoke(#closureOpt, [11, 12, 13]).reflectee);
54 Expect.equals('4 C 14 15 null 16', /// named: ok
55 im.invoke(#closureNamed, [14, 15], {#w: 16}).reflectee); /// named: continued
56 Expect.equals('DNU',
57 im.invoke(#doesNotExist, [17, 18]).reflectee);
58 Expect.throws(() => im.invoke(#closure, ['wrong arity']),
59 (e) => e is NoSuchMethodError);
60 Expect.throws(() => im.invoke(#notAClosure, []),
61 (e) => e is NoSuchMethodError);
62 }
63
64 class D {
65 static get fakeFunctionCall => new FakeFunctionCall();
66 static get fakeFunctionNSM => new FakeFunctionNSM();
67 static get closure => (x, y) => '2 $x $y';
68 static get closureOpt => (x, y, [z, w]) => '3 $x $y $z $w';
69 static get closureNamed => (x, y, {z, w}) => '4 $x $y $z $w';
70 static get notAClosure => 'Not a closure';
71 }
72
73 testClassBase() {
74 Expect.equals('1 5 6', D.fakeFunctionCall(5, 6));
75 Expect.equals('7, 8', D.fakeFunctionNSM(7, 8));
76 Expect.equals('2 9 10', D.closure(9, 10));
77 Expect.equals('3 11 12 13 null', D.closureOpt(11, 12, 13));
78 Expect.equals('4 14 15 null 16', D.closureNamed(14, 15, w: 16));
79 Expect.throws(() => D.closure('wrong arity'), (e) => e is NoSuchMethodError);
80 }
81
82 testClassReflective() {
83 ClassMirror cm = reflectClass(D);
84
85 Expect.equals('1 5 6',
86 cm.invoke(#fakeFunctionCall, [5, 6]).reflectee);
87 Expect.equals('7, 8',
88 cm.invoke(#fakeFunctionNSM, [7, 8]).reflectee);
89 Expect.equals('2 9 10',
90 cm.invoke(#closure, [9, 10]).reflectee);
91 Expect.equals('3 11 12 13 null',
92 cm.invoke(#closureOpt, [11, 12, 13]).reflectee);
93 Expect.equals('4 14 15 null 16', /// n amed: continued
94 cm.invoke(#closureNamed, [14, 15], {#w: 16}).reflectee); /// n amed: continued
95 Expect.throws(() => cm.invoke(#closure, ['wrong arity']),
96 (e) => e is NoSuchMethodError);
97 }
98
99 get fakeFunctionCall => new FakeFunctionCall();
100 get fakeFunctionNSM => new FakeFunctionNSM();
101 get closure => (x, y) => '2 $x $y';
102 get closureOpt => (x, y, [z, w]) => '3 $x $y $z $w';
103 get closureNamed => (x, y, {z, w}) => '4 $x $y $z $w';
104 get notAClosure => 'Not a closure';
105
106 testLibraryBase() {
107 Expect.equals('1 5 6', fakeFunctionCall(5, 6));
108 Expect.equals('7, 8', fakeFunctionNSM(7, 8));
109 Expect.equals('2 9 10', closure(9, 10));
110 Expect.equals('3 11 12 13 null', closureOpt(11, 12, 13));
111 Expect.equals('4 14 15 null 16', closureNamed(14, 15, w: 16));
112 Expect.throws(() => closure('wrong arity'), (e) => e is NoSuchMethodError);
113 }
114
115 testLibraryReflective() {
116 LibraryMirror lm = reflectClass(D).owner;
117
118 Expect.equals('1 5 6',
119 lm.invoke(#fakeFunctionCall, [5, 6]).reflectee);
120 Expect.equals('7, 8',
121 lm.invoke(#fakeFunctionNSM, [7, 8]).reflectee);
122 Expect.equals('2 9 10',
123 lm.invoke(#closure, [9, 10]).reflectee);
124 Expect.equals('3 11 12 13 null',
125 lm.invoke(#closureOpt, [11, 12, 13]).reflectee);
126 Expect.equals('4 14 15 null 16', /// na med: continued
127 lm.invoke(#closureNamed, [14, 15], {#w: 16}).reflectee); /// na med: continued
128 Expect.throws(() => lm.invoke(#closure, ['wrong arity']),
129 (e) => e is NoSuchMethodError);
130 }
131
132 main() {
133 // Do not access the getters/closures at the base level in this variant.
134 //testInstanceBase();
135 testInstanceReflective();
136 //testClassBase();
137 testClassReflective();
138 //testLibraryBase();
139 testLibraryReflective();
140 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698