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

Unified Diff: tests/lib/mirrors/metadata_scope_test.dart

Issue 217543004: VM: Evaluate metadata on a class in the scope of its library not the scope of the class. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: comments Created 6 years, 9 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 | « tests/lib/lib.status ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/lib/mirrors/metadata_scope_test.dart
diff --git a/tests/lib/mirrors/metadata_scope_test.dart b/tests/lib/mirrors/metadata_scope_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..2ccf39743eddfdafa02dbefc65d169945d1650d6
--- /dev/null
+++ b/tests/lib/mirrors/metadata_scope_test.dart
@@ -0,0 +1,60 @@
+// Copyright (c) 2014, 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.metadata_scope;
+
+import 'dart:mirrors';
+import 'package:expect/expect.dart';
+
+class Annotation {
+ final contents;
+ const Annotation(this.contents);
+ toString() => "Annotation($contents)";
+}
+
+// Note there is no compile-time constant 'foo' in scope. In particular, A.foo
+// is not in scope here.
+@Annotation(foo) /// 01: compile-time error
+class A {
+ @Annotation(foo)
+ static foo() {}
+
+ @Annotation(foo)
+ static bar() {}
+}
+
+@Annotation(B.foo)
+class B {
+ @Annotation(B.foo)
+ static foo() {}
+
+ @Annotation(B.foo)
+ static bar() {}
+}
+
+baz() {}
+
+// Note the top-level function baz is in scope here, not C.baz.
+@Annotation(baz)
+class C {
+ @Annotation(baz)
+ static baz() {}
+}
+
+checkMetadata(DeclarationMirror mirror, List expectedMetadata) {
+ Expect.listEquals(expectedMetadata.map(reflect).toList(), mirror.metadata);
+}
+
+main() {
+ reflectClass(A).metadata;
+ checkMetadata(reflectClass(A).declarations[#foo], [const Annotation(A.foo)]);
+ checkMetadata(reflectClass(A).declarations[#bar], [const Annotation(A.foo)]);
+ checkMetadata(reflectClass(B), [const Annotation(B.foo)]);
+ checkMetadata(reflectClass(B).declarations[#foo], [const Annotation(B.foo)]);
+ checkMetadata(reflectClass(B).declarations[#bar], [const Annotation(B.foo)]);
+ // The top-level function baz, not C.baz.
+ checkMetadata(reflectClass(C), [const Annotation(baz)]);
+ // C.baz, not the top-level function baz.
+ checkMetadata(reflectClass(C).declarations[#baz], [const Annotation(C.baz)]);
+}
« no previous file with comments | « tests/lib/lib.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698