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

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

Issue 17759007: First pass at asynchronous input loading in dart2js. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments Created 7 years, 3 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
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';
7 import "package:async_helper/async_helper.dart";
6 import 'memory_compiler.dart' show compilerFor; 8 import 'memory_compiler.dart' show compilerFor;
7 import '../../../sdk/lib/_internal/compiler/implementation/apiimpl.dart' show 9 import '../../../sdk/lib/_internal/compiler/implementation/apiimpl.dart' show
8 Compiler; 10 Compiler;
9 import 11 import
10 '../../../sdk/lib/_internal/compiler/implementation/tree/tree.dart' 12 '../../../sdk/lib/_internal/compiler/implementation/tree/tree.dart'
11 show 13 show
12 Node; 14 Node;
13 import 15 import
14 '../../../sdk/lib/_internal/compiler/implementation/dart_backend/dart_backen d.dart'; 16 '../../../sdk/lib/_internal/compiler/implementation/dart_backend/dart_backen d.dart';
15 import 17 import
16 '../../../sdk/lib/_internal/compiler/implementation/mirror_renamer/mirror_re namer.dart'; 18 '../../../sdk/lib/_internal/compiler/implementation/mirror_renamer/mirror_re namer.dart';
17 import 19 import
18 '../../../sdk/lib/_internal/compiler/implementation/scanner/scannerlib.dart' 20 '../../../sdk/lib/_internal/compiler/implementation/scanner/scannerlib.dart'
19 show 21 show
20 SourceString; 22 SourceString;
21 23
22 main() { 24 main() {
23 testWithMirrorHelperLibrary(minify: true); 25 testWithMirrorHelperLibrary(minify: true);
24 testWithMirrorHelperLibrary(minify: false); 26 testWithMirrorHelperLibrary(minify: false);
25 testWithoutMirrorHelperLibrary(minify: true); 27 testWithoutMirrorHelperLibrary(minify: true);
26 testWithoutMirrorHelperLibrary(minify: false); 28 testWithoutMirrorHelperLibrary(minify: false);
27 } 29 }
28 30
29 Compiler runCompiler({useMirrorHelperLibrary: false, minify: false}) { 31 Future<Compiler> runCompiler({useMirrorHelperLibrary: false, minify: false}) {
30 List<String> options = ['--output-type=dart']; 32 List<String> options = ['--output-type=dart'];
31 if (minify) { 33 if (minify) {
32 options.add('--minify'); 34 options.add('--minify');
33 } 35 }
34 Compiler compiler = compilerFor(MEMORY_SOURCE_FILES, options: options); 36 Compiler compiler = compilerFor(MEMORY_SOURCE_FILES, options: options);
35 DartBackend backend = compiler.backend; 37 DartBackend backend = compiler.backend;
36 backend.useMirrorHelperLibrary = useMirrorHelperLibrary; 38 backend.useMirrorHelperLibrary = useMirrorHelperLibrary;
37 compiler.runCompiler(Uri.parse('memory:main.dart')); 39 return
38 return compiler; 40 compiler.runCompiler(Uri.parse('memory:main.dart')).then((_) => compiler);
39 } 41 }
40 42
41 void testWithMirrorHelperLibrary({bool minify}) { 43 void testWithMirrorHelperLibrary({bool minify}) {
42 Compiler compiler = runCompiler(useMirrorHelperLibrary: true, minify: minify); 44 asyncTest(() => runCompiler(useMirrorHelperLibrary: true, minify: minify).
45 then((Compiler compiler) {
46 DartBackend backend = compiler.backend;
47 MirrorRenamer mirrorRenamer = backend.mirrorRenamer;
48 Map<Node, String> renames = backend.renames;
49 Map<String, SourceString> symbols = mirrorRenamer.symbols;
43 50
44 DartBackend backend = compiler.backend; 51 Expect.isFalse(null == backend.mirrorHelperLibrary);
45 MirrorRenamer mirrorRenamer = backend.mirrorRenamer; 52 Expect.isFalse(null == backend.mirrorHelperGetNameFunction);
46 Map<Node, String> renames = backend.renames;
47 Map<String, SourceString> symbols = mirrorRenamer.symbols;
48 53
49 Expect.isFalse(null == backend.mirrorHelperLibrary); 54 for (Node n in renames.keys) {
50 Expect.isFalse(null == backend.mirrorHelperGetNameFunction); 55 if (symbols.containsKey(renames[n])) {
51 56 if(n.toString() == 'getName') {
52 for (Node n in renames.keys) { 57 Expect.equals(
53 if (symbols.containsKey(renames[n])) { 58 const SourceString(MirrorRenamer.MIRROR_HELPER_GET_NAME_FUNCTION),
54 if(n.toString() == 'getName') { 59 symbols[renames[n]]);
55 Expect.equals( 60 } else {
56 const SourceString(MirrorRenamer.MIRROR_HELPER_GET_NAME_FUNCTION), 61 Expect.equals(n.toString(), symbols[renames[n]].stringValue);
57 symbols[renames[n]]); 62 }
58 } else {
59 Expect.equals(n.toString(), symbols[renames[n]].stringValue);
60 } 63 }
61 } 64 }
62 }
63 65
64 String output = compiler.assembledCode; 66 String output = compiler.assembledCode;
65 String getNameMatch = MirrorRenamer.MIRROR_HELPER_GET_NAME_FUNCTION; 67 String getNameMatch = MirrorRenamer.MIRROR_HELPER_GET_NAME_FUNCTION;
66 Iterable i = getNameMatch.allMatches(output); 68 Iterable i = getNameMatch.allMatches(output);
67 69
70 if (minify) {
71 Expect.equals(0, i.length);
72 } else {
73 // Appears twice in code (defined & called).
74 Expect.equals(2, i.length);
75 }
68 76
69 if (minify) { 77 String mapMatch = 'const<String,SourceString>';
70 Expect.equals(0, i.length); 78 i = mapMatch.allMatches(output);
71 } else { 79 Expect.equals(1, i.length);
72 // Appears twice in code (defined & called). 80 }));
73 Expect.equals(2, i.length);
74 }
75
76 String mapMatch = 'const<String,SourceString>';
77 i = mapMatch.allMatches(output);
78 Expect.equals(1, i.length);
79 } 81 }
80 82
81 void testWithoutMirrorHelperLibrary({bool minify}) { 83 void testWithoutMirrorHelperLibrary({bool minify}) {
82 Compiler compiler = 84 asyncTest(() => runCompiler(useMirrorHelperLibrary: false, minify: minify).
83 runCompiler(useMirrorHelperLibrary: false, minify: minify); 85 then((Compiler compiler) {
84 DartBackend backend = compiler.backend; 86 DartBackend backend = compiler.backend;
85 87
86 Expect.equals(null, backend.mirrorHelperLibrary); 88 Expect.equals(null, backend.mirrorHelperLibrary);
87 Expect.equals(null, backend.mirrorHelperGetNameFunction); 89 Expect.equals(null, backend.mirrorHelperGetNameFunction);
88 Expect.equals(null, backend.mirrorRenamer); 90 Expect.equals(null, backend.mirrorRenamer);
91 }));
89 } 92 }
90 93
91 const MEMORY_SOURCE_FILES = const <String, String> { 94 const MEMORY_SOURCE_FILES = const <String, String> {
92 'main.dart': """ 95 'main.dart': """
93 import 'dart:mirrors'; 96 import 'dart:mirrors';
94 97
95 class Foo { 98 class Foo {
96 noSuchMethod(Invocation invocation) { 99 noSuchMethod(Invocation invocation) {
97 MirrorSystem.getName(invocation.memberName); 100 MirrorSystem.getName(invocation.memberName);
98 } 101 }
99 } 102 }
100 103
101 void main() { 104 void main() {
102 new Foo().fisk(); 105 new Foo().fisk();
103 } 106 }
104 """}; 107 """};
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/metadata_test.dart ('k') | tests/compiler/dart2js/mirror_helper_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698