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

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

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

Powered by Google App Engine
This is Rietveld 408576698