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

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

Issue 22791002: Add renames in output when using the mirror helper library. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Changed solution approach. 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
Index: tests/compiler/dart2js/mirror_helper2_test.dart
diff --git a/tests/compiler/dart2js/mirror_helper2_test.dart b/tests/compiler/dart2js/mirror_helper2_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..48e731c0f22fa8afffbea288e3d4230a99d51864
--- /dev/null
+++ b/tests/compiler/dart2js/mirror_helper2_test.dart
@@ -0,0 +1,101 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
ahe 2013/08/19 15:34:06 Could you come up with a less generic name for thi
zarah 2013/08/20 14:08:17 Done.
+// 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/tree/tree.dart'
+show
+ Node;
+import
+ '../../../sdk/lib/_internal/compiler/implementation/dart_backend/dart_backend.dart';
+import
+ '../../../sdk/lib/_internal/compiler/implementation/mirror_renamer/mirror_renamer.dart';
+
+main() {
+ testWithMirrorHeplerLibrary(minify: true);
+ testWithMirrorHeplerLibrary(minify: false);
+ testWithoutMirrorHelperLibrary(minify: true);
+ testWithoutMirrorHelperLibrary(minify: false);
+}
+
+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;
+ MirrorRenamer.inverseRenames = null;
+ compiler.runCompiler(Uri.parse('memory:main.dart'));
+ return compiler;
+}
+
+void testWithMirrorHeplerLibrary({bool minify}) {
+ Compiler compiler = runCompiler(useMirrorHelperLibrary: true, minify: minify);
+
+ DartBackend backend = compiler.backend;
+ Map<Node, String> renames = backend.renames;
+ Map<String, String> inverseRenames = MirrorRenamer.inverseRenames;
+
+ Expect.isFalse(null == compiler.mirrorHelperLibrary);
+ Expect.isFalse(null == compiler.mirrorHelperFunction);
+ Expect.isTrue(inverseRenames.
+ containsValue(MirrorRenamer.MIRROR_HELPER_GET_NAME_FUNCTION));
+
+ for (Node n in renames.keys) {
+ if (inverseRenames.containsKey(renames[n])) {
+ if(n.toString() == 'getName') {
+ Expect.equals(MirrorRenamer.MIRROR_HELPER_GET_NAME_FUNCTION,
+ inverseRenames[renames[n]]);
+ } else {
+ Expect.equals(n.toString(), inverseRenames[renames[n]]);
+ }
+ }
+ }
+
+ String output = compiler.assembledCode;
+ String getNameMatch = MirrorRenamer.MIRROR_HELPER_GET_NAME_FUNCTION;
+ Iterable i = getNameMatch.allMatches(output);
+
+ if (minify) {
+ Expect.equals(1, i.length);
+ } else {
+ // Referenced twice in code and twice in renames map.
+ Expect.equals(4, i.length);
+ }
+
+ String mapMatch = 'const Map<String,String>';
+ i = mapMatch.allMatches(output);
+ Expect.equals(1, i.length);
+
ahe 2013/08/19 15:34:06 Extra line.
zarah 2013/08/20 14:08:17 Done.
+}
+
+void testWithoutMirrorHelperLibrary({bool minify}) {
+ Compiler compiler =
+ runCompiler(useMirrorHelperLibrary: false, minify: minify);
+
+ Expect.equals(null, compiler.mirrorHelperLibrary);
+ Expect.equals(null, compiler.mirrorHelperFunction);
+ Expect.equals(null, MirrorRenamer.inverseRenames);
+}
+
+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();
+}
+"""};

Powered by Google App Engine
This is Rietveld 408576698