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 library dart2js.test.uri_retention_test; |
| 6 |
| 7 import 'dart:async'; |
| 8 |
| 9 import 'package:expect/expect.dart'; |
| 10 import "package:async_helper/async_helper.dart"; |
| 11 |
| 12 import 'memory_compiler.dart' show |
| 13 compilerFor; |
| 14 |
| 15 Future<String> compileSources(sources, {bool minify}) { |
| 16 var compiler = compilerFor(sources, options: minify ? ['--minify'] : []); |
| 17 return compiler.runCompiler(Uri.parse('memory:main.dart')).then((_) { |
| 18 return compiler.assembledCode; |
| 19 }); |
| 20 } |
| 21 |
| 22 Future test(sources, { bool libName, bool fileName }) { |
| 23 return compileSources(sources, minify: false).then((output) { |
| 24 // Unminified the sources should always contain the library name and the |
| 25 // file name. |
| 26 Expect.isTrue(output.contains("main_lib")); |
| 27 Expect.isTrue(output.contains("main.dart")); |
| 28 }).then((_) { |
| 29 compileSources(sources, minify: true).then((output) { |
| 30 Expect.equals(libName, output.contains("main_lib")); |
| 31 Expect.equals(fileName, output.contains("main.dart")); |
| 32 }); |
| 33 }); |
| 34 } |
| 35 |
| 36 void main() { |
| 37 asyncTest(() { |
| 38 return new Future.value() |
| 39 .then((_) => test(MEMORY_SOURCE_FILES1, libName: false, fileName: false)) |
| 40 .then((_) => test(MEMORY_SOURCE_FILES2, libName: true, fileName: false)) |
| 41 .then((_) => test(MEMORY_SOURCE_FILES3, libName: true, fileName: true)); |
| 42 }); |
| 43 } |
| 44 |
| 45 const MEMORY_SOURCE_FILES1 = const <String, String> { |
| 46 'main.dart': """ |
| 47 library main_lib; |
| 48 |
| 49 class A { |
| 50 final uri = "foo"; |
| 51 } |
| 52 |
| 53 main() { |
| 54 print(Uri.base); |
| 55 print(new A().uri); |
| 56 } |
| 57 """, |
| 58 }; |
| 59 |
| 60 |
| 61 // Requires the library name, but not the URIs. |
| 62 const MEMORY_SOURCE_FILES2 = const <String, String> { |
| 63 'main.dart': """ |
| 64 library main_lib; |
| 65 |
| 66 @MirrorsUsed(targets: 'main_lib') |
| 67 import 'dart:mirrors'; |
| 68 import 'file2.dart'; |
| 69 |
| 70 class A { |
| 71 } |
| 72 |
| 73 main() { |
| 74 print(Uri.base); |
| 75 // Unfortunately we can't use new B().uri yet, because that would require |
| 76 // some type-feedback to know that the '.uri' is not the one from the library. |
| 77 print(new B()); |
| 78 print(reflectClass(A).declarations.length); |
| 79 } |
| 80 """, |
| 81 'file2.dart': """ |
| 82 library other_lib; |
| 83 |
| 84 class B { |
| 85 final uri = "xyz"; |
| 86 } |
| 87 """, |
| 88 }; |
| 89 |
| 90 // Requires the uri (and will contain the library-name, too). |
| 91 const MEMORY_SOURCE_FILES3 = const <String, String> { |
| 92 'main.dart': """ |
| 93 library main_lib; |
| 94 |
| 95 @MirrorsUsed(targets: 'main_lib') |
| 96 import 'dart:mirrors'; |
| 97 |
| 98 main() { |
| 99 print(currentMirrorSystem().findLibrary(#main_lib).uri); |
| 100 } |
| 101 """, |
| 102 }; |
OLD | NEW |