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 'dart:async'; | 5 import 'dart:async'; |
6 | 6 |
7 @lazy import 'deferred_class_library.dart'; | 7 @lazy import 'deferred_class_library.dart'; |
8 | 8 |
9 const lazy = const DeferredLibrary('deferred_class_library'); | 9 const lazy = const DeferredLibrary('deferred_class_library'); |
10 | 10 |
11 isNoSuchMethodError(e) => e is NoSuchMethodError; | 11 isNoSuchMethodError(e) => e is NoSuchMethodError; |
12 | 12 |
| 13 class Expect { |
| 14 static void isTrue(x) => expect.equals(true, x); |
| 15 static void equals(expected, actual) { |
| 16 if (expected != actual) { |
| 17 throw "Not equal. Expected: $expected. Got: $actual"; |
| 18 } |
| 19 } |
| 20 static void throws(fun, [test]) { |
| 21 try { |
| 22 fun(); |
| 23 } catch (e) { |
| 24 if (!test(e)) throw "doesn't satisfy exception test"; |
| 25 return; |
| 26 } |
| 27 throw "didn't throw"; |
| 28 } |
| 29 } |
| 30 |
13 main() { | 31 main() { |
14 var x; | 32 var x; |
15 Expect.throws(() { x = new MyClass(); }, isNoSuchMethodError); | 33 Expect.throws(() { x = new MyClass(); }, isNoSuchMethodError); |
16 Expect.isNull(x); | 34 Expect.isNull(x); |
17 int counter = 0; | 35 int counter = 0; |
18 lazy.load().then((bool didLoad) { | 36 lazy.load().then((bool didLoad) { |
19 Expect.isTrue(didLoad); | 37 Expect.isTrue(didLoad); |
20 Expect.equals(1, ++counter); | 38 Expect.equals(1, ++counter); |
21 print('deferred_class_library was loaded'); | 39 print('deferred_class_library was loaded'); |
22 x = new MyClass(); | 40 x = new MyClass(); |
23 Expect.equals(42, x.foo(87)); | 41 Expect.equals(42, x.foo(87)); |
24 }); | 42 }); |
25 Expect.equals(0, counter); | 43 Expect.equals(0, counter); |
26 Expect.isNull(x); | 44 Expect.isNull(x); |
27 lazy.load().then((bool didLoad) { | 45 lazy.load().then((bool didLoad) { |
28 Expect.isFalse(didLoad); | 46 Expect.isFalse(didLoad); |
29 Expect.equals(2, ++counter); | 47 Expect.equals(2, ++counter); |
30 print('deferred_class_library was loaded'); | 48 print('deferred_class_library was loaded'); |
31 x = new MyClass(); | 49 x = new MyClass(); |
32 Expect.equals(42, x.foo(87)); | 50 Expect.equals(42, x.foo(87)); |
33 }); | 51 }); |
34 Expect.equals(0, counter); | 52 Expect.equals(0, counter); |
35 Expect.isNull(x); | 53 Expect.isNull(x); |
36 Expect.throws(() { x = new MyClass(); }, isNoSuchMethodError); | 54 Expect.throws(() { x = new MyClass(); }, isNoSuchMethodError); |
37 Expect.isNull(x); | 55 Expect.isNull(x); |
38 } | 56 } |
OLD | NEW |