Files
sdk/tests/lib/mirrors/private_field_test.dart
T
Ryan Macnak 00b2e580a3 [test] Fork mirrors tests.
Bug: https://github.com/dart-lang/sdk/issues/40045
Change-Id: I597259b38684de87016f1e136723d24f4ac05420
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132440
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2020-01-22 18:46:23 +00:00

37 lines
927 B
Dart

// Copyright (c) 2016, 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.mixin;
import 'dart:mirrors';
import 'package:expect/expect.dart';
import 'private_field_helper.dart';
class Foo extends Bar {
int _field = 42;
static int _staticField = 99;
}
var privateSymbol = #_field;
var publicSymbol = #field;
main() {
Expect.equals(publicSymbol, publicSymbol2);
Expect.notEquals(privateSymbol, privateSymbol2);
var foo = new Foo();
var m = reflect(foo);
m.setField(privateSymbol, 38);
Expect.equals(38, foo._field);
m.setField(privateSymbol2, "world");
Expect.equals("world", foo.field);
Expect.equals("world", m.getField(publicSymbol).reflectee);
var type = reflectClass(Foo);
Expect.equals(99, type.getField(#_staticField).reflectee);
}