Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(681)

Unified Diff: tests/lib/mirrors/enum_test.dart

Issue 938513002: Add ClassMirror.isEnum. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« runtime/lib/mirrors.cc ('K') | « tests/lib/lib.status ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/lib/mirrors/enum_test.dart
diff --git a/tests/lib/mirrors/enum_test.dart b/tests/lib/mirrors/enum_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..7b265a0204f604c737157283edd987256fb8263e
--- /dev/null
+++ b/tests/lib/mirrors/enum_test.dart
@@ -0,0 +1,52 @@
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library test.enums;
+
+import 'dart:mirrors';
+import 'package:expect/expect.dart';
+import 'stringify.dart';
+
+class C {}
+enum Suite { CLUBS, DIAMONDS, SPADES, HEARTS }
+
+main() {
+ Expect.isFalse(reflectClass(C).isEnum);
+
+ Expect.isTrue(reflectClass(Suite).isEnum);
+ Expect.isFalse(reflectClass(Suite).isAbstract);
+ Expect.equals(0, reflectClass(Suite).declarations.values.where(
+ (d) => d is MethodMirror && d.isConstructor).length);
+
+ Expect.equals(reflectClass(Suite),
+ (reflectClass(C).owner as LibraryMirror).declarations[#Suite],
+ "found in library");
+
+ Expect.equals(reflectClass(Suite), reflect(Suite.CLUBS).type);
+
+ Expect.equals(0, reflect(Suite.CLUBS).getField(#index).reflectee);
+ Expect.equals(1, reflect(Suite.DIAMONDS).getField(#index).reflectee);
+ Expect.equals(2, reflect(Suite.SPADES).getField(#index).reflectee);
+ Expect.equals(3, reflect(Suite.HEARTS).getField(#index).reflectee);
+
+ Expect.equals("Suite.CLUBS",
+ reflect(Suite.CLUBS).invoke(#toString, []).reflectee);
+ Expect.equals("Suite.DIAMONDS",
+ reflect(Suite.DIAMONDS).invoke(#toString, []).reflectee);
+ Expect.equals("Suite.SPADES",
+ reflect(Suite.SPADES).invoke(#toString, []).reflectee);
+ Expect.equals("Suite.HEARTS",
+ reflect(Suite.HEARTS).invoke(#toString, []).reflectee);
+
+ Expect.setEquals(
+ ['Variable(s(index) in s(Suite), final)',
+ 'Variable(s(CLUBS) in s(Suite), static, final)',
+ 'Variable(s(DIAMONDS) in s(Suite), static, final)',
+ 'Variable(s(SPADES) in s(Suite), static, final)',
+ 'Variable(s(HEARTS) in s(Suite), static, final)',
+ 'Variable(s(values) in s(Suite), static, final)',
+ 'Method(s(toString) in s(Suite))'],
+ reflectClass(Suite).declarations.values
+ .where((d) => !d.isPrivate).map(stringify));
+}
« runtime/lib/mirrors.cc ('K') | « tests/lib/lib.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698