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 'dart:async'; | 8 import 'dart:async'; |
9 @lazy import 'deferred_function_library.dart'; | 9 @lazy import 'deferred_function_library.dart'; |
10 | 10 |
11 const lazy = const DeferredLibrary('deferred_function_library'); | 11 const lazy = const DeferredLibrary('deferred_function_library'); |
12 | 12 |
13 isNoSuchMethodError(e) => e is NoSuchMethodError; | 13 isNoSuchMethodError(e) => e is NoSuchMethodError; |
14 | 14 |
15 class Expect { | 15 class Expect { |
16 static void isTrue(x) => Expect.equals(true, x); | 16 static void isTrue(x) => Expect.equals(true, x); |
17 | 17 |
18 static void isFalse(x) => Expect.equals(true, x); | 18 static void isFalse(x) => Expect.equals(false, x); |
19 | 19 |
20 static void equals(expected, actual) { | 20 static void equals(expected, actual) { |
21 if (expected != actual) { | 21 if (expected != actual) { |
22 throw "Not equal. Expected: $expected. Got: $actual"; | 22 throw "Not equal. Expected: $expected. Got: $actual"; |
23 } | 23 } |
24 } | 24 } |
25 static void throws(fun, [test]) { | 25 static void throws(fun, [test]) { |
26 try { | 26 try { |
27 fun(); | 27 fun(); |
28 } catch (e) { | 28 } catch (e) { |
(...skipping 19 matching lines...) Expand all Loading... |
48 lazy.load().then((bool didLoad) { | 48 lazy.load().then((bool didLoad) { |
49 Expect.isFalse(didLoad); | 49 Expect.isFalse(didLoad); |
50 Expect.equals(2, ++counter); | 50 Expect.equals(2, ++counter); |
51 print('lazy was loaded'); | 51 print('lazy was loaded'); |
52 Expect.equals(42, foo('b')); | 52 Expect.equals(42, foo('b')); |
53 print('unittest-suite-success'); | 53 print('unittest-suite-success'); |
54 }); | 54 }); |
55 Expect.equals(0, counter); | 55 Expect.equals(0, counter); |
56 Expect.throws(() { foo('a'); }, isNoSuchMethodError); | 56 Expect.throws(() { foo('a'); }, isNoSuchMethodError); |
57 } | 57 } |
OLD | NEW |