| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 // TODO(rmacnak): Move the existing mirror tests here (a place for | 5 // TODO(rmacnak): Move the existing mirror tests here (a place for |
| 6 // cross-implementation tests). | 6 // cross-implementation tests). |
| 7 | 7 |
| 8 #library("MirrorsTest.dart"); | 8 #library("MirrorsTest.dart"); |
| 9 #import("dart:mirrors"); | 9 #import("dart:mirrors"); |
| 10 #import("../../../lib/unittest/unittest.dart"); | 10 #import("../../../lib/unittest/unittest.dart"); |
| 11 | 11 |
| 12 var topLevelField; | 12 var topLevelField; |
| 13 | 13 |
| 14 class Class { | 14 class Class { |
| 15 var field; | 15 var field; |
| 16 static var staticField; | 16 static var staticField; |
| 17 } | 17 } |
| 18 | 18 |
| 19 testFieldAccess(mirrors) { | 19 testFieldAccess(mirrors) { |
| 20 var instance = new Class(); | 20 var instance = new Class(); |
| 21 | 21 |
| 22 var libMirror = mirrors.rootLibrary; | 22 var libMirror = mirrors.libraries()["MirrorsTest.dart"]; |
| 23 var classMirror = libMirror.classes()["Class"]; | 23 var classMirror = libMirror.classes()["Class"]; |
| 24 var instMirror = mirrors.mirrorOf(instance); | 24 var instMirror = mirrors.mirrorOf(instance); |
| 25 | 25 |
| 26 libMirror.setField('topLevelField', 42); | 26 libMirror.setField('topLevelField', 42); |
| 27 var future = libMirror.getField('topLevelField'); | 27 var future = libMirror.getField('topLevelField'); |
| 28 future.then(expectAsync1((resultMirror) { | 28 future.then(expectAsync1((resultMirror) { |
| 29 expect(resultMirror.reflectee, equals(42)); | 29 expect(resultMirror.reflectee, equals(42)); |
| 30 expect(topLevelField, equals(42)); | 30 expect(topLevelField, equals(42)); |
| 31 })); | 31 })); |
| 32 | 32 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 44 expect(instance.field, equals(44)); | 44 expect(instance.field, equals(44)); |
| 45 })); | 45 })); |
| 46 } | 46 } |
| 47 | 47 |
| 48 main() { | 48 main() { |
| 49 var mirrors = currentMirrorSystem(); | 49 var mirrors = currentMirrorSystem(); |
| 50 | 50 |
| 51 test("Test field access", () { testFieldAccess(mirrors); }); | 51 test("Test field access", () { testFieldAccess(mirrors); }); |
| 52 } | 52 } |
| 53 | 53 |
| OLD | NEW |