Chromium Code Reviews| 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 library MirrorsTest; | 5 library MirrorsTest; |
| 6 import "dart:mirrors"; | 6 |
| 7 import "../../../pkg/unittest/lib/unittest.dart"; | 7 import 'dart:mirrors'; |
| 8 | |
| 9 import '../../light_unittest.dart'; | |
|
ahe
2013/07/21 15:43:20
pkg/unittest has started using mirrors. That make
| |
| 8 | 10 |
| 9 bool isDart2js = false; // TODO(ahe): Remove this field. | 11 bool isDart2js = false; // TODO(ahe): Remove this field. |
| 10 bool isMinified = false; // TODO(ahe): Remove this field. | |
| 11 | 12 |
| 12 var topLevelField; | 13 var topLevelField; |
| 13 u(a, b, c) => {"a": a, "b": b, "c": c}; | 14 u(a, b, c) => {"a": a, "b": b, "c": c}; |
| 14 _v(a, b) => a + b; | 15 _v(a, b) => a + b; |
| 15 | 16 |
| 16 class Class<T> { | 17 class Class<T> { |
| 17 Class() { this.field = "default value"; } | 18 Class() { this.field = "default value"; } |
| 18 Class.withInitialValue(this.field); | 19 Class.withInitialValue(this.field); |
| 19 var field; | 20 var field; |
| 20 | 21 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 | 115 |
| 115 var libMirror = mirrors.findLibrary(const Symbol("MirrorsTest")).single; | 116 var libMirror = mirrors.findLibrary(const Symbol("MirrorsTest")).single; |
| 116 var classMirror = libMirror.classes[const Symbol("Class")]; | 117 var classMirror = libMirror.classes[const Symbol("Class")]; |
| 117 var instMirror = reflect(instance); | 118 var instMirror = reflect(instance); |
| 118 var fieldMirror = classMirror.members[const Symbol('field')]; | 119 var fieldMirror = classMirror.members[const Symbol('field')]; |
| 119 var future; | 120 var future; |
| 120 | 121 |
| 121 expect(fieldMirror is VariableMirror, isTrue); | 122 expect(fieldMirror is VariableMirror, isTrue); |
| 122 expect(fieldMirror.type, equals(mirrors.dynamicType)); | 123 expect(fieldMirror.type, equals(mirrors.dynamicType)); |
| 123 | 124 |
| 124 if (!isMinified) { | 125 libMirror.setField(const Symbol('topLevelField'), [91]); |
| 125 libMirror.setField(const Symbol('topLevelField'), [91]); | 126 expect(libMirror.getField(const Symbol('topLevelField')).reflectee, |
| 126 expect(libMirror.getField(const Symbol('topLevelField')).reflectee, | 127 equals([91])); |
| 127 equals([91])); | 128 expect(topLevelField, equals([91])); |
| 128 expect(topLevelField, equals([91])); | |
| 129 | 129 |
| 130 libMirror.setFieldAsync(const Symbol('topLevelField'), 42); | 130 libMirror.setFieldAsync(const Symbol('topLevelField'), 42); |
| 131 future = libMirror.getFieldAsync(const Symbol('topLevelField')); | 131 future = libMirror.getFieldAsync(const Symbol('topLevelField')); |
| 132 future.then(expectAsync1((resultMirror) { | 132 future.then(expectAsync1((resultMirror) { |
| 133 expect(resultMirror.reflectee, equals(42)); | 133 expect(resultMirror.reflectee, equals(42)); |
| 134 expect(topLevelField, equals(42)); | 134 expect(topLevelField, equals(42)); |
| 135 })); | 135 })); |
| 136 } | |
| 137 | 136 |
| 138 classMirror.setFieldAsync(const Symbol('staticField'), 43); | 137 classMirror.setFieldAsync(const Symbol('staticField'), 43); |
| 139 future = classMirror.getFieldAsync(const Symbol('staticField')); | 138 future = classMirror.getFieldAsync(const Symbol('staticField')); |
| 140 future.then(expectAsync1((resultMirror) { | 139 future.then(expectAsync1((resultMirror) { |
| 141 expect(resultMirror.reflectee, equals(43)); | 140 expect(resultMirror.reflectee, equals(43)); |
| 142 expect(Class.staticField, equals(43)); | 141 expect(Class.staticField, equals(43)); |
| 143 })); | 142 })); |
| 144 | 143 |
| 145 instMirror.setFieldAsync(const Symbol('field'), 44); | 144 instMirror.setFieldAsync(const Symbol('field'), 44); |
| 146 future = instMirror.getFieldAsync(const Symbol('field')); | 145 future = instMirror.getFieldAsync(const Symbol('field')); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 288 test("Test current library uri", () { | 287 test("Test current library uri", () { |
| 289 testLibraryUri(new Class(), | 288 testLibraryUri(new Class(), |
| 290 (Uri uri) => uri.path.endsWith('/mirrors_test.dart')); | 289 (Uri uri) => uri.path.endsWith('/mirrors_test.dart')); |
| 291 }); | 290 }); |
| 292 test("Test dart library uri", () { | 291 test("Test dart library uri", () { |
| 293 testLibraryUri("test", (Uri uri) => uri == Uri.parse('dart:core')); | 292 testLibraryUri("test", (Uri uri) => uri == Uri.parse('dart:core')); |
| 294 }); | 293 }); |
| 295 test("Test simple and qualifiedName", () { testNames(mirrors); }); | 294 test("Test simple and qualifiedName", () { testNames(mirrors); }); |
| 296 test("Test reflect type", () { testReflectClass(mirrors); }); | 295 test("Test reflect type", () { testReflectClass(mirrors); }); |
| 297 } | 296 } |
| OLD | NEW |