| OLD | NEW |
| (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/dart_backend/dart_backen
d.dart' |
| 11 show |
| 12 DartBackend; |
| 13 |
| 14 main() { |
| 15 testUniqueMinification(); |
| 16 testNoUniqueMinification(); |
| 17 } |
| 18 |
| 19 Compiler runCompiler({useMirrorHelperLibrary: false, minify: false}) { |
| 20 List<String> options = ['--output-type=dart']; |
| 21 if (minify) { |
| 22 options.add('--minify'); |
| 23 } |
| 24 Compiler compiler = compilerFor(MEMORY_SOURCE_FILES, options: options); |
| 25 DartBackend backend = compiler.backend; |
| 26 backend.useMirrorHelperLibrary = useMirrorHelperLibrary; |
| 27 compiler.runCompiler(Uri.parse('memory:main.dart')); |
| 28 return compiler; |
| 29 } |
| 30 |
| 31 void testUniqueMinification() { |
| 32 Compiler compiler = runCompiler(useMirrorHelperLibrary: true, minify: true); |
| 33 DartBackend backend = compiler.backend; |
| 34 Map<Node, String> renames = backend.renames; |
| 35 |
| 36 //'Foo' appears twice, so toSet() reduces the length by 1. |
| 37 Expect.equals(renames.values.toSet().length, renames.values.length - 1); |
| 38 } |
| 39 |
| 40 void testNoUniqueMinification() { |
| 41 Compiler compiler = runCompiler(useMirrorHelperLibrary: false, minify: true); |
| 42 DartBackend backend = compiler.backend; |
| 43 Map<Node, String> renames = backend.renames; |
| 44 |
| 45 //'Foo' appears twice and now 'invocation' and 'hest' can get the same name. |
| 46 Expect.equals(renames.values.toSet().length, renames.values.length - 2); |
| 47 } |
| 48 |
| 49 const MEMORY_SOURCE_FILES = const <String, String> { |
| 50 'main.dart': """ |
| 51 import 'dart:mirrors'; |
| 52 |
| 53 class Foo { |
| 54 noSuchMethod(invocation) { |
| 55 MirrorSystem.getName(const Symbol('hest')); |
| 56 } |
| 57 } |
| 58 |
| 59 main() { |
| 60 new Foo().fisk(); |
| 61 var hest; |
| 62 } |
| 63 """}; |
| OLD | NEW |