| Index: tests/compiler/dart2js/deferred_load_mapping_test.dart
|
| diff --git a/tests/compiler/dart2js/deferred_load_mapping_test.dart b/tests/compiler/dart2js/deferred_load_mapping_test.dart
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..af760fa8253d7511aa900a230356a7a4d66afefd
|
| --- /dev/null
|
| +++ b/tests/compiler/dart2js/deferred_load_mapping_test.dart
|
| @@ -0,0 +1,100 @@
|
| +// Copyright (c) 2015, 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.
|
| +
|
| +import 'package:expect/expect.dart';
|
| +import "package:async_helper/async_helper.dart";
|
| +import 'memory_source_file_helper.dart';
|
| +import "memory_compiler.dart";
|
| +
|
| +void main() {
|
| + var collector = new OutputCollector();
|
| + Compiler compiler = compilerFor(MEMORY_SOURCE_FILES,
|
| + options: ['--deferred-map=deferred_map.json'],
|
| + outputProvider: collector);
|
| + asyncTest(() {
|
| + return compiler.run(Uri.parse('memory:main.dart')).then((success) {
|
| + // Ensure a mapping file is output.
|
| + Expect.isNotNull(
|
| + collector.getOutput("deferred_map.json", "deferred_map"));
|
| +
|
| + Map mapping = compiler.deferredLoadTask.deferredMap();
|
| + // Test structure of mapping.
|
| + Expect.isTrue(mapping["main.dart"]["lib1"].length == 2);
|
| + Expect.isTrue(mapping["main.dart"]["lib2"].length == 2);
|
| + Expect.isTrue(mapping["main.dart"]["convert"].length == 1);
|
| + Expect.isTrue(mapping["memory:lib1.dart"]["lib4_1"].length == 1);
|
| + Expect.isTrue(mapping["memory:lib2.dart"]["lib4_2"].length == 1);
|
| + });
|
| + });
|
| +}
|
| +
|
| +const Map MEMORY_SOURCE_FILES = const {
|
| + "main.dart":"""
|
| +import 'dart:convert' deferred as convert;
|
| +import 'lib1.dart' deferred as lib1;
|
| +import 'lib2.dart' deferred as lib2;
|
| +
|
| +void main() {
|
| + lib1.loadLibrary().then((_) {
|
| + lib1.foo1();
|
| + new lib1.C();
|
| + lib2.loadLibrary().then((_) {
|
| + lib2.foo2();
|
| + });
|
| + });
|
| + convert.loadLibrary().then((_) {
|
| + new convert.JsonCodec();
|
| + });
|
| +}
|
| +""",
|
| + "lib1.dart":"""
|
| +library lib1;
|
| +import "dart:async";
|
| +import "dart:html";
|
| +
|
| +import "lib3.dart" as l3;
|
| +import "lib4.dart" deferred as lib4_1;
|
| +
|
| +class C {}
|
| +
|
| +foo1() {
|
| + new InputElement();
|
| + lib4_1.loadLibrary().then((_) {
|
| + lib4_1.bar1();
|
| + });
|
| + return () {return 1 + l3.foo3();} ();
|
| +}
|
| +""",
|
| + "lib2.dart":"""
|
| +library lib2;
|
| +import "dart:async";
|
| +import "lib3.dart" as l3;
|
| +import "lib4.dart" deferred as lib4_2;
|
| +
|
| +foo2() {
|
| + lib4_2.loadLibrary().then((_) {
|
| + lib4_2.bar2();
|
| + });
|
| + return () {return 2+l3.foo3();} ();
|
| +}
|
| +""",
|
| + "lib3.dart":"""
|
| +library lib3;
|
| +
|
| +foo3() {
|
| + return () {return 3;} ();
|
| +}
|
| +""",
|
| + "lib4.dart":"""
|
| +library lib4;
|
| +
|
| +bar1() {
|
| + return "hello";
|
| +}
|
| +
|
| +bar2() {
|
| + return 2;
|
| +}
|
| +""",
|
| +};
|
|
|