| Index: dart/tests/compiler/dart2js/metadata_test.dart
|
| diff --git a/dart/tests/compiler/dart2js/metadata_test.dart b/dart/tests/compiler/dart2js/metadata_test.dart
|
| index 3961e7065ac45b8df1634d8bab84b36a00f8fe7f..1be5f7bed93d46586bdaeb803109f914cd7c336b 100644
|
| --- a/dart/tests/compiler/dart2js/metadata_test.dart
|
| +++ b/dart/tests/compiler/dart2js/metadata_test.dart
|
| @@ -9,43 +9,61 @@
|
| #import('../../../lib/compiler/implementation/elements/elements.dart');
|
| #import('../../../lib/compiler/implementation/leg.dart');
|
|
|
| -void testClassMetadata() {
|
| - // TODO(ahe): native should be "const", not "final".
|
| - final source = """final native = 'xyz';
|
| - @native class Foo {}
|
| - main() {}""";
|
| -
|
| - check(compiler, element) {
|
| - Expect.isFalse(element.metadata.isEmpty());
|
| - Expect.isTrue(element.metadata.tail.isEmpty());
|
| +void checkTopLevelAnnotation(String name, String declaration) {
|
| + var source;
|
| +
|
| + // Ensure that a compile-time constant can be resolved from an
|
| + // annotation.
|
| + source = """const native = 'xyz';
|
| + @native
|
| + $declaration
|
| + main() {}""";
|
| +
|
| + compileAndCheck(source, name, (compiler, element) {
|
| + Expect.equals(1, length(element.metadata));
|
| MetadataAnnotation annotation = element.metadata.head;
|
| annotation.ensureResolved(compiler);
|
| Constant value = annotation.value;
|
| Expect.stringEquals('xyz', value.value.slowToString());
|
| - }
|
| + });
|
| +
|
| + // Ensure that each repeated annotation has a unique instance of
|
| + // [MetadataAnnotation].
|
| + source = """const native = 'xyz';
|
| + @native @native
|
| + $declaration
|
| + main() {}""";
|
| +
|
| + compileAndCheck(source, name, (compiler, element) {
|
| + Expect.equals(2, length(element.metadata));
|
| + MetadataAnnotation annotation1 = element.metadata.head;
|
| + MetadataAnnotation annotation2 = element.metadata.tail.head;
|
| + annotation1.ensureResolved(compiler);
|
| + annotation2.ensureResolved(compiler);
|
| + Expect.isTrue(annotation1 !== annotation2, 'expected unique instances');
|
| + Expect.notEquals(annotation1, annotation2, 'expected unequal instances');
|
| + Constant value1 = annotation1.value;
|
| + Constant value2 = annotation2.value;
|
| + Expect.identical(value1, value2, 'expected same compile-time constant');
|
| + Expect.stringEquals('xyz', value1.value.slowToString());
|
| + Expect.stringEquals('xyz', value2.value.slowToString());
|
| + });
|
| +}
|
|
|
| - compileAndCheck(source, 'Foo', check);
|
| +void testClassMetadata() {
|
| + checkTopLevelAnnotation('Foo', 'class Foo {}');
|
| }
|
|
|
| void testTopLevelMethodMetadata() {
|
| - // TODO(ahe): native should be "const", not "final".
|
| - final source = """final native = 'xyz';
|
| - @native
|
| - main() {}""";
|
| -
|
| - check(compiler, element) {
|
| - Expect.isFalse(element.metadata.isEmpty());
|
| - Expect.isTrue(element.metadata.tail.isEmpty());
|
| - MetadataAnnotation annotation = element.metadata.head;
|
| - annotation.ensureResolved(compiler);
|
| - Constant value = annotation.value;
|
| - Expect.stringEquals('xyz', value.value.slowToString());
|
| - }
|
| + checkTopLevelAnnotation('foo', 'foo() {}');
|
| +}
|
|
|
| - compileAndCheck(source, 'main', check);
|
| +void testTopLevelFieldMetadata() {
|
| + checkTopLevelAnnotation('foo', 'var foo;');
|
| }
|
|
|
| void main() {
|
| testClassMetadata();
|
| testTopLevelMethodMetadata();
|
| + testTopLevelFieldMetadata();
|
| }
|
|
|