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

Side by Side Diff: tests/compiler/dart2js/mirror_helper_unique_minification_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: Added an assert. 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
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 'memory_compiler.dart' show compilerFor; 6 import 'memory_compiler.dart' show compilerFor;
7 import '../../../sdk/lib/_internal/compiler/implementation/apiimpl.dart' show 7 import '../../../sdk/lib/_internal/compiler/implementation/apiimpl.dart' show
8 Compiler; 8 Compiler;
9 import 9 import
10 '../../../sdk/lib/_internal/compiler/implementation/dart_backend/dart_backen d.dart' 10 '../../../sdk/lib/_internal/compiler/implementation/dart_backend/dart_backen d.dart'
11 show 11 show
12 DartBackend; 12 DartBackend;
13 import
14 '../../../sdk/lib/_internal/compiler/implementation/tree/tree.dart'
15 show
16 Node;
13 17
14 main() { 18 main() {
15 testUniqueMinification(); 19 testUniqueMinification();
16 testNoUniqueMinification(); 20 testNoUniqueMinification();
17 } 21 }
18 22
19 Compiler runCompiler({useMirrorHelperLibrary: false, minify: false}) { 23 Compiler runCompiler({useMirrorHelperLibrary: false, minify: false}) {
20 List<String> options = ['--output-type=dart']; 24 List<String> options = ['--output-type=dart'];
21 if (minify) { 25 if (minify) {
22 options.add('--minify'); 26 options.add('--minify');
23 } 27 }
24 Compiler compiler = compilerFor(MEMORY_SOURCE_FILES, options: options); 28 Compiler compiler = compilerFor(MEMORY_SOURCE_FILES, options: options);
25 DartBackend backend = compiler.backend; 29 DartBackend backend = compiler.backend;
26 backend.useMirrorHelperLibrary = useMirrorHelperLibrary; 30 backend.useMirrorHelperLibrary = useMirrorHelperLibrary;
27 compiler.runCompiler(Uri.parse('memory:main.dart')); 31 compiler.runCompiler(Uri.parse('memory:main.dart'));
28 return compiler; 32 return compiler;
29 } 33 }
30 34
31 void testUniqueMinification() { 35 void testUniqueMinification() {
32 Compiler compiler = runCompiler(useMirrorHelperLibrary: true, minify: true); 36 Compiler compiler = runCompiler(useMirrorHelperLibrary: true, minify: true);
33 DartBackend backend = compiler.backend; 37 DartBackend backend = compiler.backend;
38 MirrorRenamer mirrorRenamer = backend.mirrorRenamer;
34 Map<Node, String> renames = backend.renames; 39 Map<Node, String> renames = backend.renames;
40 Map<String, SourceString> symbols = mirrorRenamer.symbols;
35 41
36 //'Foo' appears twice, so toSet() reduces the length by 1. 42 // Check that no two different source code names get the same mangled name,
37 Expect.equals(renames.values.toSet().length, renames.values.length - 1); 43 // with the exception of MirrorSystem.getName that gets renamed to the same
44 // mangled name as the getNameHelper from _mirror_helper.dart.
45 for (Node node in renames.keys) {
46 Identifier identifier = node.asIdentifier();
47 if (identifier != null) {
48 SourceString source = identifier.source;
49 if (mirrorRenamer.mirrorSystemGetNameNodes.first.selector == node)
50 continue;
51 if (symbols.containsKey(renames[node])) {
52 print(node);
53 Expect.equals(source, symbols[renames[node]]);
54 }
55 }
56 }
38 } 57 }
39 58
40 void testNoUniqueMinification() { 59 void testNoUniqueMinification() {
41 Compiler compiler = runCompiler(useMirrorHelperLibrary: false, minify: true); 60 Compiler compiler = runCompiler(useMirrorHelperLibrary: false, minify: true);
42 DartBackend backend = compiler.backend; 61 DartBackend backend = compiler.backend;
43 Map<Node, String> renames = backend.renames; 62 Map<Node, String> renames = backend.renames;
44 63
45 //'Foo' appears twice and now 'invocation' and 'hest' can get the same name. 64 // 'Foo' appears twice and 'invocation' and 'hest' get the same mangled name.
46 Expect.equals(renames.values.toSet().length, renames.values.length - 2); 65 Expect.equals(renames.values.toSet().length, renames.values.length - 2);
47 } 66 }
48 67
49 const MEMORY_SOURCE_FILES = const <String, String> { 68 const MEMORY_SOURCE_FILES = const <String, String> {
50 'main.dart': """ 69 'main.dart': """
51 import 'dart:mirrors'; 70 import 'dart:mirrors';
52 71
53 class Foo { 72 class Foo {
54 noSuchMethod(invocation) { 73 noSuchMethod(invocation) {
55 MirrorSystem.getName(const Symbol('hest')); 74 MirrorSystem.getName(null);
56 } 75 }
57 } 76 }
58 77
59 main() { 78 main() {
60 new Foo().fisk(); 79 new Foo().fisk();
61 var hest; 80 var hest;
62 } 81 }
63 """}; 82 """};
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/mirror_helper_test.dart ('k') | tests/compiler/dart2js/mock_compiler.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698