Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(321)

Unified Diff: dart/tests/compiler/dart2js/metadata_test.dart

Issue 10876036: Extend testing of metadata. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fixed missing import Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « dart/tests/compiler/dart2js/compiler_helper.dart ('k') | dart/tests/compiler/dart2js/resolver_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
}
« no previous file with comments | « dart/tests/compiler/dart2js/compiler_helper.dart ('k') | dart/tests/compiler/dart2js/resolver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698