dart-sdk/tests/lib_2/mirrors/variable_is_const_test.dart
Jakob Roland Andersen ecd7e9cf81 Migrate test batch 233 to Dart 2.0
Bug:
Change-Id: I8f3c28b306acad1353e347ff8bd7009e49f74f6a
Reviewed-on: https://dart-review.googlesource.com/4400
Commit-Queue: Jakob Roland Andersen <jakobr@google.com>
Reviewed-by: Florian Loitsch <floitsch@google.com>
2017-09-11 10:46:03 +00:00

37 lines
1 KiB
Dart

// 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;
@MirrorsUsed(targets: "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));
}