OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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 import "package:expect/expect.dart"; | 5 import '../../../async_helper.dart'; |
| 6 |
| 7 import 'package:expect/expect.dart'; |
| 8 |
6 import 'dart:async'; | 9 import 'dart:async'; |
7 | 10 |
8 @lazy import 'deferred_class_library.dart'; | 11 @lazy import 'deferred_class_library.dart'; |
9 | 12 |
10 const lazy = const DeferredLibrary('deferred_class_library'); | 13 const lazy = const DeferredLibrary('deferred_class_library'); |
11 | 14 |
12 main() { | 15 main() { |
13 var x; | 16 var x; |
14 Expect.isNull(const MyClass()); | 17 Expect.isNull(const MyClass()); |
15 Expect.isNull(const Constant(42)); | 18 Expect.isNull(const Constant(42)); |
16 Expect.isNull(const [const Constant(42)]); | 19 Expect.isNull(const [const Constant(42)]); |
17 Expect.isNull(x); | 20 Expect.isNull(x); |
18 int counter = 0; | 21 int counter = 0; |
| 22 asyncStart(); |
19 lazy.load().then((bool didLoad) { | 23 lazy.load().then((bool didLoad) { |
20 Expect.isTrue(didLoad); | 24 Expect.isTrue(didLoad); |
21 Expect.equals(1, ++counter); | 25 Expect.equals(1, ++counter); |
22 print('deferred_class_library was loaded'); | 26 print('deferred_class_library was loaded'); |
23 x = const MyClass(); | 27 x = const MyClass(); |
24 Expect.equals(42, x.foo(87)); | 28 Expect.equals(42, x.foo(87)); |
25 Expect.listEquals(const [const Constant(42)], [new Constant(42)]); | 29 Expect.listEquals(const [const Constant(42)], [new Constant(42)]); |
| 30 asyncEnd(); |
26 }); | 31 }); |
27 Expect.equals(0, counter); | 32 Expect.equals(0, counter); |
28 Expect.isNull(x); | 33 Expect.isNull(x); |
| 34 asyncStart(); |
29 lazy.load().then((bool didLoad) { | 35 lazy.load().then((bool didLoad) { |
30 Expect.isFalse(didLoad); | 36 Expect.isFalse(didLoad); |
31 Expect.equals(2, ++counter); | 37 Expect.equals(2, ++counter); |
32 print('deferred_class_library was loaded'); | 38 print('deferred_class_library was loaded'); |
33 x = const MyClass(); | 39 x = const MyClass(); |
34 Expect.equals(42, x.foo(87)); | 40 Expect.equals(42, x.foo(87)); |
35 Expect.listEquals(const [const Constant(42)], [new Constant(42)]); | 41 Expect.listEquals(const [const Constant(42)], [new Constant(42)]); |
| 42 asyncEnd(); |
36 }); | 43 }); |
37 Expect.equals(0, counter); | 44 Expect.equals(0, counter); |
38 Expect.isNull(x); | 45 Expect.isNull(x); |
39 Expect.isNull(const Constant(42)); | 46 Expect.isNull(const Constant(42)); |
40 Expect.isNull(const [const Constant(42)]); | 47 Expect.isNull(const [const Constant(42)]); |
41 Expect.isNull(x); | 48 Expect.isNull(x); |
42 } | 49 } |
OLD | NEW |