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 "package:expect/expect.dart"; |
| 6 import "package:async_helper/async_helper.dart"; |
6 import 'compiler_helper.dart'; | 7 import 'compiler_helper.dart'; |
7 | 8 |
8 const String TEST1 = r""" | 9 const String TEST1 = r""" |
9 main() { | 10 main() { |
10 var a = [42, null]; | 11 var a = [42, null]; |
11 return a[0] + 42; | 12 return a[0] + 42; |
12 } | 13 } |
13 """; | 14 """; |
14 | 15 |
15 const String TEST2 = r""" | 16 const String TEST2 = r""" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 const String TEST6 = r""" | 51 const String TEST6 = r""" |
51 const a = const [1, 2, 3]; | 52 const a = const [1, 2, 3]; |
52 var b = 4; | 53 var b = 4; |
53 main() { | 54 main() { |
54 return 42 + a[b]; | 55 return 42 + a[b]; |
55 } | 56 } |
56 """; | 57 """; |
57 | 58 |
58 | 59 |
59 main() { | 60 main() { |
60 String generated = compileAll(TEST1); | 61 asyncTest(() => compileAll(TEST1).then((generated) { |
61 // Check that we only do a null check on the receiver for | 62 // Check that we only do a null check on the receiver for |
62 // [: a[0] + 42 :]. We can do a null check because we inferred that | 63 // [: a[0] + 42 :]. We can do a null check because we inferred that |
63 // the list is of type int or null. | 64 // the list is of type int or null. |
64 Expect.isFalse(generated.contains('if (typeof t1')); | 65 Expect.isFalse(generated.contains('if (typeof t1')); |
65 Expect.isTrue(generated.contains('if (t1 == null)')); | 66 Expect.isTrue(generated.contains('if (t1 == null)')); |
| 67 })); |
66 | 68 |
67 generated = compileAll(TEST2); | 69 asyncTest(() => compileAll(TEST2).then((generated) { |
68 Expect.isFalse(generated.contains('if (typeof t1')); | 70 Expect.isFalse(generated.contains('if (typeof t1')); |
69 Expect.isTrue(generated.contains('if (t1 == null)')); | 71 Expect.isTrue(generated.contains('if (t1 == null)')); |
| 72 })); |
70 | 73 |
71 generated = compileAll(TEST3); | 74 asyncTest(() => compileAll(TEST3).then((generated) { |
72 Expect.isFalse(generated.contains('if (typeof t1')); | 75 Expect.isFalse(generated.contains('if (typeof t1')); |
73 Expect.isTrue(generated.contains('if (t1 == null)')); | 76 Expect.isTrue(generated.contains('if (t1 == null)')); |
| 77 })); |
74 | 78 |
75 generated = compileAll(TEST4); | 79 asyncTest(() => compileAll(TEST4).then((generated) { |
76 Expect.isFalse(generated.contains('if (typeof t1')); | 80 Expect.isFalse(generated.contains('if (typeof t1')); |
77 Expect.isTrue(generated.contains('if (t1 == null)')); | 81 Expect.isTrue(generated.contains('if (t1 == null)')); |
| 82 })); |
78 | 83 |
79 generated = compileAll(TEST5); | 84 asyncTest(() => compileAll(TEST5).then((generated) { |
80 Expect.isFalse(generated.contains('iae')); | 85 Expect.isFalse(generated.contains('iae')); |
| 86 })); |
81 | 87 |
82 generated = compileAll(TEST6); | 88 asyncTest(() => compileAll(TEST6).then((generated) { |
83 Expect.isFalse(generated.contains('iae')); | 89 Expect.isFalse(generated.contains('iae')); |
| 90 })); |
84 } | 91 } |
OLD | NEW |