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

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

Issue 58183003: Implement VariableMirror.isConst in the VM and ParameterMirror.isConst in dart2js. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: git cl dcommit Created 7 years, 1 month 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
« no previous file with comments | « tests/lib/mirrors/parameter_is_const_test.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/lib/mirrors/variable_is_const_test.dart
diff --git a/tests/lib/mirrors/variable_is_const_test.dart b/tests/lib/mirrors/variable_is_const_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..fc90fae9aa03552853eede09cf6d82c9d8c9666d
--- /dev/null
+++ b/tests/lib/mirrors/variable_is_const_test.dart
@@ -0,0 +1,35 @@
+// Copyright (c) 2013, 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.variable_is_const;
+
+import 'dart:mirrors';
+
+import 'package:expect/expect.dart';
+
+class Class {
+ const /// 01: compile-time error
+ int instanceWouldBeConst = 1;
+ var instanceNonConst = 2;
+
+ static const staticConst = 3;
+ static var staticNonConst = 4;
+}
+
+const topLevelConst = 5;
+var topLevelNonConst = 6;
+
+main() {
+ bool isConst(m, Symbol s) => (m.declarations[s] as VariableMirror).isConst;
+
+ ClassMirror cm = reflectClass(Class);
+ Expect.isFalse(isConst(cm, #instanceWouldBeConst));
+ Expect.isFalse(isConst(cm, #instanceNonConst));
+ Expect.isTrue(isConst(cm, #staticConst));
+ Expect.isFalse(isConst(cm, #staticNonConst));
+
+ LibraryMirror lm = cm.owner;
+ Expect.isTrue(isConst(lm, #topLevelConst));
+ Expect.isFalse(isConst(lm, #topLevelNonConst));
+}
« no previous file with comments | « tests/lib/mirrors/parameter_is_const_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698