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

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

Issue 21339002: Rename MirrorSystem.getName calls in dart2dart. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Format TODO comments. Created 7 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 | « sdk/lib/_internal/compiler/implementation/mirror_renamer/renamer.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/compiler/dart2js/mirror_helper_test.dart
diff --git a/tests/compiler/dart2js/mirror_helper_test.dart b/tests/compiler/dart2js/mirror_helper_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..01e69edba3f1c0144b7668bb51e5f655234e61b8
--- /dev/null
+++ b/tests/compiler/dart2js/mirror_helper_test.dart
@@ -0,0 +1,134 @@
+// Copyright (c) 2013, 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.
+
+import "package:expect/expect.dart";
+import 'memory_compiler.dart' show compilerFor;
+import '../../../sdk/lib/_internal/compiler/implementation/apiimpl.dart' show
+ Compiler;
+import
+ '../../../sdk/lib/_internal/compiler/implementation/elements/elements.dart'
+show
+ Element, LibraryElement, ClassElement;
+import
+ '../../../sdk/lib/_internal/compiler/implementation/tree/tree.dart'
+show
+ Node;
+import
+ '../../../sdk/lib/_internal/compiler/implementation/dart_backend/dart_backend.dart'
+show
+ DartBackend, ElementAst;
+import
+ '../../../sdk/lib/_internal/compiler/implementation/mirror_renamer/mirror_renamer.dart'
+show
+ MirrorRenamer;
+import
+ '../../../sdk/lib/_internal/compiler/implementation/scanner/scannerlib.dart'
+show
+ SourceString;
+
+
+main() {
+ testWithMirrorRenaming();
+ testWithoutMirrorRenaming();
+ testWithMirrorRenamingMinify();
+ testWithoutMirrorRenamingMinify();
+}
+
+Compiler runCompiler({useMirrorHelperLibrary: false, minify: false}) {
+ List<String> options = ['--output-type=dart'];
+ if (minify) {
+ options.add('--minify');
+ }
+ Compiler compiler = compilerFor(MEMORY_SOURCE_FILES, options: options);
+ DartBackend backend = compiler.backend;
+ backend.useMirrorHelperLibrary = useMirrorHelperLibrary;
+ compiler.runCompiler(Uri.parse('memory:main.dart'));
+ return compiler;
+}
+
+void testWithMirrorRenaming() {
+ Compiler compiler = runCompiler(useMirrorHelperLibrary: true, minify: false);
+
+ DartBackend backend = compiler.backend;
+ Map<Node, String> renames = backend.renames;
+ Map<LibraryElement, String> imports = backend.imports;
+
+ Node getNameFunctionNode =
+ backend.memberNodes.values.first.first.body.statements.nodes.head;
+
+ Expect.equals(MirrorRenamer.MIRROR_HELPER_GET_NAME_FUNCTION,
+ renames[getNameFunctionNode.expression.selector]);
+ Expect.equals(MirrorRenamer.MIRROR_HELPER_CLASS_FULLY_QUALIFIED_NAME,
+ renames[getNameFunctionNode.expression.receiver]);
+ Expect.equals(2, imports.keys.length);
+ Expect.isTrue(imports.keys.any((library) =>
+ library.canonicalUri ==
+ new Uri(path: MirrorRenamer.MIRROR_HELPER_LIBRARY_NAME)));
+}
+
+void testWithMirrorRenamingMinify() {
+ Compiler compiler = runCompiler(useMirrorHelperLibrary: true, minify: true);
+
+ DartBackend backend = compiler.backend;
+ Map<Node, String> renames = backend.renames;
+ Map<LibraryElement, String> imports = backend.imports;
+
+ Node getNameFunctionNode =
+ backend.memberNodes.values.first.first.body.statements.nodes.head;
+
+ Expect.equals(MirrorRenamer.MIRROR_HELPER_GET_NAME_FUNCTION,
+ renames[getNameFunctionNode.expression.selector]);
+ Expect.equals(MirrorRenamer.MIRROR_HELPER_CLASS_FULLY_QUALIFIED_NAME,
+ renames[getNameFunctionNode.expression.receiver]);
+ Expect.equals(2, imports.keys.length);
+ Expect.isTrue(imports.keys.any((library) =>
+ library.canonicalUri ==
+ new Uri(path: MirrorRenamer.MIRROR_HELPER_LIBRARY_NAME)));
+}
+
+void testWithoutMirrorRenaming() {
+ Compiler compiler = runCompiler(useMirrorHelperLibrary: false, minify: false);
+
+ DartBackend backend = compiler.backend;
+ Map<Node, String> renames = backend.renames;
+ Map<LibraryElement, String> imports = backend.imports;
+
+ Node getNameFunctionNode =
+ backend.memberNodes.values.first.first.body.statements.nodes.head;
+
+ Expect.isFalse(renames.containsKey(getNameFunctionNode.expression.selector));
+ Expect.isFalse(renames.containsKey(getNameFunctionNode.expression.receiver));
+ Expect.equals(1, imports.keys.length);
+}
+
+void testWithoutMirrorRenamingMinify() {
+ Compiler compiler = runCompiler(useMirrorHelperLibrary: false, minify: true);
+
+ DartBackend backend = compiler.backend;
+ Map<Node, String> renames = backend.renames;
+ Map<LibraryElement, String> imports = backend.imports;
+
+ Node getNameFunctionNode =
+ backend.memberNodes.values.first.first.body.statements.nodes.head;
+
+ Expect.isFalse(renames.containsKey(getNameFunctionNode.expression.selector));
+ Expect.isFalse(renames.containsKey(getNameFunctionNode.expression.receiver));
+ Expect.equals(1, imports.keys.length);
+}
+
+const MEMORY_SOURCE_FILES = const <String, String> {
+ 'main.dart': """
+import 'dart:mirrors';
+
+
+class Foo {
+ noSuchMethod(Invocation invocation) {
+ MirrorSystem.getName(invocation.memberName);
+ }
+}
+
+void main() {
+ new Foo().fisk();
+}
+"""};
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/mirror_renamer/renamer.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698