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 import "dart:mirrors"; |
| 7 import "../../../pkg/unittest/lib/unittest.dart"; | 7 import "../../../pkg/unittest/lib/unittest.dart"; |
| 8 | 8 |
| 9 var topLevelField; | 9 var topLevelField; |
| 10 u(a, b, c) => {"a": a, "b": b, "c": c}; | 10 u(a, b, c) => {"a": a, "b": b, "c": c}; |
| 11 _v(a, b) => a + b; | 11 _v(a, b) => a + b; |
| 12 | 12 |
| 13 class Class<T> { | 13 class Class<T> { |
|
regis
2013/07/15 22:37:35
Is there any particular reason why Class has a typ
rmacnak
2013/07/16 00:03:21
Another test in this file inspects it reflectively
| |
| 14 Class() { this.field = "default value"; } | 14 Class() { this.field = "default value"; } |
| 15 Class.withInitialValue(this.field); | 15 Class.withInitialValue(this.field); |
| 16 var field; | 16 var field; |
| 17 | 17 |
| 18 Class.generative(this.field); | 18 Class.generative(this.field); |
| 19 Class.redirecting(y) : this.generative(y*2); | 19 Class.redirecting(y) : this.generative(y*2); |
| 20 factory Class.faktory(y) => "FakeClass $y"; | 20 factory Class.faktory(y) => new Class.withInitialValue(y*3); |
| 21 factory Class.redirectingFactory(y) = Class.faktory; | 21 factory Class.redirectingFactory(y) = Class.faktory; |
| 22 | 22 |
| 23 m(a, b, c) => {"a": a, "b": b, "c": c}; | 23 m(a, b, c) => {"a": a, "b": b, "c": c}; |
| 24 _n(a, b) => a + b; | 24 _n(a, b) => a + b; |
| 25 noSuchMethod(invocation) => "DNU"; | 25 noSuchMethod(invocation) => "DNU"; |
| 26 | 26 |
| 27 static var staticField; | 27 static var staticField; |
| 28 static s(a, b, c) => {"a": a, "b": b, "c": c}; | 28 static s(a, b, c) => {"a": a, "b": b, "c": c}; |
| 29 static _t(a, b) => a + b; | 29 static _t(a, b) => a + b; |
| 30 } | 30 } |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 183 | 183 |
| 184 instanceMirror = classMirror.newInstance(const Symbol('redirecting'), | 184 instanceMirror = classMirror.newInstance(const Symbol('redirecting'), |
| 185 [8]); | 185 [8]); |
| 186 expect(instanceMirror.reflectee is Class, equals(true)); | 186 expect(instanceMirror.reflectee is Class, equals(true)); |
| 187 expect(instanceMirror.reflectee.field, equals(16)); | 187 expect(instanceMirror.reflectee.field, equals(16)); |
| 188 | 188 |
| 189 | 189 |
| 190 if (!isDart2js) { | 190 if (!isDart2js) { |
| 191 instanceMirror = classMirror.newInstance(const Symbol('faktory'), | 191 instanceMirror = classMirror.newInstance(const Symbol('faktory'), |
| 192 [9]); | 192 [9]); |
| 193 expect(instanceMirror.reflectee, equals('FakeClass 9')); | 193 expect(instanceMirror.reflectee is Class, equals(true)); |
| 194 expect(instanceMirror.reflectee.field, equals(27)); | |
| 195 | |
| 194 | 196 |
| 195 instanceMirror = classMirror.newInstance(const Symbol('redirectingFactory'), | 197 instanceMirror = classMirror.newInstance(const Symbol('redirectingFactory'), |
| 196 [10]); | 198 [10]); |
| 197 expect(instanceMirror.reflectee, equals('FakeClass 10')); | 199 expect(instanceMirror.reflectee is Class, equals(true)); |
| 200 expect(instanceMirror.reflectee.field, equals(30)); | |
| 198 } | 201 } |
| 199 | 202 |
| 200 | 203 |
| 201 var future = classMirror.newInstanceAsync(const Symbol(''), []); | 204 var future = classMirror.newInstanceAsync(const Symbol(''), []); |
| 202 future.then(expectAsync1((resultMirror) { | 205 future.then(expectAsync1((resultMirror) { |
| 203 var instance = resultMirror.reflectee; | 206 var instance = resultMirror.reflectee; |
| 204 expect(instance is Class, equals(true)); | 207 expect(instance is Class, equals(true)); |
| 205 expect(instance.field, equals("default value")); | 208 expect(instance.field, equals("default value")); |
| 206 })); | 209 })); |
| 207 | 210 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 284 }); | 287 }); |
| 285 if (!isMinified) // TODO(ahe): Remove this line. | 288 if (!isMinified) // TODO(ahe): Remove this line. |
| 286 test("Test simple and qualifiedName", () { testNames(mirrors, isDart2js); }); | 289 test("Test simple and qualifiedName", () { testNames(mirrors, isDart2js); }); |
| 287 if (isDart2js) return; // TODO(ahe): Remove this line. | 290 if (isDart2js) return; // TODO(ahe): Remove this line. |
| 288 test("Test reflect type", () { testReflectClass(mirrors); }); | 291 test("Test reflect type", () { testReflectClass(mirrors); }); |
| 289 } | 292 } |
| 290 | 293 |
| 291 main() { | 294 main() { |
| 292 mainWithArgument(); | 295 mainWithArgument(); |
| 293 } | 296 } |
| OLD | NEW |