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

Side by Side 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: 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 import "package:expect/expect.dart";
6 import 'memory_compiler.dart' show compilerFor;
7 import '../../../sdk/lib/_internal/compiler/implementation/apiimpl.dart' show
8 Compiler;
9 import
10 '../../../sdk/lib/_internal/compiler/implementation/elements/elements.dart'
11 show
12 Elements;
13 import
14 '../../../sdk/lib/_internal/compiler/implementation/tree/tree.dart'
15 show
16 Node;
17 import
18 '../../../sdk/lib/_internal/compiler/implementation/dart_backend/dart_backen d.dart';
19 import
20 '../../../sdk/lib/_internal/compiler/implementation/mirror_renamer/mirror_re namer.dart';
21
22 main() {
23 testWithMirrorHeplerLibrary(minify: true);
24 testWithMirrorHeplerLibrary(minify: false);
25 testWithoutMirrorHelperLibrary(minify: true);
26 testWithoutMirrorHelperLibrary(minify: false);
27 }
28
29 Compiler runCompiler({useMirrorHelperLibrary: false, minify: false}) {
30 List<String> options = ['--output-type=dart'];
31 if (minify) {
32 options.add('--minify');
33 }
34 Compiler compiler = compilerFor(MEMORY_SOURCE_FILES, options: options);
35 DartBackend backend = compiler.backend;
36 backend.useMirrorHelperLibrary = useMirrorHelperLibrary;
37 MirrorRenamer.inverseRenames = null;
38 compiler.runCompiler(Uri.parse('memory:main.dart'));
39 return compiler;
40 }
41
42 void testWithMirrorHeplerLibrary({bool minify}) {
43 Compiler compiler = runCompiler(useMirrorHelperLibrary: true, minify: minify);
44
45 DartBackend backend = compiler.backend;
46 Map<Node, String> renames = backend.renames;
47 Map<String, String> inverseRenames = MirrorRenamer.inverseRenames;
48
49 Expect.isFalse(inverseRenames.isEmpty);
50
51 for (Node n in renames.keys) {
52 if (inverseRenames.containsKey(renames[n])) {
53 Expect.equals(inverseRenames[renames[n]], n.toString());
54 }
55 }
56
57 String output = compiler.assembledCode;
58 String match =
59 "${MirrorRenamer.MIRROR_HELPER_CLASS_FULLY_QUALIFIED_NAME}."
60 "${MirrorRenamer.MIRROR_HELPER_ADD_RENAME_FUNCTION}";
61 Iterable i = match.allMatches(output);
62
63 Expect.isTrue(output.indexOf('main(){$match') != -1);
64 Expect.equals(inverseRenames.length, i.length);
65 }
66
67 void testWithoutMirrorHelperLibrary({bool minify}) {
68 Compiler compiler =
69 runCompiler(useMirrorHelperLibrary: false, minify: minify);
70
71 Expect.equals(null, MirrorRenamer.inverseRenames);
72
73 String output = compiler.assembledCode;
74 String match =
75 "${MirrorRenamer.MIRROR_HELPER_CLASS_FULLY_QUALIFIED_NAME}."
76 "${MirrorRenamer.MIRROR_HELPER_ADD_RENAME_FUNCTION}";
77 Expect.equals(-1, output.indexOf(match));
78 }
79
80 const MEMORY_SOURCE_FILES = const <String, String> {
81 'main.dart': """
82 import 'dart:mirrors';
83
84
85 class Foo {
86 noSuchMethod(Invocation invocation) {
87 MirrorSystem.getName(invocation.memberName);
88 }
89 }
90
91 void main() {
92 new Foo().fisk();
93 }
94 """};
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698