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

Side by Side Diff: tests/lib/mirrors/invoke_closurization2_test.dart

Issue 217963002: Allow getField of methods. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address typo-comment. Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « tests/lib/lib.status ('k') | tests/lib/mirrors/invoke_closurization_test.dart » ('j') | 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) 2014, 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_closurization_test;
6
7 import 'dart:mirrors';
8
9 import 'package:expect/expect.dart';
10
11 class A {
12 foo() => "foo";
13 bar([x]) => "bar-$x";
14 gee({named}) => "gee-$named";
15
16 // Methods that must be intercepted.
17
18 // Tear-offs we will also get without mirrors.
19 codeUnitAt(x) => "codeUnitAt-$x";
20 toUpperCase() => "toUpperCase";
21 // indexOf takes an optional argument in String.
22 indexOf(x) => "indexOf-$x";
23 // lastIndexOf matches signature from String.
24 lastIndexOf(x, [y]) => "lastIndexOf-$x,$y";
25 // splitMapJoin matches signature from String.
26 splitMapJoin(x, {onMatch, onNonMatch}) =>
27 "splitMapJoin-$x,$onMatch,$onNonMatch";
28 // Same name as intercepted, but with named argument.
29 trim({named}) => "trim-$named";
30
31 // Tear-offs we will not call directly.
32 endsWith(x) => "endsWith-$x";
33 toLowerCase() => "toLowerCase";
34 // matchAsPrefix matches signature from String.
35 matchAsPrefix(x, [y = 0]) => "matchAsPrefix-$x,$y";
36 // Matches signature from List
37 toList({growable: true}) => "toList-$growable";
38 // Same name as intercepted, but with named argument.
39 toSet({named}) => "toSet-$named";
40 }
41
42 // The recursive call makes inlining difficult.
43 // The use of DateTime.now makes the result unpredictable.
44 confuse(x) {
45 if (new DateTime.now().millisecondsSinceEpoch == 42) {
46 return confuse(new DateTime.now().millisecondsSinceEpoch);
47 }
48 return x;
49 }
50
51 main() {
52 var list = ["foo", new List(), new A()];
53
54 getAMirror() => reflect(list[confuse(2)]);
55
56 // Tear-off without mirrors.
57 var f = confuse(getAMirror().reflectee.codeUnitAt);
58 Expect.equals("codeUnitAt-42", f(42));
59 f = confuse(getAMirror().reflectee.toUpperCase);
60 Expect.equals("toUpperCase", f());
61 f = confuse(getAMirror().reflectee.indexOf);
62 Expect.equals("indexOf-499", f(499));
63 f = confuse(getAMirror().reflectee.lastIndexOf);
64 Expect.equals("lastIndexOf-FOO,BAR", f("FOO", "BAR"));
65 f = confuse(getAMirror().reflectee.splitMapJoin);
66 Expect.equals("splitMapJoin-1,2,3", f(1, onMatch: 2, onNonMatch: 3));
67 f = confuse(getAMirror().reflectee.trim);
68 Expect.equals("trim-true", f(named: true));
69
70 // Now the same thing through mirrors.
71 f = getAMirror().getField(#codeUnitAt).reflectee;
72 Expect.equals("codeUnitAt-42", f(42));
73 f = getAMirror().getField(#toUpperCase).reflectee;
74 Expect.equals("toUpperCase", f());
75 f = getAMirror().getField(#indexOf).reflectee;
76 Expect.equals("indexOf-499", f(499));
77 f = getAMirror().getField(#lastIndexOf).reflectee;
78 Expect.equals("lastIndexOf-FOO,BAR", f("FOO", "BAR"));
79 f = getAMirror().getField(#splitMapJoin).reflectee;
80 Expect.equals("splitMapJoin-1,2,3", f(1, onMatch: 2, onNonMatch: 3));
81 f = getAMirror().getField(#trim).reflectee;
82 Expect.equals("trim-true", f(named: true));
83
84 // Now the same thing through mirrors and mirror-invocation.
85 f = getAMirror().getField(#codeUnitAt);
86 Expect.equals("codeUnitAt-42", f.invoke(#call, [42], {}).reflectee);
87 f = getAMirror().getField(#toUpperCase);
88 Expect.equals("toUpperCase", f.invoke(#call, [], {}).reflectee);
89 f = getAMirror().getField(#indexOf);
90 Expect.equals("indexOf-499", f.invoke(#call, [499], {}).reflectee);
91 f = getAMirror().getField(#lastIndexOf);
92 Expect.equals("lastIndexOf-FOO,BAR",
93 f.invoke(#call, ["FOO", "BAR"]).reflectee);
94 f = getAMirror().getField(#splitMapJoin);
95 Expect.equals("splitMapJoin-1,2,3",
96 f.invoke(#call, [1], {#onMatch: 2, #onNonMatch: 3}).reflectee);
97 f = getAMirror().getField(#trim);
98 Expect.equals("trim-true", f.invoke(#call, [], {#named: true}).reflectee);
99
100 // Tear-offs only through mirrors. (No direct selector in the code).
101 // --------
102
103 f = getAMirror().getField(#endsWith).reflectee;
104 Expect.equals("endsWith-42", f(42));
105 f = getAMirror().getField(#toLowerCase).reflectee;
106 Expect.equals("toLowerCase", f());
107 f = getAMirror().getField(#indexOf).reflectee;
108 Expect.equals("indexOf-499", f(499));
109 f = getAMirror().getField(#matchAsPrefix).reflectee;
110 Expect.equals("matchAsPrefix-FOO,BAR", f("FOO", "BAR"));
111 f = getAMirror().getField(#toList).reflectee;
112 Expect.equals("toList-1", f(growable: 1));
113 f = getAMirror().getField(#toSet).reflectee;
114 Expect.equals("toSet-true", f(named: true));
115
116 f = getAMirror().getField(#endsWith);
117 Expect.equals("endsWith-42", f.invoke(#call, [42], {}).reflectee);
118 f = getAMirror().getField(#toLowerCase);
119 Expect.equals("toLowerCase", f.invoke(#call, [], {}).reflectee);
120 f = getAMirror().getField(#indexOf);
121 Expect.equals("indexOf-499", f.invoke(#call, [499], {}).reflectee);
122 f = getAMirror().getField(#matchAsPrefix);
123 Expect.equals("matchAsPrefix-FOO,BAR",
124 f.invoke(#call, ["FOO", "BAR"]).reflectee);
125 f = getAMirror().getField(#toList);
126 Expect.equals("toList-1",
127 f.invoke(#call, [], {#growable: 1}).reflectee);
128 f = getAMirror().getField(#toSet);
129 Expect.equals("toSet-true", f.invoke(#call, [], {#named: true}).reflectee);
130 }
OLDNEW
« no previous file with comments | « tests/lib/lib.status ('k') | tests/lib/mirrors/invoke_closurization_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698