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

Side by Side Diff: test/codegen/lib/mirrors/hot_get_field_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) 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.hot_get_field;
6
7 import 'dart:mirrors';
8 import 'package:expect/expect.dart';
9
10 class C {
11 var field;
12 var _field;
13 operator +(other) => field + other;
14 }
15
16 const int optimizationThreshold = 20;
17
18 testPublic() {
19 var c = new C();
20 var im = reflect(c);
21
22 for (int i = 0; i < (2 * optimizationThreshold); i++) {
23 c.field = i;
24 Expect.equals(i, im.getField(#field).reflectee);
25 }
26 }
27
28 testPrivate() {
29 var c = new C();
30 var im = reflect(c);
31
32 for (int i = 0; i < (2 * optimizationThreshold); i++) {
33 c._field = i;
34 Expect.equals(i, im.getField(#_field).reflectee);
35 }
36 }
37
38 testPrivateWrongLibrary() {
39 var c = new C();
40 var im = reflect(c);
41 var selector = MirrorSystem.getSymbol('_field', reflectClass(Mirror).owner);
42
43 for (int i = 0; i < (2 * optimizationThreshold); i++) {
44 Expect.throws(() => im.getField(selector), (e) => e is NoSuchMethodError);
45 }
46 }
47
48 testOperator() {
49 var plus = const Symbol("+");
50 var c = new C();
51 var im = reflect(c);
52
53 for (int i = 0; i < (2 * optimizationThreshold); i++) {
54 c.field = i;
55 var closurizedPlus = im.getField(plus).reflectee;
56 Expect.isTrue(closurizedPlus is Function);
57 Expect.equals(2 * i, closurizedPlus(i));
58 }
59 }
60
61 main() {
62 testPublic();
63 testPrivate();
64 testPrivateWrongLibrary();
65 testOperator();
66 }
OLDNEW
« no previous file with comments | « test/codegen/lib/mirrors/hierarchy_invariants_test.dart ('k') | test/codegen/lib/mirrors/hot_set_field_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698