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