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 // Test that loading of a library (with top-level functions only) can | 5 // Test that loading of a library (with top-level functions only) can |
6 // be deferred. | 6 // be deferred. |
7 | 7 |
8 import 'package:async_helper/async_helper.dart'; | 8 import 'package:async_helper/async_helper.dart'; |
9 import 'package:expect/expect.dart'; | 9 import 'package:expect/expect.dart'; |
10 | 10 |
11 import 'deferred_function_library.dart' deferred as lib; | 11 import 'deferred_function_library.dart' deferred as lib; |
12 | 12 |
13 isError(e) => e is Error; | 13 isError(e) => e is Error; |
14 | 14 |
15 readFoo() { | 15 readFoo() { |
16 return lib.foo; | 16 return lib.foo; |
17 } | 17 } |
18 | 18 |
19 main() { | 19 main() { |
20 Expect.throws(() { lib.foo('a'); }, isError); | 20 Expect.throws(() { |
| 21 lib.foo('a'); |
| 22 }, isError); |
21 Expect.throws(readFoo, isError); | 23 Expect.throws(readFoo, isError); |
22 int counter = 0; | 24 int counter = 0; |
23 asyncStart(); | 25 asyncStart(); |
24 lib.loadLibrary().then((_) { | 26 lib.loadLibrary().then((_) { |
25 Expect.equals(1, ++counter); | 27 Expect.equals(1, ++counter); |
26 print('lazy was loaded'); | 28 print('lazy was loaded'); |
27 Expect.equals(42, lib.foo('b')); | 29 Expect.equals(42, lib.foo('b')); |
28 Expect.isNotNull(readFoo()); | 30 Expect.isNotNull(readFoo()); |
29 asyncEnd(); | 31 asyncEnd(); |
30 }); | 32 }); |
31 Expect.equals(0, counter); | 33 Expect.equals(0, counter); |
32 asyncStart(); | 34 asyncStart(); |
33 lib.loadLibrary().then((_) { | 35 lib.loadLibrary().then((_) { |
34 Expect.equals(2, ++counter); | 36 Expect.equals(2, ++counter); |
35 print('lazy was loaded'); | 37 print('lazy was loaded'); |
36 Expect.equals(42, lib.foo('b')); | 38 Expect.equals(42, lib.foo('b')); |
37 Expect.isNotNull(readFoo()); | 39 Expect.isNotNull(readFoo()); |
38 asyncEnd(); | 40 asyncEnd(); |
39 }); | 41 }); |
40 Expect.equals(0, counter); | 42 Expect.equals(0, counter); |
41 Expect.throws(() { lib.foo('a'); }, isError); | 43 Expect.throws(() { |
| 44 lib.foo('a'); |
| 45 }, isError); |
42 Expect.throws(readFoo, isError); | 46 Expect.throws(readFoo, isError); |
43 } | 47 } |
OLD | NEW |