OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 // Test that loading of a library (with top-level functions only) can |
| 6 // be deferred. |
| 7 |
| 8 import 'dart:async'; |
| 9 @lazy import 'deferred_function_library.dart'; |
| 10 |
| 11 const lazy = const DeferredLibrary('deferred_function_library'); |
| 12 |
| 13 isNoSuchMethodError(e) => e is NoSuchMethodError; |
| 14 |
| 15 main() { |
| 16 print('unittest-suite-wait-for-done'); |
| 17 |
| 18 Expect.throws(() { foo('a'); }, isNoSuchMethodError); |
| 19 int counter = 0; |
| 20 lazy.load().then((bool didLoad) { |
| 21 Expect.isTrue(didLoad); |
| 22 Expect.equals(1, ++counter); |
| 23 print('lazy was loaded'); |
| 24 Expect.equals(42, foo('b')); |
| 25 }); |
| 26 Expect.equals(0, counter); |
| 27 lazy.load().then((bool didLoad) { |
| 28 Expect.isFalse(didLoad); |
| 29 Expect.equals(2, ++counter); |
| 30 print('lazy was loaded'); |
| 31 Expect.equals(42, foo('b')); |
| 32 print('unittest-suite-success'); |
| 33 }); |
| 34 Expect.equals(0, counter); |
| 35 Expect.throws(() { foo('a'); }, isNoSuchMethodError); |
| 36 } |
OLD | NEW |