| 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"); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 })); | 38 })); |
| 39 | 39 |
| 40 instMirror.setField('field', 44); | 40 instMirror.setField('field', 44); |
| 41 future = instMirror.getField('field'); | 41 future = instMirror.getField('field'); |
| 42 future.then(expectAsync1((resultMirror) { | 42 future.then(expectAsync1((resultMirror) { |
| 43 expect(resultMirror.reflectee, equals(44)); | 43 expect(resultMirror.reflectee, equals(44)); |
| 44 expect(instance.field, equals(44)); | 44 expect(instance.field, equals(44)); |
| 45 })); | 45 })); |
| 46 } | 46 } |
| 47 | 47 |
| 48 testClosureMirrors(mirrors) { |
| 49 var closure = (x, y, z) { return x + y + z; }; |
| 50 |
| 51 var mirror = mirrors.mirrorOf(closure); |
| 52 expect(mirror is ClosureMirror, equals(true)); |
| 53 |
| 54 var funcMirror = mirror.function(); |
| 55 expect(funcMirror is MethodMirror, equals(true)); |
| 56 expect(funcMirror.parameters().length, equals(3)); |
| 57 |
| 58 var future = mirror.apply([2, 4, 8]); |
| 59 future.then(expectAsync1((resultMirror) { |
| 60 expect(resultMirror.reflectee, equals(14)); |
| 61 })); |
| 62 } |
| 63 |
| 48 main() { | 64 main() { |
| 49 var mirrors = currentMirrorSystem(); | 65 var mirrors = currentMirrorSystem(); |
| 50 | 66 |
| 51 test("Test field access", () { testFieldAccess(mirrors); }); | 67 test("Test field access", () { testFieldAccess(mirrors); }); |
| 68 test("Test closure mirrors", () { testClosureMirrors(mirrors); }); |
| 52 } | 69 } |
| 53 | 70 |
| OLD | NEW |