| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2015, 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 "package:async_helper/async_helper.dart"; |
| 7 import 'memory_source_file_helper.dart'; |
| 8 import "memory_compiler.dart"; |
| 9 |
| 10 void main() { |
| 11 var collector = new OutputCollector(); |
| 12 Compiler compiler = compilerFor(MEMORY_SOURCE_FILES, |
| 13 options: ['--deferred-map=deferred_map.json'], |
| 14 outputProvider: collector); |
| 15 asyncTest(() { |
| 16 return compiler.run(Uri.parse('memory:main.dart')).then((success) { |
| 17 // Ensure a mapping file is output. |
| 18 Expect.isNotNull( |
| 19 collector.getOutput("deferred_map.json", "deferred_map")); |
| 20 |
| 21 Map mapping = compiler.deferredLoadTask.deferredMap(); |
| 22 // Test structure of mapping. |
| 23 Expect.isTrue(mapping["main.dart"]["lib1"].length == 2); |
| 24 Expect.isTrue(mapping["main.dart"]["lib2"].length == 2); |
| 25 Expect.isTrue(mapping["main.dart"]["convert"].length == 1); |
| 26 Expect.isTrue(mapping["memory:lib1.dart"]["lib4_1"].length == 1); |
| 27 Expect.isTrue(mapping["memory:lib2.dart"]["lib4_2"].length == 1); |
| 28 }); |
| 29 }); |
| 30 } |
| 31 |
| 32 const Map MEMORY_SOURCE_FILES = const { |
| 33 "main.dart":""" |
| 34 import 'dart:convert' deferred as convert; |
| 35 import 'lib1.dart' deferred as lib1; |
| 36 import 'lib2.dart' deferred as lib2; |
| 37 |
| 38 void main() { |
| 39 lib1.loadLibrary().then((_) { |
| 40 lib1.foo1(); |
| 41 new lib1.C(); |
| 42 lib2.loadLibrary().then((_) { |
| 43 lib2.foo2(); |
| 44 }); |
| 45 }); |
| 46 convert.loadLibrary().then((_) { |
| 47 new convert.JsonCodec(); |
| 48 }); |
| 49 } |
| 50 """, |
| 51 "lib1.dart":""" |
| 52 library lib1; |
| 53 import "dart:async"; |
| 54 import "dart:html"; |
| 55 |
| 56 import "lib3.dart" as l3; |
| 57 import "lib4.dart" deferred as lib4_1; |
| 58 |
| 59 class C {} |
| 60 |
| 61 foo1() { |
| 62 new InputElement(); |
| 63 lib4_1.loadLibrary().then((_) { |
| 64 lib4_1.bar1(); |
| 65 }); |
| 66 return () {return 1 + l3.foo3();} (); |
| 67 } |
| 68 """, |
| 69 "lib2.dart":""" |
| 70 library lib2; |
| 71 import "dart:async"; |
| 72 import "lib3.dart" as l3; |
| 73 import "lib4.dart" deferred as lib4_2; |
| 74 |
| 75 foo2() { |
| 76 lib4_2.loadLibrary().then((_) { |
| 77 lib4_2.bar2(); |
| 78 }); |
| 79 return () {return 2+l3.foo3();} (); |
| 80 } |
| 81 """, |
| 82 "lib3.dart":""" |
| 83 library lib3; |
| 84 |
| 85 foo3() { |
| 86 return () {return 3;} (); |
| 87 } |
| 88 """, |
| 89 "lib4.dart":""" |
| 90 library lib4; |
| 91 |
| 92 bar1() { |
| 93 return "hello"; |
| 94 } |
| 95 |
| 96 bar2() { |
| 97 return 2; |
| 98 } |
| 99 """, |
| 100 }; |
| OLD | NEW |