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

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

Issue 12207017: Allow metadata on script tags. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix bug in legacy tags Created 7 years, 10 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/sdk/lib/_internal/compiler/implementation/tree/tree.dart ('k') | no next file » | 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 de74b88ab49a16d1cf7237ca859c9051adcf93c6..1591ebca633504613db7e5bdaef9502f6124571c 100644
--- a/dart/tests/compiler/dart2js/metadata_test.dart
+++ b/dart/tests/compiler/dart2js/metadata_test.dart
@@ -10,9 +10,9 @@ import 'parser_helper.dart';
import '../../../sdk/lib/_internal/compiler/implementation/elements/elements.dart';
import '../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart';
import '../../../sdk/lib/_internal/compiler/implementation/util/util.dart'
- show Spannable;
+ show Spannable, Link;
import '../../../sdk/lib/_internal/compiler/implementation/tree/tree.dart'
- show Node;
+ show Node, LibraryTag;
void checkPosition(Spannable spannable, Node node, String source, compiler) {
SourceSpan span = compiler.spanFromSpannable(spannable);
@@ -147,8 +147,74 @@ void testTopLevelFieldMetadata() {
checkAnnotation('foo', 'var foo;');
}
+void testLibraryTags() {
+ void compileAndCheckLibrary(
+ String source,
+ Link<MetadataAnnotation> extractMetadata(LibraryElement element)) {
+ Uri partUri = new Uri.fromComponents(scheme: 'source', path: 'part.dart');
+ String partSource = '@native part of foo;';
+
+ Uri libUri = new Uri.fromComponents(scheme: 'source', path: 'lib.dart');
+ String libSource = 'library lib;';
+
+ Uri uri = new Uri.fromComponents(scheme: 'source', path: 'main.dart');
+
+ var compiler = compilerFor(source, uri)
+ ..registerSource(partUri, partSource)
+ ..registerSource(libUri, libSource)
+ ..runCompiler(uri);
+ compiler.enqueuer.resolution.queueIsClosed = false;
+ LibraryElement element = compiler.libraries['$uri'];
+ Expect.isNotNull(element, 'Cannot find $uri');
+
+ Link<MetadataAnnotation> metadata = extractMetadata(element);
+ Expect.equals(1, length(metadata));
+
+ PartialMetadataAnnotation annotation = metadata.head;
+ annotation.ensureResolved(compiler);
+ Constant value = annotation.value;
+ Expect.stringEquals('xyz', value.value.slowToString());
+
+ checkPosition(annotation, annotation.cachedNode, source, compiler);
+ }
+
+ var source;
+
+ source = """@native
+ library foo;
+ const native = 'xyz';
+ main() {}""";
+ compileAndCheckLibrary(source, (e) => e.libraryTag.metadata);
+
+ source = """@native
+ import 'lib.dart';
+ const native = 'xyz';
+ main() {}""";
+ compileAndCheckLibrary(source, (e) => e.tags.single.metadata);
+
+ source = """@native
+ export 'lib.dart';
+ const native = 'xyz';
+ main() {}""";
+ compileAndCheckLibrary(source, (e) => e.tags.single.metadata);
+
+ source = """@native
+ part 'part.dart';
+ const native = 'xyz';
+ main() {}""";
+ compileAndCheckLibrary(source, (e) => e.tags.single.metadata);
+
+ source = """@native
+ part 'part.dart';
+ const native = 'xyz';
+ main() {}""";
+ compileAndCheckLibrary(source,
+ (e) => e.compilationUnits.first.partTag.metadata);
+}
+
void main() {
testClassMetadata();
testTopLevelMethodMetadata();
testTopLevelFieldMetadata();
+ testLibraryTags();
}
« no previous file with comments | « dart/sdk/lib/_internal/compiler/implementation/tree/tree.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698