| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2015, 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.enums; | |
| 6 | |
| 7 @MirrorsUsed(targets: "test.enums") | |
| 8 import 'dart:mirrors'; | |
| 9 import 'package:expect/expect.dart'; | |
| 10 import 'stringify.dart'; | |
| 11 | |
| 12 class C {} | |
| 13 | |
| 14 enum Suite { CLUBS, DIAMONDS, SPADES, HEARTS } | |
| 15 | |
| 16 main() { | |
| 17 Expect.isFalse(reflectClass(C).isEnum); | |
| 18 | |
| 19 Expect.isTrue(reflectClass(Suite).isEnum); | |
| 20 Expect.isFalse(reflectClass(Suite).isAbstract); | |
| 21 Expect.equals( | |
| 22 0, | |
| 23 reflectClass(Suite) | |
| 24 .declarations | |
| 25 .values | |
| 26 .where((d) => d is MethodMirror && d.isConstructor) | |
| 27 .length); | |
| 28 | |
| 29 Expect.equals( | |
| 30 reflectClass(Suite), | |
| 31 (reflectClass(C).owner as LibraryMirror).declarations[#Suite], | |
| 32 "found in library"); | |
| 33 | |
| 34 Expect.equals(reflectClass(Suite), reflect(Suite.CLUBS).type); | |
| 35 | |
| 36 Expect.equals(0, reflect(Suite.CLUBS).getField(#index).reflectee); | |
| 37 Expect.equals(1, reflect(Suite.DIAMONDS).getField(#index).reflectee); | |
| 38 Expect.equals(2, reflect(Suite.SPADES).getField(#index).reflectee); | |
| 39 Expect.equals(3, reflect(Suite.HEARTS).getField(#index).reflectee); | |
| 40 | |
| 41 Expect.equals( | |
| 42 "Suite.CLUBS", reflect(Suite.CLUBS).invoke(#toString, []).reflectee); | |
| 43 Expect.equals("Suite.DIAMONDS", | |
| 44 reflect(Suite.DIAMONDS).invoke(#toString, []).reflectee); | |
| 45 Expect.equals( | |
| 46 "Suite.SPADES", reflect(Suite.SPADES).invoke(#toString, []).reflectee); | |
| 47 Expect.equals( | |
| 48 "Suite.HEARTS", reflect(Suite.HEARTS).invoke(#toString, []).reflectee); | |
| 49 | |
| 50 Expect.setEquals( | |
| 51 [ | |
| 52 'Variable(s(index) in s(Suite), final)', | |
| 53 'Variable(s(CLUBS) in s(Suite), static, final)', | |
| 54 'Variable(s(DIAMONDS) in s(Suite), static, final)', | |
| 55 'Variable(s(SPADES) in s(Suite), static, final)', | |
| 56 'Variable(s(HEARTS) in s(Suite), static, final)', | |
| 57 'Variable(s(values) in s(Suite), static, final)', | |
| 58 'Method(s(hashCode) in s(Suite), getter)', | |
| 59 'Method(s(toString) in s(Suite))' | |
| 60 ], | |
| 61 reflectClass(Suite) | |
| 62 .declarations | |
| 63 .values | |
| 64 .where((d) => !d.isPrivate) | |
| 65 .map(stringify)); | |
| 66 } | |
| OLD | NEW |