OLD | NEW |
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 library dart2js.test.uri_retention_test; | 5 library dart2js.test.uri_retention_test; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:expect/expect.dart'; | 9 import 'package:expect/expect.dart'; |
10 import "package:async_helper/async_helper.dart"; | 10 import "package:async_helper/async_helper.dart"; |
11 | 11 |
12 import 'memory_compiler.dart' show | 12 import 'memory_compiler.dart' show |
13 compilerFor; | 13 compilerFor; |
14 | 14 |
15 Future<String> compileSources(sources, {bool minify}) { | 15 Future<String> compileSources(sources, {bool minify, bool preserveUri}) { |
16 var compiler = compilerFor(sources, options: minify ? ['--minify'] : []); | 16 var options = []; |
| 17 if (minify) options.add("--minify"); |
| 18 if (preserveUri) options.add("--preserve-uris"); |
| 19 var compiler = compilerFor(sources, options: options); |
17 return compiler.runCompiler(Uri.parse('memory:main.dart')).then((_) { | 20 return compiler.runCompiler(Uri.parse('memory:main.dart')).then((_) { |
18 return compiler.assembledCode; | 21 return compiler.assembledCode; |
19 }); | 22 }); |
20 } | 23 } |
21 | 24 |
22 Future test(sources, { bool libName, bool fileName }) { | 25 Future test(sources, { bool libName, bool fileName }) { |
23 return compileSources(sources, minify: false).then((output) { | 26 return |
| 27 compileSources(sources, minify: false, preserveUri: false).then((output) { |
24 // Unminified the sources should always contain the library name and the | 28 // Unminified the sources should always contain the library name and the |
25 // file name. | 29 // file name. |
26 Expect.isTrue(output.contains("main_lib")); | 30 Expect.isTrue(output.contains("main_lib")); |
27 Expect.isTrue(output.contains("main.dart")); | 31 Expect.isTrue(output.contains("main.dart")); |
28 }).then((_) { | 32 }).then((_) { |
29 compileSources(sources, minify: true).then((output) { | 33 compileSources(sources, minify: true, preserveUri: false).then((output) { |
| 34 Expect.equals(libName, output.contains("main_lib")); |
| 35 Expect.isFalse(output.contains("main.dart")); |
| 36 }); |
| 37 }).then((_) { |
| 38 compileSources(sources, minify: true, preserveUri: true).then((output) { |
30 Expect.equals(libName, output.contains("main_lib")); | 39 Expect.equals(libName, output.contains("main_lib")); |
31 Expect.equals(fileName, output.contains("main.dart")); | 40 Expect.equals(fileName, output.contains("main.dart")); |
32 }); | 41 }); |
33 }); | 42 }); |
34 } | 43 } |
35 | 44 |
36 void main() { | 45 void main() { |
37 asyncTest(() { | 46 asyncTest(() { |
38 return new Future.value() | 47 return new Future.value() |
39 .then((_) => test(MEMORY_SOURCE_FILES1, libName: false, fileName: false)) | 48 .then((_) => test(MEMORY_SOURCE_FILES1, libName: false, fileName: false)) |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 library main_lib; | 102 library main_lib; |
94 | 103 |
95 @MirrorsUsed(targets: 'main_lib') | 104 @MirrorsUsed(targets: 'main_lib') |
96 import 'dart:mirrors'; | 105 import 'dart:mirrors'; |
97 | 106 |
98 main() { | 107 main() { |
99 print(currentMirrorSystem().findLibrary(#main_lib).uri); | 108 print(currentMirrorSystem().findLibrary(#main_lib).uri); |
100 } | 109 } |
101 """, | 110 """, |
102 }; | 111 }; |
OLD | NEW |