| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 @string @symbol | 5 @string @symbol |
| 6 library test.library_metadata_test; | 6 library test.library_metadata_test; |
| 7 | 7 |
| 8 import 'dart:mirrors'; | 8 import 'dart:mirrors'; |
| 9 | 9 |
| 10 const string = 'a metadata string'; | 10 import 'metadata_test.dart'; |
| 11 | |
| 12 const symbol = const Symbol('symbol'); | |
| 13 | |
| 14 const hest = 'hest'; | |
| 15 | |
| 16 checkMetadata(DeclarationMirror mirror, List expectedMetadata) { | |
| 17 List metadata = mirror.metadata.map((m) => m.reflectee).toList(); | |
| 18 if (metadata == null) { | |
| 19 throw 'Null metadata on $mirror'; | |
| 20 } | |
| 21 int expectedLength = expectedMetadata.length; | |
| 22 int actualLength = metadata.length; | |
| 23 if (expectedLength != actualLength) { | |
| 24 throw 'Expected length = $expectedLength, but got length = $actualLength.'; | |
| 25 } | |
| 26 for (int i = 0; i < expectedLength; i++) { | |
| 27 if (metadata[i] != expectedMetadata[i]) { | |
| 28 throw '${metadata[i]} is not "${expectedMetadata[i]}"' | |
| 29 ' in $mirror at index $i'; | |
| 30 } | |
| 31 } | |
| 32 print(metadata); | |
| 33 } | |
| 34 | 11 |
| 35 main() { | 12 main() { |
| 36 if (MirrorSystem.getName(symbol) != 'symbol') { | |
| 37 // This happened in dart2js due to how early library metadata is | |
| 38 // computed. | |
| 39 throw 'Bad constant: $symbol'; | |
| 40 } | |
| 41 | |
| 42 MirrorSystem mirrors = currentMirrorSystem(); | 13 MirrorSystem mirrors = currentMirrorSystem(); |
| 43 checkMetadata(mirrors.findLibrary(const Symbol('test.library_metadata_test')).
first, | 14 checkMetadata(mirrors.findLibrary(const Symbol('test.library_metadata_test')).
first, |
| 44 [string, symbol]); | 15 [string, symbol]); |
| 45 } | 16 } |
| OLD | NEW |