| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 // Test of the graph segmentation algorithm used by deferred loading | 5 // Test of the graph segmentation algorithm used by deferred loading |
| 6 // to determine which elements can be deferred and which libraries | 6 // to determine which elements can be deferred and which libraries |
| 7 // much be included in the initial download (loaded eagerly). | 7 // much be included in the initial download (loaded eagerly). |
| 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"; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 | 31 |
| 32 var lib1 = compiler.libraries["memory:lib1.dart"]; | 32 var lib1 = compiler.libraries["memory:lib1.dart"]; |
| 33 var lib2 = compiler.libraries["memory:lib2.dart"]; | 33 var lib2 = compiler.libraries["memory:lib2.dart"]; |
| 34 var mathLib = compiler.libraries["dart:math"]; | 34 var mathLib = compiler.libraries["dart:math"]; |
| 35 var sin = mathLib.find('sin'); | 35 var sin = mathLib.find('sin'); |
| 36 var foo1 = lib1.find("foo1"); | 36 var foo1 = lib1.find("foo1"); |
| 37 var foo2 = lib2.find("foo2"); | 37 var foo2 = lib2.find("foo2"); |
| 38 var field2 = lib2.find("field2"); | 38 var field2 = lib2.find("field2"); |
| 39 | 39 |
| 40 Expect.notEquals(outputUnitForElement(main), outputUnitForElement(foo1)); | 40 Expect.notEquals(outputUnitForElement(main), outputUnitForElement(foo1)); |
| 41 Expect.equals(outputUnitForElement(foo1), outputUnitForElement(sin)); | 41 Expect.equals(outputUnitForElement(main), outputUnitForElement(sin)); |
| 42 Expect.equals(outputUnitForElement(foo2), outputUnitForElement(sin)); | |
| 43 Expect.equals(outputUnitForElement(foo2), outputUnitForElement(field2)); | 42 Expect.equals(outputUnitForElement(foo2), outputUnitForElement(field2)); |
| 44 }); | 43 }); |
| 45 runTest('memory:main2.dart', (compiler) { | 44 runTest('memory:main2.dart', (compiler) { |
| 46 // Just check that the compile runs. | 45 // Just check that the compile runs. |
| 47 // This is a regression test. | 46 // This is a regression test. |
| 48 Expect.isTrue(true); | 47 Expect.isTrue(true); |
| 49 }); | 48 }); |
| 50 runTest('memory:main3.dart', (compiler) { | 49 runTest('memory:main3.dart', (compiler) { |
| 51 var main = compiler.mainApp.find(dart2js.Compiler.MAIN); | 50 var main = compiler.mainApp.find(dart2js.Compiler.MAIN); |
| 52 Expect.isNotNull(main, "Could not find 'main'"); | 51 Expect.isNotNull(main, "Could not find 'main'"); |
| 53 compiler.deferredLoadTask.onResolutionComplete(main); | 52 compiler.deferredLoadTask.onResolutionComplete(main); |
| 54 var outputUnitForElement = compiler.deferredLoadTask.outputUnitForElement; | 53 var outputUnitForElement = compiler.deferredLoadTask.outputUnitForElement; |
| 55 | 54 |
| 56 var mainLib = compiler.libraries["memory:main3.dart"]; | 55 var mainLib = compiler.libraries["memory:main3.dart"]; |
| 57 var lib3 = compiler.libraries["memory:lib3.dart"]; | 56 var lib3 = compiler.libraries["memory:lib3.dart"]; |
| 58 var C = mainLib.find("C"); | 57 var C = mainLib.find("C"); |
| 59 var foo = lib3.find("foo"); | 58 var foo = lib3.find("foo"); |
| 60 | 59 |
| 61 Expect.notEquals(outputUnitForElement(main), outputUnitForElement(foo)); | 60 Expect.notEquals(outputUnitForElement(main), outputUnitForElement(foo)); |
| 62 Expect.equals(outputUnitForElement(foo), outputUnitForElement(C)); | 61 Expect.equals(outputUnitForElement(main), outputUnitForElement(C)); |
| 63 }); | 62 }); |
| 64 } | 63 } |
| 65 | 64 |
| 66 // "lib1.dart" uses mirrors without a MirrorsUsed annotation, so everything | 65 // "lib1.dart" uses mirrors without a MirrorsUsed annotation, so everything |
| 67 // should be put in the "lib1" output unit. | 66 // should be put in the "lib1" output unit. |
| 68 const Map MEMORY_SOURCE_FILES = const { | 67 const Map MEMORY_SOURCE_FILES = const { |
| 69 "main.dart": """ | 68 "main.dart": """ |
| 70 import "dart:math"; | 69 import "dart:math"; |
| 71 | 70 |
| 72 import 'lib1.dart' deferred as lib1; | 71 import 'lib1.dart' deferred as lib1; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 """, | 140 """, |
| 142 "lib3.dart": """ | 141 "lib3.dart": """ |
| 143 @MirrorsUsed(targets: const ["main3.C"]) | 142 @MirrorsUsed(targets: const ["main3.C"]) |
| 144 import "dart:mirrors"; | 143 import "dart:mirrors"; |
| 145 | 144 |
| 146 foo() { | 145 foo() { |
| 147 currentMirrorSystem().findLibrary(#main3); | 146 currentMirrorSystem().findLibrary(#main3); |
| 148 } | 147 } |
| 149 """, | 148 """, |
| 150 }; | 149 }; |
| OLD | NEW |