Chromium Code Reviews| Index: tests/lib_strong/mirrors/field_metadata2_test.dart |
| diff --git a/tests/lib_strong/mirrors/field_metadata2_test.dart b/tests/lib_strong/mirrors/field_metadata2_test.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d2b616f1130ad9f6e5f228e6822cafb2f517b7b8 |
| --- /dev/null |
| +++ b/tests/lib_strong/mirrors/field_metadata2_test.dart |
| @@ -0,0 +1,26 @@ |
| +// compile options: --emit-metadata |
| +// Copyright (c) 2017, 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. |
| + |
| +// Run essentially the same test, but with emit-metadata compile option, |
| +// which allows us to reflect on the fields. |
| +import 'dart:mirrors'; |
| +import 'package:expect/expect.dart'; |
| + |
| +import 'field_metadata_test.dart' as field_metadata_test; |
| +import 'field_metadata_test.dart' show Foo, Bar; |
| + |
| +void main() { |
| + // Make sure the other test still works. |
| + field_metadata_test.main(); |
| + |
| + // Check that we can now relfect on the annotations. |
|
vsm
2017/05/02 21:43:53
relfect -> reflect
Jennifer Messerly
2017/05/02 21:44:50
thanks! done :)
|
| + dynamic f = new Foo(); |
| + var members = reflect(f).type.declarations; |
| + var bar = members[#x].metadata.first.reflectee as Bar; |
| + Expect.equals(bar.name, 'bar'); |
| + |
| + var baz = members[#y].metadata.first.reflectee as Bar; |
| + Expect.equals(baz.name, 'baz'); |
| +} |