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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/mirror_renamer/renamer.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 Element, LibraryElement, ClassElement;
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 show
20 DartBackend, ElementAst;
21 import
22 '../../../sdk/lib/_internal/compiler/implementation/mirror_renamer/mirror_re namer.dart'
23 show
24 MirrorRenamer;
25 import
26 '../../../sdk/lib/_internal/compiler/implementation/scanner/scannerlib.dart'
27 show
28 SourceString;
29
30
31 main() {
32 testWithMirrorRenaming();
33 testWithoutMirrorRenaming();
34 testWithMirrorRenamingMinify();
35 testWithoutMirrorRenamingMinify();
36 }
37
38 Compiler runCompiler({useMirrorHelperLibrary: false, minify: false}) {
39 List<String> options = ['--output-type=dart'];
40 if (minify) {
41 options.add('--minify');
42 }
43 Compiler compiler = compilerFor(MEMORY_SOURCE_FILES, options: options);
44 DartBackend backend = compiler.backend;
45 backend.useMirrorHelperLibrary = useMirrorHelperLibrary;
46 compiler.runCompiler(Uri.parse('memory:main.dart'));
47 return compiler;
48 }
49
50 void testWithMirrorRenaming() {
51 Compiler compiler = runCompiler(useMirrorHelperLibrary: true, minify: false);
52
53 DartBackend backend = compiler.backend;
54 Map<Node, String> renames = backend.renames;
55 Map<LibraryElement, String> imports = backend.imports;
56
57 Node getNameFunctionNode =
58 backend.memberNodes.values.first.first.body.statements.nodes.head;
59
60 Expect.equals(MirrorRenamer.MIRROR_HELPER_GET_NAME_FUNCTION,
61 renames[getNameFunctionNode.expression.selector]);
62 Expect.equals(MirrorRenamer.MIRROR_HELPER_CLASS_FULLY_QUALIFIED_NAME,
63 renames[getNameFunctionNode.expression.receiver]);
64 Expect.equals(2, imports.keys.length);
65 Expect.isTrue(imports.keys.any((library) =>
66 library.canonicalUri ==
67 new Uri(path: MirrorRenamer.MIRROR_HELPER_LIBRARY_NAME)));
68 }
69
70 void testWithMirrorRenamingMinify() {
71 Compiler compiler = runCompiler(useMirrorHelperLibrary: true, minify: true);
72
73 DartBackend backend = compiler.backend;
74 Map<Node, String> renames = backend.renames;
75 Map<LibraryElement, String> imports = backend.imports;
76
77 Node getNameFunctionNode =
78 backend.memberNodes.values.first.first.body.statements.nodes.head;
79
80 Expect.equals(MirrorRenamer.MIRROR_HELPER_GET_NAME_FUNCTION,
81 renames[getNameFunctionNode.expression.selector]);
82 Expect.equals(MirrorRenamer.MIRROR_HELPER_CLASS_FULLY_QUALIFIED_NAME,
83 renames[getNameFunctionNode.expression.receiver]);
84 Expect.equals(2, imports.keys.length);
85 Expect.isTrue(imports.keys.any((library) =>
86 library.canonicalUri ==
87 new Uri(path: MirrorRenamer.MIRROR_HELPER_LIBRARY_NAME)));
88 }
89
90 void testWithoutMirrorRenaming() {
91 Compiler compiler = runCompiler(useMirrorHelperLibrary: false, minify: false);
92
93 DartBackend backend = compiler.backend;
94 Map<Node, String> renames = backend.renames;
95 Map<LibraryElement, String> imports = backend.imports;
96
97 Node getNameFunctionNode =
98 backend.memberNodes.values.first.first.body.statements.nodes.head;
99
100 Expect.isFalse(renames.containsKey(getNameFunctionNode.expression.selector));
101 Expect.isFalse(renames.containsKey(getNameFunctionNode.expression.receiver));
102 Expect.equals(1, imports.keys.length);
103 }
104
105 void testWithoutMirrorRenamingMinify() {
106 Compiler compiler = runCompiler(useMirrorHelperLibrary: false, minify: true);
107
108 DartBackend backend = compiler.backend;
109 Map<Node, String> renames = backend.renames;
110 Map<LibraryElement, String> imports = backend.imports;
111
112 Node getNameFunctionNode =
113 backend.memberNodes.values.first.first.body.statements.nodes.head;
114
115 Expect.isFalse(renames.containsKey(getNameFunctionNode.expression.selector));
116 Expect.isFalse(renames.containsKey(getNameFunctionNode.expression.receiver));
117 Expect.equals(1, imports.keys.length);
118 }
119
120 const MEMORY_SOURCE_FILES = const <String, String> {
121 'main.dart': """
122 import 'dart:mirrors';
123
124
125 class Foo {
126 noSuchMethod(Invocation invocation) {
127 MirrorSystem.getName(invocation.memberName);
128 }
129 }
130
131 void main() {
132 new Foo().fisk();
133 }
134 """};
OLDNEW
« 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