Index: tests/compiler/dart2js/uri_retention_test.dart |
diff --git a/tests/compiler/dart2js/uri_retention_test.dart b/tests/compiler/dart2js/uri_retention_test.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..fcdcdcc0409a5554a2d77db20f3d4965bb95287a |
--- /dev/null |
+++ b/tests/compiler/dart2js/uri_retention_test.dart |
@@ -0,0 +1,102 @@ |
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
+// for details. All rights reserved. Use of this source code is governed by a |
+// BSD-style license that can be found in the LICENSE file. |
+ |
+library dart2js.test.uri_retention_test; |
+ |
+import 'dart:async'; |
+ |
+import 'package:expect/expect.dart'; |
+import "package:async_helper/async_helper.dart"; |
+ |
+import 'memory_compiler.dart' show |
+ compilerFor; |
+ |
+Future<String> compileSources(sources, {bool minify}) { |
+ var compiler = compilerFor(sources, options: minify ? ['--minify'] : []); |
+ return compiler.runCompiler(Uri.parse('memory:main.dart')).then((_) { |
+ return compiler.assembledCode; |
+ }); |
+} |
+ |
+Future test(sources, { bool libName, bool fileName }) { |
+ return compileSources(sources, minify: false).then((output) { |
+ // Unminified the sources should always contain the library name and the |
+ // file name. |
+ Expect.isTrue(output.contains("main_lib")); |
+ Expect.isTrue(output.contains("main.dart")); |
+ }).then((_) { |
+ compileSources(sources, minify: true).then((output) { |
+ Expect.equals(libName, output.contains("main_lib")); |
+ Expect.equals(fileName, output.contains("main.dart")); |
+ }); |
+ }); |
+} |
+ |
+void main() { |
+ asyncTest(() { |
+ return new Future.value() |
+ .then((_) => test(MEMORY_SOURCE_FILES1, libName: false, fileName: false)) |
+ .then((_) => test(MEMORY_SOURCE_FILES2, libName: true, fileName: false)) |
+ .then((_) => test(MEMORY_SOURCE_FILES3, libName: true, fileName: true)); |
+ }); |
+} |
+ |
+const MEMORY_SOURCE_FILES1 = const <String, String> { |
+ 'main.dart': """ |
+library main_lib; |
+ |
+class A { |
+ final uri = "foo"; |
+} |
+ |
+main() { |
+ print(Uri.base); |
+ print(new A().uri); |
+} |
+""", |
+}; |
+ |
+ |
+// Requires the library name, but not the URIs. |
+const MEMORY_SOURCE_FILES2 = const <String, String> { |
+ 'main.dart': """ |
+library main_lib; |
+ |
+@MirrorsUsed(targets: 'main_lib') |
+import 'dart:mirrors'; |
+import 'file2.dart'; |
+ |
+class A { |
+} |
+ |
+main() { |
+ print(Uri.base); |
+ // Unfortunately we can't use new B().uri yet, because that would require |
+ // some type-feedback to know that the '.uri' is not the one from the library. |
+ print(new B()); |
+ print(reflectClass(A).declarations.length); |
+} |
+""", |
+ 'file2.dart': """ |
+library other_lib; |
+ |
+class B { |
+ final uri = "xyz"; |
+} |
+""", |
+}; |
+ |
+// Requires the uri (and will contain the library-name, too). |
+const MEMORY_SOURCE_FILES3 = const <String, String> { |
+ 'main.dart': """ |
+library main_lib; |
+ |
+@MirrorsUsed(targets: 'main_lib') |
+import 'dart:mirrors'; |
+ |
+main() { |
+ print(currentMirrorSystem().findLibrary(#main_lib).uri); |
+} |
+""", |
+}; |