Chromium Code Reviews| 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..33d7782b6bb5e5bc427525476561b9e771d35f41 |
| --- /dev/null |
| +++ b/tests/lib/mirrors/variable_is_const_test.dart |
| @@ -0,0 +1,36 @@ |
| +// 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 { |
| + // Illegal. |
| + // const instanceConst = 1; |
|
ahe
2013/11/11 10:23:07
For completeness, how about:
const /// 01: compil
rmacnak
2013/11/11 17:54:22
Done.
|
| + 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); |
| + // Illegal. |
| + // Expect.isTrue(isConst(cm, #instanceConst)); |
|
ahe
2013/11/11 10:23:07
If you make the above modification, update this to
|
| + 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)); |
| +} |