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

Side by Side Diff: tests/compiler/dart2js/mirror_helper_test.dart

Issue 1409803006: Rename apiimpl.Compiler to CompilerImpl. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Fix long lines Created 5 years, 1 month 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
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import "package:expect/expect.dart"; 5 import "package:expect/expect.dart";
6 import 'dart:async'; 6 import 'dart:async';
7 import "package:async_helper/async_helper.dart"; 7 import "package:async_helper/async_helper.dart";
8 import 'memory_compiler.dart' show runCompiler; 8 import 'memory_compiler.dart' show runCompiler;
9 import 'package:compiler/src/apiimpl.dart' show 9 import 'package:compiler/src/apiimpl.dart' show
10 Compiler; 10 CompilerImpl;
11 import 'package:compiler/src/elements/elements.dart' show 11 import 'package:compiler/src/elements/elements.dart' show
12 Element, LibraryElement, ClassElement; 12 Element, LibraryElement, ClassElement;
13 import 'package:compiler/src/tree/tree.dart' show 13 import 'package:compiler/src/tree/tree.dart' show
14 Block, ExpressionStatement, FunctionExpression, Node, Send; 14 Block, ExpressionStatement, FunctionExpression, Node, Send;
15 import 'package:compiler/src/dart_backend/dart_backend.dart' show 15 import 'package:compiler/src/dart_backend/dart_backend.dart' show
16 DartBackend, ElementAst; 16 DartBackend, ElementAst;
17 import 'package:compiler/src/mirror_renamer/mirror_renamer.dart' show 17 import 'package:compiler/src/mirror_renamer/mirror_renamer.dart' show
18 MirrorRenamerImpl; 18 MirrorRenamerImpl;
19 19
20 main() { 20 main() {
21 asyncTest(() async { 21 asyncTest(() async {
22 await testWithMirrorRenaming(minify: true); 22 await testWithMirrorRenaming(minify: true);
23 await testWithMirrorRenaming(minify: false); 23 await testWithMirrorRenaming(minify: false);
24 await testWithoutMirrorRenaming(minify: true); 24 await testWithoutMirrorRenaming(minify: true);
25 await testWithoutMirrorRenaming(minify: false); 25 await testWithoutMirrorRenaming(minify: false);
26 }); 26 });
27 } 27 }
28 28
29 Future<Compiler> run({useMirrorHelperLibrary: false, minify: false}) async { 29 Future<CompilerImpl> run({useMirrorHelperLibrary: false, minify: false}) async {
30 List<String> options = ['--output-type=dart']; 30 List<String> options = ['--output-type=dart'];
31 if (minify) { 31 if (minify) {
32 options.add('--minify'); 32 options.add('--minify');
33 } 33 }
34 var result = await runCompiler( 34 var result = await runCompiler(
35 memorySourceFiles: MEMORY_SOURCE_FILES, 35 memorySourceFiles: MEMORY_SOURCE_FILES,
36 options: options, 36 options: options,
37 beforeRun: (Compiler compiler) { 37 beforeRun: (CompilerImpl compiler) {
38 DartBackend backend = compiler.backend; 38 DartBackend backend = compiler.backend;
39 backend.useMirrorHelperLibrary = useMirrorHelperLibrary; 39 backend.useMirrorHelperLibrary = useMirrorHelperLibrary;
40 }); 40 });
41 return result.compiler; 41 return result.compiler;
42 } 42 }
43 43
44 Future testWithMirrorRenaming({bool minify}) async { 44 Future testWithMirrorRenaming({bool minify}) async {
45 Compiler compiler = await run(useMirrorHelperLibrary: true, minify: minify); 45 CompilerImpl compiler =
46 await run(useMirrorHelperLibrary: true, minify: minify);
46 DartBackend backend = compiler.backend; 47 DartBackend backend = compiler.backend;
47 MirrorRenamerImpl mirrorRenamer = backend.mirrorRenamer; 48 MirrorRenamerImpl mirrorRenamer = backend.mirrorRenamer;
48 Map<Node, String> renames = backend.placeholderRenamer.renames; 49 Map<Node, String> renames = backend.placeholderRenamer.renames;
49 Iterable<LibraryElement> imports = 50 Iterable<LibraryElement> imports =
50 backend.placeholderRenamer.platformImports.keys; 51 backend.placeholderRenamer.platformImports.keys;
51 52
52 FunctionExpression node = backend.memberNodes.values.first.first; 53 FunctionExpression node = backend.memberNodes.values.first.first;
53 Block block = node.body; 54 Block block = node.body;
54 ExpressionStatement getNameFunctionNode = block.statements.nodes.head; 55 ExpressionStatement getNameFunctionNode = block.statements.nodes.head;
55 Send send = getNameFunctionNode.expression; 56 Send send = getNameFunctionNode.expression;
56 57
57 Expect.equals(renames[mirrorRenamer.getNameFunctionNode.name], 58 Expect.equals(renames[mirrorRenamer.getNameFunctionNode.name],
58 renames[send.selector]); 59 renames[send.selector]);
59 Expect.equals("", 60 Expect.equals("",
60 renames[send.receiver]); 61 renames[send.receiver]);
61 Expect.equals(1, imports.length); 62 Expect.equals(1, imports.length);
62 } 63 }
63 64
64 Future testWithoutMirrorRenaming({bool minify}) async { 65 Future testWithoutMirrorRenaming({bool minify}) async {
65 Compiler compiler = await run(useMirrorHelperLibrary: false, minify: minify); 66 CompilerImpl compiler =
67 await run(useMirrorHelperLibrary: false, minify: minify);
66 DartBackend backend = compiler.backend; 68 DartBackend backend = compiler.backend;
67 Map<Node, String> renames = backend.placeholderRenamer.renames; 69 Map<Node, String> renames = backend.placeholderRenamer.renames;
68 Iterable<LibraryElement> imports = 70 Iterable<LibraryElement> imports =
69 backend.placeholderRenamer.platformImports.keys; 71 backend.placeholderRenamer.platformImports.keys;
70 FunctionExpression node = backend.memberNodes.values.first.first; 72 FunctionExpression node = backend.memberNodes.values.first.first;
71 Block block = node.body; 73 Block block = node.body;
72 ExpressionStatement getNameFunctionNode = block.statements.nodes.head; 74 ExpressionStatement getNameFunctionNode = block.statements.nodes.head;
73 Send send = getNameFunctionNode.expression; 75 Send send = getNameFunctionNode.expression;
74 76
75 Expect.isFalse(renames.containsKey(send.selector)); 77 Expect.isFalse(renames.containsKey(send.selector));
76 Expect.equals(1, imports.length); 78 Expect.equals(1, imports.length);
77 } 79 }
78 80
79 const MEMORY_SOURCE_FILES = const <String, String> { 81 const MEMORY_SOURCE_FILES = const <String, String> {
80 'main.dart': """ 82 'main.dart': """
81 import 'dart:mirrors'; 83 import 'dart:mirrors';
82 84
83 class Foo { 85 class Foo {
84 noSuchMethod(Invocation invocation) { 86 noSuchMethod(Invocation invocation) {
85 MirrorSystem.getName(invocation.memberName); 87 MirrorSystem.getName(invocation.memberName);
86 } 88 }
87 } 89 }
88 90
89 void main() { 91 void main() {
90 new Foo().fisk(); 92 new Foo().fisk();
91 } 93 }
92 """}; 94 """};
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698