Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | |
| 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. | |
| 4 | |
| 5 import "package:expect/expect.dart"; | |
| 6 | |
| 7 confuse(x) { | |
| 8 if (new DateTime.now().millisecondsSinceEpoch == 0) { | |
| 9 return confuse(x + 1); | |
| 10 } else if (new DateTime.now().millisecondsSinceEpoch == 0) { | |
| 11 return confuse(x - 1); | |
| 12 } | |
| 13 return x; | |
| 14 } | |
| 15 | |
| 16 test1() { | |
| 17 int x = 0; | |
| 18 // Give x a range of -1 to 0. | |
| 19 if (confuse(0) == 1) x = -1; | |
| 20 | |
| 21 int y = 0; | |
| 22 // Give x a range of 0 to 1. | |
|
ngeoffray
2014/07/04 22:36:53
x -> y
floitsch
2014/07/07 16:02:49
Done.
| |
| 23 if (confuse(0) == 1) y = 1; | |
| 24 | |
| 25 var zero = 0; | |
| 26 | |
| 27 var status = "bad"; | |
| 28 if (x < zero) { | |
| 29 Expect.fail("unreachable"); | |
| 30 } else { | |
| 31 // Dart2js must not conclude that zero has a range of [-1, 0]. | |
| 32 if (y <= zero) { | |
| 33 status = "good"; | |
| 34 } | |
| 35 } | |
| 36 Expect.equals("good", status); | |
| 37 } | |
| 38 | |
| 39 test2() { | |
| 40 int x = 0; | |
| 41 // Give x a range of -1 to 0. | |
| 42 if (confuse(0) == 1) x = -1; | |
| 43 | |
| 44 int y = 0; | |
| 45 // Give x a range of -1 to 1. | |
|
ngeoffray
2014/07/04 22:36:53
x -> y
floitsch
2014/07/07 16:02:49
Done.
| |
| 46 if (confuse(0) == 1) y = 1; | |
| 47 if (confuse(1) == 2) y = -1; | |
| 48 | |
| 49 var z = 0; | |
|
ngeoffray
2014/07/04 22:36:53
z is unused in this method.
floitsch
2014/07/07 16:02:49
Done.
| |
| 50 // Give z a range of 0 to | |
|
ngeoffray
2014/07/04 22:36:53
0 to 0.
floitsch
2014/07/07 16:02:49
Done.
| |
| 51 | |
| 52 var status = "good"; | |
| 53 if (x < y) { | |
| 54 Expect.fail("unreachable"); | |
| 55 } else { | |
| 56 // Dart2js must not conclude that y has a range of [-1, -1]. | |
| 57 if (y == -1) { | |
| 58 status = "bad"; | |
| 59 } | |
| 60 } | |
| 61 Expect.equals("good", status); | |
| 62 } | |
| 63 | |
| 64 test3a() { | |
| 65 int x = 0; | |
| 66 // Give x a range of -1 to 1. | |
| 67 if (confuse(0) == 1) x = -1; | |
| 68 if (confuse(1) == 2) x = 1; | |
| 69 | |
| 70 int y = 0; | |
| 71 // Give x a range of -1 to 1. | |
|
ngeoffray
2014/07/04 22:36:53
x -> y
floitsch
2014/07/07 16:02:49
Done.
| |
| 72 if (confuse(0) == 1) y = 1; | |
| 73 if (confuse(1) == 2) y = -1; | |
| 74 | |
| 75 var z = 0; | |
|
ngeoffray
2014/07/04 22:36:53
unused z.
floitsch
2014/07/07 16:02:49
Done.
| |
| 76 // Give z a range of 0 to | |
| 77 | |
| 78 var status = "good"; | |
| 79 if (x < y) { | |
| 80 Expect.fail("unreachable"); | |
| 81 } else { | |
| 82 // Test that the range-analysis does not lose a value. | |
| 83 if (x <= -1) status = "bad"; | |
| 84 if (x >= 1) status = "bad"; | |
| 85 if (x < 0) status = "bad"; | |
| 86 if (x > 0) status = "bad"; | |
| 87 if (-1 >= x) status = "bad"; | |
| 88 if (1 <= x) status = "bad"; | |
| 89 if (0 > x) status = "bad"; | |
| 90 if (0 < x) status = "bad"; | |
| 91 if (y <= -1) status = "bad"; | |
| 92 if (y >= 1) status = "bad"; | |
| 93 if (y < 0) status = "bad"; | |
| 94 if (y > 0) status = "bad"; | |
| 95 if (-1 >= y) status = "bad"; | |
| 96 if (1 <= y) status = "bad"; | |
| 97 if (0 > y) status = "bad"; | |
| 98 if (0 < y) status = "bad"; | |
| 99 } | |
| 100 Expect.equals("good", status); | |
| 101 } | |
| 102 | |
| 103 test3b() { | |
| 104 int x = 0; | |
| 105 // Give x a range of -2 to 0. | |
| 106 if (confuse(0) == 1) x = -2; | |
| 107 | |
| 108 int y = 0; | |
| 109 // Give x a range of -1 to 1. | |
|
ngeoffray
2014/07/04 22:36:53
x -> y
floitsch
2014/07/07 16:02:49
Done.
| |
| 110 if (confuse(0) == 1) y = 1; | |
| 111 if (confuse(1) == 2) y = -1; | |
| 112 | |
| 113 var z = 0; | |
| 114 // Give z a range of 0 to | |
|
ngeoffray
2014/07/04 22:36:53
unused
floitsch
2014/07/07 16:02:49
Done.
| |
| 115 | |
| 116 var status = "good"; | |
| 117 if (x < y) { | |
| 118 Expect.fail("unreachable"); | |
| 119 } else { | |
| 120 // Test that the range-analysis does not lose a value. | |
| 121 if (x <= -1) status = "bad"; | |
| 122 if (x >= 1) status = "bad"; | |
| 123 if (x < 0) status = "bad"; | |
| 124 if (x > 0) status = "bad"; | |
| 125 if (-1 >= x) status = "bad"; | |
| 126 if (1 <= x) status = "bad"; | |
| 127 if (0 > x) status = "bad"; | |
| 128 if (0 < x) status = "bad"; | |
| 129 if (y <= -1) status = "bad"; | |
| 130 if (y >= 1) status = "bad"; | |
| 131 if (y < 0) status = "bad"; | |
| 132 if (y > 0) status = "bad"; | |
| 133 if (-1 >= y) status = "bad"; | |
| 134 if (1 <= y) status = "bad"; | |
| 135 if (0 > y) status = "bad"; | |
| 136 if (0 < y) status = "bad"; | |
| 137 } | |
| 138 Expect.equals("good", status); | |
| 139 } | |
| 140 | |
| 141 test4a() { | |
|
ngeoffray
2014/07/04 22:36:53
same comments in this method
floitsch
2014/07/07 16:02:49
Done.
| |
| 142 int x = -1; | |
| 143 // Give x a range of -1 to 1. | |
| 144 if (confuse(0) == 1) x = 1; | |
| 145 | |
| 146 int y = 0; | |
| 147 // Give x a range of -1 to 1. | |
| 148 if (confuse(0) == 1) y = 1; | |
| 149 if (confuse(1) == 2) y = -1; | |
| 150 | |
| 151 var z = 0; | |
| 152 // Give z a range of 0 to | |
| 153 | |
| 154 var status = "good"; | |
| 155 if (x < y) { | |
| 156 // Test that the range-analysis does not lose a value. | |
| 157 if (x <= -2) status = "bad"; | |
| 158 if (x >= 0) status = "bad"; | |
| 159 if (x < -1) status = "bad"; | |
| 160 if (x > -1) status = "bad"; | |
| 161 if (-2 >= x) status = "bad"; | |
| 162 if (0 <= x) status = "bad"; | |
| 163 if (-1 > x) status = "bad"; | |
| 164 if (-1 < x) status = "bad"; | |
| 165 if (y <= -1) status = "bad"; | |
| 166 if (y >= 1) status = "bad"; | |
| 167 if (y < 0) status = "bad"; | |
| 168 if (y > 0) status = "bad"; | |
| 169 if (-1 >= y) status = "bad"; | |
| 170 if (1 <= y) status = "bad"; | |
| 171 if (0 > y) status = "bad"; | |
| 172 if (0 < y) status = "bad"; | |
| 173 } else { | |
| 174 Expect.fail("unreachable"); | |
| 175 } | |
| 176 Expect.equals("good", status); | |
| 177 } | |
| 178 | |
| 179 test4b() { | |
|
ngeoffray
2014/07/04 22:36:53
ditto
floitsch
2014/07/07 16:02:49
Done.
| |
| 180 int x = -1; | |
| 181 // Give x a range of -2 to 0. | |
| 182 if (confuse(0) == 1) x = -2; | |
| 183 if (confuse(1) == 2) x = 0; | |
| 184 | |
| 185 int y = 0; | |
| 186 // Give x a range of -1 to 1. | |
| 187 if (confuse(0) == 1) y = 1; | |
| 188 if (confuse(1) == 2) y = -1; | |
| 189 | |
| 190 var z = 0; | |
| 191 // Give z a range of 0 to | |
| 192 | |
| 193 var status = "good"; | |
| 194 if (x < y) { | |
| 195 // Test that the range-analysis does not lose a value. | |
| 196 if (x <= -2) status = "bad"; | |
| 197 if (x >= 0) status = "bad"; | |
| 198 if (x < -1) status = "bad"; | |
| 199 if (x > -1) status = "bad"; | |
| 200 if (-2 >= x) status = "bad"; | |
| 201 if (0 <= x) status = "bad"; | |
| 202 if (-1 > x) status = "bad"; | |
| 203 if (-1 < x) status = "bad"; | |
| 204 if (y <= -1) status = "bad"; | |
| 205 if (y >= 1) status = "bad"; | |
| 206 if (y < 0) status = "bad"; | |
| 207 if (y > 0) status = "bad"; | |
| 208 if (-1 >= y) status = "bad"; | |
| 209 if (1 <= y) status = "bad"; | |
| 210 if (0 > y) status = "bad"; | |
| 211 if (0 < y) status = "bad"; | |
| 212 } else { | |
| 213 Expect.fail("unreachable"); | |
| 214 } | |
| 215 Expect.equals("good", status); | |
| 216 } | |
| 217 | |
| 218 main() { | |
| 219 test1(); | |
| 220 test2(); | |
| 221 test3a(); | |
| 222 test3b(); | |
| 223 test4a(); | |
| 224 test4b(); | |
| 225 } | |
| OLD | NEW |