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