| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
package main |
| 8 |
|
| 9 |
import ( |
| 10 |
"fmt" |
| 11 |
"strings" |
| 12 |
) |
| 13 |
|
| 14 |
func main() { |
| 15 |
TestCheck("TestCheck") |
| 16 |
TestCooperativeBadOfSliceIndex("TestCooperativeBadOfSliceIndex") |
| 17 |
TestCooperativeBadOfSliceIndexCheck("TestCooperativeBadOfSliceIndexCheck") |
| 18 |
TestTrickyIterAll("TestTrickyIterAll") |
| 19 |
TestTrickyIterOne("TestTrickyIterOne") |
| 20 |
TestTrickyIterZero("TestTrickyIterZero") |
| 21 |
TestTrickyIterZeroCheck("TestTrickyIterZeroCheck") |
| 22 |
TestTrickyIterEcho("TestTrickyIterEcho") |
| 23 |
TestTrickyIterEcho2("TestTrickyIterEcho2") |
| 24 |
TestBreak1("TestBreak1") |
| 25 |
TestBreak2("TestBreak2") |
| 26 |
TestContinue("TestContinue") |
| 27 |
TestBreak3("TestBreak3") |
| 28 |
TestBreak1BadA("TestBreak1BadA") |
| 29 |
TestBreak1BadB("TestBreak1BadB") |
| 30 |
TestMultiCont0("TestMultiCont0") |
| 31 |
TestMultiCont1("TestMultiCont1") |
| 32 |
TestMultiCont2("TestMultiCont2") |
| 33 |
TestMultiCont3("TestMultiCont3") |
| 34 |
TestMultiBreak0("TestMultiBreak0") |
| 35 |
TestMultiBreak1("TestMultiBreak1") |
| 36 |
TestMultiBreak2("TestMultiBreak2") |
| 37 |
TestMultiBreak3("TestMultiBreak3") |
| 38 |
TestPanickyIterator1("TestPanickyIterator1") |
| 39 |
TestPanickyIterator1Check("TestPanickyIterator1Check") |
| 40 |
TestPanickyIterator2("TestPanickyIterator2") |
| 41 |
TestPanickyIterator2Check("TestPanickyIterator2Check") |
| 42 |
TestPanickyIterator3("TestPanickyIterator3") |
| 43 |
TestPanickyIterator3Check("TestPanickyIterator3Check") |
| 44 |
TestPanickyIterator4("TestPanickyIterator4") |
| 45 |
TestPanickyIterator4Check("TestPanickyIterator4Check") |
| 46 |
TestVeryBad1("TestVeryBad1") |
| 47 |
TestVeryBad2("TestVeryBad2") |
| 48 |
TestVeryBadCheck("TestVeryBadCheck") |
| 49 |
TestOk("TestOk") |
| 50 |
TestBreak1BadDefer("TestBreak1BadDefer") |
| 51 |
TestReturns("TestReturns") |
| 52 |
TestGotoA("TestGotoA") |
| 53 |
TestGotoB("TestGotoB") |
| 54 |
TestPanicReturns("TestPanicReturns") |
| 55 |
} |
| 56 |
|
| 57 |
type testingT string |
| 58 |
|
| 59 |
func (t testingT) Log(args ...any) { |
| 60 |
s := fmt.Sprint(args...) |
| 61 |
println(t, "\t", s) |
| 62 |
} |
| 63 |
|
| 64 |
func (t testingT) Error(args ...any) { |
| 65 |
s := string(t) + "\terror: " + fmt.Sprint(args...) |
| 66 |
panic(s) |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
func slicesEqual[S ~[]E, E comparable](s1, s2 S) bool { |
| 71 |
if len(s1) != len(s2) { |
| 72 |
return false |
| 73 |
} |
| 74 |
for i := range s1 { |
| 75 |
if s1[i] != s2[i] { |
| 76 |
return false |
| 77 |
} |
| 78 |
} |
| 79 |
return true |
| 80 |
} |
| 81 |
|
| 82 |
type Seq[T any] func(yield func(T) bool) |
| 83 |
type Seq2[T1, T2 any] func(yield func(T1, T2) bool) |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
func OfSliceIndex[T any, S ~[]T](s S) Seq2[int, T] { |
| 88 |
return func(yield func(int, T) bool) { |
| 89 |
for i, v := range s { |
| 90 |
if !yield(i, v) { |
| 91 |
return |
| 92 |
} |
| 93 |
} |
| 94 |
return |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
func BadOfSliceIndex[T any, S ~[]T](s S) Seq2[int, T] { |
| 101 |
return func(yield func(int, T) bool) { |
| 102 |
for i, v := range s { |
| 103 |
yield(i, v) |
| 104 |
} |
| 105 |
return |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
func VeryBadOfSliceIndex[T any, S ~[]T](s S) Seq2[int, T] { |
| 113 |
return func(yield func(int, T) bool) { |
| 114 |
for i, v := range s { |
| 115 |
func() { |
| 116 |
defer func() { |
| 117 |
recover() |
| 118 |
}() |
| 119 |
yield(i, v) |
| 120 |
}() |
| 121 |
} |
| 122 |
return |
| 123 |
} |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
func SwallowPanicOfSliceIndex[T any, S ~[]T](s S) Seq2[int, T] { |
| 128 |
return func(yield func(int, T) bool) { |
| 129 |
for i, v := range s { |
| 130 |
done := false |
| 131 |
func() { |
| 132 |
defer func() { |
| 133 |
if r := recover(); r != nil { |
| 134 |
done = true |
| 135 |
} |
| 136 |
}() |
| 137 |
done = !yield(i, v) |
| 138 |
}() |
| 139 |
if done { |
| 140 |
return |
| 141 |
} |
| 142 |
} |
| 143 |
return |
| 144 |
} |
| 145 |
} |
| 146 |
|
| 147 |
|
| 148 |
func PanickyOfSliceIndex[T any, S ~[]T](s S) Seq2[int, T] { |
| 149 |
return func(yield func(int, T) bool) { |
| 150 |
for i, v := range s { |
| 151 |
if !yield(i, v) { |
| 152 |
panic("Panicky iterator panicking") |
| 153 |
} |
| 154 |
} |
| 155 |
return |
| 156 |
} |
| 157 |
} |
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
func CooperativeBadOfSliceIndex[T any, S ~[]T](s S, proceed chan any) Seq2[int, T] { |
| 162 |
return func(yield func(int, T) bool) { |
| 163 |
for i, v := range s { |
| 164 |
if !yield(i, v) { |
| 165 |
|
| 166 |
go func() { |
| 167 |
<-proceed |
| 168 |
defer func() { |
| 169 |
proceed <- recover() |
| 170 |
}() |
| 171 |
yield(0, s[0]) |
| 172 |
}() |
| 173 |
return |
| 174 |
} |
| 175 |
} |
| 176 |
return |
| 177 |
} |
| 178 |
} |
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
type TrickyIterator struct { |
| 184 |
yield func(int, int) bool |
| 185 |
} |
| 186 |
|
| 187 |
func (ti *TrickyIterator) iterEcho(s []int) Seq2[int, int] { |
| 188 |
return func(yield func(int, int) bool) { |
| 189 |
for i, v := range s { |
| 190 |
if !yield(i, v) { |
| 191 |
ti.yield = yield |
| 192 |
return |
| 193 |
} |
| 194 |
if ti.yield != nil && !ti.yield(i, v) { |
| 195 |
return |
| 196 |
} |
| 197 |
} |
| 198 |
ti.yield = yield |
| 199 |
return |
| 200 |
} |
| 201 |
} |
| 202 |
|
| 203 |
func (ti *TrickyIterator) iterAll(s []int) Seq2[int, int] { |
| 204 |
return func(yield func(int, int) bool) { |
| 205 |
ti.yield = yield |
| 206 |
for i, v := range s { |
| 207 |
if !yield(i, v) { |
| 208 |
return |
| 209 |
} |
| 210 |
} |
| 211 |
return |
| 212 |
} |
| 213 |
} |
| 214 |
func (ti *TrickyIterator) iterOne(s []int) Seq2[int, int] { |
| 215 |
return func(yield func(int, int) bool) { |
| 216 |
ti.yield = yield |
| 217 |
if len(s) > 0 { |
| 218 |
yield(0, s[0]) |
| 219 |
} |
| 220 |
return |
| 221 |
} |
| 222 |
} |
| 223 |
func (ti *TrickyIterator) iterZero(s []int) Seq2[int, int] { |
| 224 |
return func(yield func(int, int) bool) { |
| 225 |
ti.yield = yield |
| 226 |
|
| 227 |
return |
| 228 |
} |
| 229 |
} |
| 230 |
func (ti *TrickyIterator) fail() { |
| 231 |
if ti.yield != nil { |
| 232 |
ti.yield(1, 1) |
| 233 |
} |
| 234 |
} |
| 235 |
|
| 236 |
func matchError(r any, x string) bool { |
| 237 |
if r == nil { |
| 238 |
return false |
| 239 |
} |
| 240 |
if x == "" { |
| 241 |
return true |
| 242 |
} |
| 243 |
switch p := r.(type) { |
| 244 |
case string: |
| 245 |
return p == x |
| 246 |
case errorString: |
| 247 |
return p.Error() == x |
| 248 |
case error: |
| 249 |
return strings.Contains(p.Error(), x) |
| 250 |
} |
| 251 |
return false |
| 252 |
} |
| 253 |
|
| 254 |
func matchErrorHelper(t testingT, r any, x string) { |
| 255 |
if matchError(r, x) { |
| 256 |
t.Log("Saw expected panic: ", r) |
| 257 |
} else { |
| 258 |
t.Error("Saw wrong panic: '", r, "' . expected '", x, "'") |
| 259 |
} |
| 260 |
} |
| 261 |
|
| 262 |
const DONE = 0 |
| 263 |
const READY = 1 |
| 264 |
const PANIC = 2 |
| 265 |
const EXHAUSTED = 3 |
| 266 |
const MISSING_PANIC = 4 |
| 267 |
|
| 268 |
|
| 269 |
type errorString string |
| 270 |
|
| 271 |
func (e errorString) Error() string { |
| 272 |
return string(e) |
| 273 |
} |
| 274 |
|
| 275 |
const ( |
| 276 |
|
| 277 |
RERR_DONE = "yield function called after range loop exit" |
| 278 |
RERR_PANIC = "range function continued iteration after loop body panic" |
| 279 |
RERR_EXHAUSTED = "yield function called after range loop exit" |
| 280 |
RERR_MISSING = "iterator call did not preserve panic" |
| 281 |
|
| 282 |
|
| 283 |
CERR_PFX = "checked rangefunc error: " |
| 284 |
CERR_DONE = CERR_PFX + "loop iteration after body done" |
| 285 |
CERR_PANIC = CERR_PFX + "loop iteration after panic" |
| 286 |
CERR_EXHAUSTED = CERR_PFX + "loop iteration after iterator exit" |
| 287 |
CERR_MISSING = CERR_PFX + "loop iterator swallowed panic" |
| 288 |
) |
| 289 |
|
| 290 |
var fail []error = []error{ |
| 291 |
errorString(CERR_DONE), |
| 292 |
errorString(CERR_PFX + "loop iterator, unexpected error"), |
| 293 |
errorString(CERR_PANIC), |
| 294 |
errorString(CERR_EXHAUSTED), |
| 295 |
errorString(CERR_MISSING), |
| 296 |
} |
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
func Check[U, V any](forall Seq2[U, V]) Seq2[U, V] { |
| 305 |
return func(body func(U, V) bool) { |
| 306 |
state := READY |
| 307 |
forall(func(u U, v V) bool { |
| 308 |
if state != READY { |
| 309 |
panic(fail[state]) |
| 310 |
} |
| 311 |
state = PANIC |
| 312 |
ret := body(u, v) |
| 313 |
if ret { |
| 314 |
state = READY |
| 315 |
} else { |
| 316 |
state = DONE |
| 317 |
} |
| 318 |
return ret |
| 319 |
}) |
| 320 |
if state == PANIC { |
| 321 |
panic(fail[MISSING_PANIC]) |
| 322 |
} |
| 323 |
state = EXHAUSTED |
| 324 |
} |
| 325 |
} |
| 326 |
|
| 327 |
func TestCheck(t testingT) { |
| 328 |
i := 0 |
| 329 |
defer func() { |
| 330 |
t.Log("i = ", i) |
| 331 |
matchErrorHelper(t, recover(), CERR_DONE) |
| 332 |
}() |
| 333 |
for _, x := range Check(BadOfSliceIndex([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10})) { |
| 334 |
i += x |
| 335 |
if i > 4*9 { |
| 336 |
break |
| 337 |
} |
| 338 |
} |
| 339 |
} |
| 340 |
|
| 341 |
func TestCooperativeBadOfSliceIndex(t testingT) { |
| 342 |
i := 0 |
| 343 |
proceed := make(chan any) |
| 344 |
for _, x := range CooperativeBadOfSliceIndex([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, proceed) { |
| 345 |
i += x |
| 346 |
if i >= 36 { |
| 347 |
break |
| 348 |
} |
| 349 |
} |
| 350 |
proceed <- true |
| 351 |
r := <-proceed |
| 352 |
matchErrorHelper(t, r, RERR_EXHAUSTED) |
| 353 |
if i != 36 { |
| 354 |
t.Error("Expected i == 36, saw ", i, "instead") |
| 355 |
} else { |
| 356 |
t.Log("i = ", i) |
| 357 |
} |
| 358 |
} |
| 359 |
|
| 360 |
func TestCooperativeBadOfSliceIndexCheck(t testingT) { |
| 361 |
i := 0 |
| 362 |
proceed := make(chan any) |
| 363 |
for _, x := range Check(CooperativeBadOfSliceIndex([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, proceed)) { |
| 364 |
i += x |
| 365 |
if i >= 36 { |
| 366 |
break |
| 367 |
} |
| 368 |
} |
| 369 |
proceed <- true |
| 370 |
r := <-proceed |
| 371 |
matchErrorHelper(t, r, CERR_EXHAUSTED) |
| 372 |
|
| 373 |
if i != 36 { |
| 374 |
t.Error("Expected i == 36, saw ", i, "instead") |
| 375 |
} else { |
| 376 |
t.Log("i = ", i) |
| 377 |
} |
| 378 |
} |
| 379 |
|
| 380 |
func TestTrickyIterAll(t testingT) { |
| 381 |
trickItAll := TrickyIterator{} |
| 382 |
i := 0 |
| 383 |
for _, x := range trickItAll.iterAll([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) { |
| 384 |
i += x |
| 385 |
if i >= 36 { |
| 386 |
break |
| 387 |
} |
| 388 |
} |
| 389 |
if i != 36 { |
| 390 |
t.Error("Expected i == 36, saw ", i, " instead") |
| 391 |
} else { |
| 392 |
t.Log("i = ", i) |
| 393 |
} |
| 394 |
defer func() { |
| 395 |
matchErrorHelper(t, recover(), RERR_EXHAUSTED) |
| 396 |
}() |
| 397 |
trickItAll.fail() |
| 398 |
} |
| 399 |
|
| 400 |
func TestTrickyIterOne(t testingT) { |
| 401 |
trickItOne := TrickyIterator{} |
| 402 |
i := 0 |
| 403 |
for _, x := range trickItOne.iterOne([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) { |
| 404 |
i += x |
| 405 |
if i >= 36 { |
| 406 |
break |
| 407 |
} |
| 408 |
} |
| 409 |
if i != 1 { |
| 410 |
t.Error("Expected i == 1, saw ", i, " instead") |
| 411 |
} else { |
| 412 |
t.Log("i = ", i) |
| 413 |
} |
| 414 |
defer func() { |
| 415 |
matchErrorHelper(t, recover(), RERR_EXHAUSTED) |
| 416 |
}() |
| 417 |
trickItOne.fail() |
| 418 |
} |
| 419 |
|
| 420 |
func TestTrickyIterZero(t testingT) { |
| 421 |
trickItZero := TrickyIterator{} |
| 422 |
i := 0 |
| 423 |
for _, x := range trickItZero.iterZero([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) { |
| 424 |
i += x |
| 425 |
if i >= 36 { |
| 426 |
break |
| 427 |
} |
| 428 |
} |
| 429 |
|
| 430 |
t.Log("i = ", i) |
| 431 |
defer func() { |
| 432 |
matchErrorHelper(t, recover(), RERR_EXHAUSTED) |
| 433 |
}() |
| 434 |
trickItZero.fail() |
| 435 |
} |
| 436 |
|
| 437 |
func TestTrickyIterZeroCheck(t testingT) { |
| 438 |
trickItZero := TrickyIterator{} |
| 439 |
i := 0 |
| 440 |
for _, x := range Check(trickItZero.iterZero([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10})) { |
| 441 |
i += x |
| 442 |
if i >= 36 { |
| 443 |
break |
| 444 |
} |
| 445 |
} |
| 446 |
|
| 447 |
t.Log("i = ", i) |
| 448 |
defer func() { |
| 449 |
matchErrorHelper(t, recover(), CERR_EXHAUSTED) |
| 450 |
}() |
| 451 |
trickItZero.fail() |
| 452 |
} |
| 453 |
|
| 454 |
func TestTrickyIterEcho(t testingT) { |
| 455 |
trickItAll := TrickyIterator{} |
| 456 |
i := 0 |
| 457 |
for _, x := range trickItAll.iterAll([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) { |
| 458 |
t.Log("first loop i=", i) |
| 459 |
i += x |
| 460 |
if i >= 10 { |
| 461 |
break |
| 462 |
} |
| 463 |
} |
| 464 |
|
| 465 |
if i != 10 { |
| 466 |
t.Error("Expected i == 10, saw", i, "instead") |
| 467 |
} else { |
| 468 |
t.Log("i = ", i) |
| 469 |
} |
| 470 |
|
| 471 |
defer func() { |
| 472 |
matchErrorHelper(t, recover(), RERR_EXHAUSTED) |
| 473 |
t.Log("end i=", i) |
| 474 |
}() |
| 475 |
|
| 476 |
i = 0 |
| 477 |
for _, x := range trickItAll.iterEcho([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) { |
| 478 |
t.Log("second loop i=", i) |
| 479 |
if x >= 5 { |
| 480 |
break |
| 481 |
} |
| 482 |
} |
| 483 |
|
| 484 |
} |
| 485 |
|
| 486 |
func TestTrickyIterEcho2(t testingT) { |
| 487 |
trickItAll := TrickyIterator{} |
| 488 |
var i int |
| 489 |
|
| 490 |
defer func() { |
| 491 |
matchErrorHelper(t, recover(), RERR_EXHAUSTED) |
| 492 |
t.Log("end i=", i) |
| 493 |
}() |
| 494 |
|
| 495 |
for k := range 2 { |
| 496 |
i = 0 |
| 497 |
for _, x := range trickItAll.iterEcho([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) { |
| 498 |
t.Log("k=", k, ",x=", x, ",i=", i) |
| 499 |
i += x |
| 500 |
if i >= 10 { |
| 501 |
break |
| 502 |
} |
| 503 |
} |
| 504 |
t.Log("i = ", i) |
| 505 |
|
| 506 |
if i != 10 { |
| 507 |
t.Error("Expected i == 10, saw ", i, "instead") |
| 508 |
} |
| 509 |
} |
| 510 |
} |
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
func TestBreak1(t testingT) { |
| 515 |
var result []int |
| 516 |
var expect = []int{1, 2, -1, 1, 2, -2, 1, 2, -3} |
| 517 |
for _, x := range OfSliceIndex([]int{-1, -2, -3, -4}) { |
| 518 |
if x == -4 { |
| 519 |
break |
| 520 |
} |
| 521 |
for _, y := range OfSliceIndex([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) { |
| 522 |
if y == 3 { |
| 523 |
break |
| 524 |
} |
| 525 |
result = append(result, y) |
| 526 |
} |
| 527 |
result = append(result, x) |
| 528 |
} |
| 529 |
t.Log(result) |
| 530 |
if !slicesEqual(expect, result) { |
| 531 |
t.Error("Expected ", expect, " got ", result) |
| 532 |
} |
| 533 |
} |
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
func TestBreak2(t testingT) { |
| 538 |
var result []int |
| 539 |
var expect = []int{1, 2, -1, 1, 2, -2, 1, 2, -3} |
| 540 |
outer: |
| 541 |
for _, x := range OfSliceIndex([]int{-1, -2, -3, -4}) { |
| 542 |
for _, y := range OfSliceIndex([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) { |
| 543 |
if y == 3 { |
| 544 |
break |
| 545 |
} |
| 546 |
if x == -4 { |
| 547 |
break outer |
| 548 |
} |
| 549 |
result = append(result, y) |
| 550 |
} |
| 551 |
result = append(result, x) |
| 552 |
} |
| 553 |
t.Log(result) |
| 554 |
if !slicesEqual(expect, result) { |
| 555 |
t.Error("Expected ", expect, ", got ", result) |
| 556 |
} |
| 557 |
} |
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
func TestContinue(t testingT) { |
| 562 |
var result []int |
| 563 |
var expect = []int{-1, 1, 2, -2, 1, 2, -3, 1, 2, -4} |
| 564 |
outer: |
| 565 |
for _, x := range OfSliceIndex([]int{-1, -2, -3, -4}) { |
| 566 |
result = append(result, x) |
| 567 |
for _, y := range OfSliceIndex([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) { |
| 568 |
if y == 3 { |
| 569 |
continue outer |
| 570 |
} |
| 571 |
if x == -4 { |
| 572 |
break outer |
| 573 |
} |
| 574 |
result = append(result, y) |
| 575 |
} |
| 576 |
result = append(result, x-10) |
| 577 |
} |
| 578 |
t.Log(result) |
| 579 |
if !slicesEqual(expect, result) { |
| 580 |
t.Error("Expected ", expect, ", got ", result) |
| 581 |
} |
| 582 |
} |
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
func TestBreak3(t testingT) { |
| 587 |
var result []int |
| 588 |
var expect = []int{100, 10, 2, 4, 200, 10, 2, 4, 20, 2, 4, 300, 10, 2, 4, 20, 2, 4, 30} |
| 589 |
X: |
| 590 |
for _, x := range OfSliceIndex([]int{100, 200, 300, 400}) { |
| 591 |
Y: |
| 592 |
for _, y := range OfSliceIndex([]int{10, 20, 30, 40}) { |
| 593 |
if 10*y >= x { |
| 594 |
break |
| 595 |
} |
| 596 |
result = append(result, y) |
| 597 |
if y == 30 { |
| 598 |
continue X |
| 599 |
} |
| 600 |
Z: |
| 601 |
for _, z := range OfSliceIndex([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) { |
| 602 |
if z&1 == 1 { |
| 603 |
continue Z |
| 604 |
} |
| 605 |
result = append(result, z) |
| 606 |
if z >= 4 { |
| 607 |
continue Y |
| 608 |
} |
| 609 |
} |
| 610 |
result = append(result, -y) |
| 611 |
} |
| 612 |
result = append(result, x) |
| 613 |
} |
| 614 |
t.Log(result) |
| 615 |
if !slicesEqual(expect, result) { |
| 616 |
t.Error("Expected ", expect, ", got ", result) |
| 617 |
} |
| 618 |
} |
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
func TestBreak1BadA(t testingT) { |
| 623 |
var result []int |
| 624 |
var expect = []int{1, 2, -1, 1, 2, -2, 1, 2, -3} |
| 625 |
defer func() { |
| 626 |
t.Log(result) |
| 627 |
matchErrorHelper(t, recover(), RERR_DONE) |
| 628 |
if !slicesEqual(expect, result) { |
| 629 |
t.Error("Expected ", expect, ", got ", result) |
| 630 |
} |
| 631 |
}() |
| 632 |
for _, x := range BadOfSliceIndex([]int{-1, -2, -3, -4, -5}) { |
| 633 |
if x == -4 { |
| 634 |
break |
| 635 |
} |
| 636 |
for _, y := range OfSliceIndex([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) { |
| 637 |
if y == 3 { |
| 638 |
break |
| 639 |
} |
| 640 |
result = append(result, y) |
| 641 |
} |
| 642 |
result = append(result, x) |
| 643 |
} |
| 644 |
} |
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
func TestBreak1BadB(t testingT) { |
| 649 |
var result []int |
| 650 |
var expect = []int{1, 2} |
| 651 |
defer func() { |
| 652 |
t.Log(result) |
| 653 |
matchErrorHelper(t, recover(), RERR_DONE) |
| 654 |
if !slicesEqual(expect, result) { |
| 655 |
t.Error("Expected ", expect, ", got", result) |
| 656 |
} |
| 657 |
}() |
| 658 |
for _, x := range OfSliceIndex([]int{-1, -2, -3, -4, -5}) { |
| 659 |
if x == -4 { |
| 660 |
break |
| 661 |
} |
| 662 |
for _, y := range BadOfSliceIndex([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) { |
| 663 |
if y == 3 { |
| 664 |
break |
| 665 |
} |
| 666 |
result = append(result, y) |
| 667 |
} |
| 668 |
result = append(result, x) |
| 669 |
} |
| 670 |
} |
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
func TestMultiCont0(t testingT) { |
| 675 |
var result []int |
| 676 |
var expect = []int{1000, 10, 2, 4, 2000} |
| 677 |
W: |
| 678 |
for _, w := range OfSliceIndex([]int{1000, 2000}) { |
| 679 |
result = append(result, w) |
| 680 |
if w == 2000 { |
| 681 |
break |
| 682 |
} |
| 683 |
for _, x := range OfSliceIndex([]int{100, 200, 300, 400}) { |
| 684 |
for _, y := range OfSliceIndex([]int{10, 20, 30, 40}) { |
| 685 |
result = append(result, y) |
| 686 |
for _, z := range OfSliceIndex([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) { |
| 687 |
if z&1 == 1 { |
| 688 |
continue |
| 689 |
} |
| 690 |
result = append(result, z) |
| 691 |
if z >= 4 { |
| 692 |
continue W |
| 693 |
} |
| 694 |
} |
| 695 |
result = append(result, -y) |
| 696 |
} |
| 697 |
result = append(result, x) |
| 698 |
} |
| 699 |
} |
| 700 |
t.Log(result) |
| 701 |
if !slicesEqual(expect, result) { |
| 702 |
t.Error("Expected ", expect, ", got %v", expect, result) |
| 703 |
} |
| 704 |
} |
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
func TestMultiCont1(t testingT) { |
| 709 |
var result []int |
| 710 |
var expect = []int{1000, 10, 2, 4} |
| 711 |
defer func() { |
| 712 |
t.Log(result) |
| 713 |
matchErrorHelper(t, recover(), RERR_DONE) |
| 714 |
if !slicesEqual(expect, result) { |
| 715 |
t.Error("Expected ", expect, ", got", result) |
| 716 |
} |
| 717 |
}() |
| 718 |
W: |
| 719 |
for _, w := range OfSliceIndex([]int{1000, 2000}) { |
| 720 |
result = append(result, w) |
| 721 |
if w == 2000 { |
| 722 |
break |
| 723 |
} |
| 724 |
for _, x := range BadOfSliceIndex([]int{100, 200, 300, 400}) { |
| 725 |
for _, y := range OfSliceIndex([]int{10, 20, 30, 40}) { |
| 726 |
result = append(result, y) |
| 727 |
for _, z := range OfSliceIndex([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) { |
| 728 |
if z&1 == 1 { |
| 729 |
continue |
| 730 |
} |
| 731 |
result = append(result, z) |
| 732 |
if z >= 4 { |
| 733 |
continue W |
| 734 |
} |
| 735 |
} |
| 736 |
result = append(result, -y) |
| 737 |
} |
| 738 |
result = append(result, x) |
| 739 |
} |
| 740 |
} |
| 741 |
if !slicesEqual(expect, result) { |
| 742 |
t.Error("Expected ", expect, ", got", result) |
| 743 |
} |
| 744 |
} |
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
func TestMultiCont2(t testingT) { |
| 749 |
var result []int |
| 750 |
var expect = []int{1000, 10, 2, 4} |
| 751 |
defer func() { |
| 752 |
t.Log(result) |
| 753 |
matchErrorHelper(t, recover(), RERR_DONE) |
| 754 |
if !slicesEqual(expect, result) { |
| 755 |
t.Error("Expected ", expect, ", got", result) |
| 756 |
} |
| 757 |
}() |
| 758 |
W: |
| 759 |
for _, w := range OfSliceIndex([]int{1000, 2000}) { |
| 760 |
result = append(result, w) |
| 761 |
if w == 2000 { |
| 762 |
break |
| 763 |
} |
| 764 |
for _, x := range OfSliceIndex([]int{100, 200, 300, 400}) { |
| 765 |
for _, y := range BadOfSliceIndex([]int{10, 20, 30, 40}) { |
| 766 |
result = append(result, y) |
| 767 |
for _, z := range OfSliceIndex([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) { |
| 768 |
if z&1 == 1 { |
| 769 |
continue |
| 770 |
} |
| 771 |
result = append(result, z) |
| 772 |
if z >= 4 { |
| 773 |
continue W |
| 774 |
} |
| 775 |
} |
| 776 |
result = append(result, -y) |
| 777 |
} |
| 778 |
result = append(result, x) |
| 779 |
} |
| 780 |
} |
| 781 |
if !slicesEqual(expect, result) { |
| 782 |
t.Error("Expected ", expect, ", got", result) |
| 783 |
} |
| 784 |
} |
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
func TestMultiCont3(t testingT) { |
| 789 |
var result []int |
| 790 |
var expect = []int{1000, 10, 2, 4} |
| 791 |
defer func() { |
| 792 |
t.Log(result) |
| 793 |
matchErrorHelper(t, recover(), RERR_DONE) |
| 794 |
if !slicesEqual(expect, result) { |
| 795 |
t.Error("Expected ", expect, ", got", result) |
| 796 |
} |
| 797 |
}() |
| 798 |
W: |
| 799 |
for _, w := range OfSliceIndex([]int{1000, 2000}) { |
| 800 |
result = append(result, w) |
| 801 |
if w == 2000 { |
| 802 |
break |
| 803 |
} |
| 804 |
for _, x := range OfSliceIndex([]int{100, 200, 300, 400}) { |
| 805 |
for _, y := range OfSliceIndex([]int{10, 20, 30, 40}) { |
| 806 |
result = append(result, y) |
| 807 |
for _, z := range BadOfSliceIndex([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) { |
| 808 |
if z&1 == 1 { |
| 809 |
continue |
| 810 |
} |
| 811 |
result = append(result, z) |
| 812 |
if z >= 4 { |
| 813 |
continue W |
| 814 |
} |
| 815 |
} |
| 816 |
result = append(result, -y) |
| 817 |
} |
| 818 |
result = append(result, x) |
| 819 |
} |
| 820 |
} |
| 821 |
if !slicesEqual(expect, result) { |
| 822 |
t.Error("Expected ", expect, ", got", result) |
| 823 |
} |
| 824 |
} |
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
func TestMultiBreak0(t testingT) { |
| 829 |
var result []int |
| 830 |
var expect = []int{1000, 10, 2, 4} |
| 831 |
defer func() { |
| 832 |
t.Log(result) |
| 833 |
matchErrorHelper(t, recover(), RERR_DONE) |
| 834 |
if !slicesEqual(expect, result) { |
| 835 |
t.Error("Expected ", expect, ", got", result) |
| 836 |
} |
| 837 |
}() |
| 838 |
W: |
| 839 |
for _, w := range BadOfSliceIndex([]int{1000, 2000}) { |
| 840 |
result = append(result, w) |
| 841 |
if w == 2000 { |
| 842 |
break |
| 843 |
} |
| 844 |
for _, x := range OfSliceIndex([]int{100, 200, 300, 400}) { |
| 845 |
for _, y := range OfSliceIndex([]int{10, 20, 30, 40}) { |
| 846 |
result = append(result, y) |
| 847 |
for _, z := range OfSliceIndex([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) { |
| 848 |
if z&1 == 1 { |
| 849 |
continue |
| 850 |
} |
| 851 |
result = append(result, z) |
| 852 |
if z >= 4 { |
| 853 |
break W |
| 854 |
} |
| 855 |
} |
| 856 |
result = append(result, -y) |
| 857 |
} |
| 858 |
result = append(result, x) |
| 859 |
} |
| 860 |
} |
| 861 |
if !slicesEqual(expect, result) { |
| 862 |
t.Error("Expected ", expect, ", got", result) |
| 863 |
} |
| 864 |
} |
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
func TestMultiBreak1(t testingT) { |
| 869 |
var result []int |
| 870 |
var expect = []int{1000, 10, 2, 4} |
| 871 |
defer func() { |
| 872 |
t.Log(result) |
| 873 |
matchErrorHelper(t, recover(), RERR_DONE) |
| 874 |
if !slicesEqual(expect, result) { |
| 875 |
t.Error("Expected ", expect, ", got", result) |
| 876 |
} |
| 877 |
}() |
| 878 |
W: |
| 879 |
for _, w := range OfSliceIndex([]int{1000, 2000}) { |
| 880 |
result = append(result, w) |
| 881 |
if w == 2000 { |
| 882 |
break |
| 883 |
} |
| 884 |
for _, x := range BadOfSliceIndex([]int{100, 200, 300, 400}) { |
| 885 |
for _, y := range OfSliceIndex([]int{10, 20, 30, 40}) { |
| 886 |
result = append(result, y) |
| 887 |
for _, z := range OfSliceIndex([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) { |
| 888 |
if z&1 == 1 { |
| 889 |
continue |
| 890 |
} |
| 891 |
result = append(result, z) |
| 892 |
if z >= 4 { |
| 893 |
break W |
| 894 |
} |
| 895 |
} |
| 896 |
result = append(result, -y) |
| 897 |
} |
| 898 |
result = append(result, x) |
| 899 |
} |
| 900 |
} |
| 901 |
if !slicesEqual(expect, result) { |
| 902 |
t.Error("Expected ", expect, ", got", result) |
| 903 |
} |
| 904 |
} |
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
func TestMultiBreak2(t testingT) { |
| 909 |
var result []int |
| 910 |
var expect = []int{1000, 10, 2, 4} |
| 911 |
defer func() { |
| 912 |
t.Log(result) |
| 913 |
matchErrorHelper(t, recover(), RERR_DONE) |
| 914 |
if !slicesEqual(expect, result) { |
| 915 |
t.Error("Expected ", expect, ", got", result) |
| 916 |
} |
| 917 |
}() |
| 918 |
W: |
| 919 |
for _, w := range OfSliceIndex([]int{1000, 2000}) { |
| 920 |
result = append(result, w) |
| 921 |
if w == 2000 { |
| 922 |
break |
| 923 |
} |
| 924 |
for _, x := range BadOfSliceIndex([]int{100, 200, 300, 400}) { |
| 925 |
for _, y := range BadOfSliceIndex([]int{10, 20, 30, 40}) { |
| 926 |
result = append(result, y) |
| 927 |
for _, z := range OfSliceIndex([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) { |
| 928 |
if z&1 == 1 { |
| 929 |
continue |
| 930 |
} |
| 931 |
result = append(result, z) |
| 932 |
if z >= 4 { |
| 933 |
break W |
| 934 |
} |
| 935 |
} |
| 936 |
result = append(result, -y) |
| 937 |
} |
| 938 |
result = append(result, x) |
| 939 |
} |
| 940 |
} |
| 941 |
if !slicesEqual(expect, result) { |
| 942 |
t.Error("Expected ", expect, ", got", result) |
| 943 |
} |
| 944 |
} |
| 945 |
|
| 946 |
|
| 947 |
|
| 948 |
func TestMultiBreak3(t testingT) { |
| 949 |
var result []int |
| 950 |
var expect = []int{1000, 10, 2, 4} |
| 951 |
defer func() { |
| 952 |
t.Log(result) |
| 953 |
matchErrorHelper(t, recover(), RERR_DONE) |
| 954 |
if !slicesEqual(expect, result) { |
| 955 |
t.Error("Expected ", expect, ", got", result) |
| 956 |
} |
| 957 |
}() |
| 958 |
W: |
| 959 |
for _, w := range OfSliceIndex([]int{1000, 2000}) { |
| 960 |
result = append(result, w) |
| 961 |
if w == 2000 { |
| 962 |
break |
| 963 |
} |
| 964 |
for _, x := range OfSliceIndex([]int{100, 200, 300, 400}) { |
| 965 |
for _, y := range OfSliceIndex([]int{10, 20, 30, 40}) { |
| 966 |
result = append(result, y) |
| 967 |
for _, z := range BadOfSliceIndex([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) { |
| 968 |
if z&1 == 1 { |
| 969 |
continue |
| 970 |
} |
| 971 |
result = append(result, z) |
| 972 |
if z >= 4 { |
| 973 |
break W |
| 974 |
} |
| 975 |
} |
| 976 |
result = append(result, -y) |
| 977 |
} |
| 978 |
result = append(result, x) |
| 979 |
} |
| 980 |
} |
| 981 |
if !slicesEqual(expect, result) { |
| 982 |
t.Error("Expected ", expect, ", got", result) |
| 983 |
} |
| 984 |
} |
| 985 |
|
| 986 |
func TestPanickyIterator1(t testingT) { |
| 987 |
var result []int |
| 988 |
var expect = []int{1, 2, 3, 4} |
| 989 |
defer func() { |
| 990 |
matchErrorHelper(t, recover(), "Panicky iterator panicking") |
| 991 |
if !slicesEqual(expect, result) { |
| 992 |
t.Error("Expected ", expect, ", got ", result) |
| 993 |
} |
| 994 |
}() |
| 995 |
for _, z := range PanickyOfSliceIndex([]int{1, 2, 3, 4}) { |
| 996 |
result = append(result, z) |
| 997 |
if z == 4 { |
| 998 |
break |
| 999 |
} |
| 1000 |
} |
| 1001 |
} |
| 1002 |
|
| 1003 |
func TestPanickyIterator1Check(t testingT) { |
| 1004 |
var result []int |
| 1005 |
var expect = []int{1, 2, 3, 4} |
| 1006 |
defer func() { |
| 1007 |
matchErrorHelper(t, recover(), "Panicky iterator panicking") |
| 1008 |
if !slicesEqual(expect, result) { |
| 1009 |
t.Error("Expected ", expect, ", got ", result) |
| 1010 |
} |
| 1011 |
}() |
| 1012 |
for _, z := range Check(PanickyOfSliceIndex([]int{1, 2, 3, 4})) { |
| 1013 |
result = append(result, z) |
| 1014 |
if z == 4 { |
| 1015 |
break |
| 1016 |
} |
| 1017 |
} |
| 1018 |
} |
| 1019 |
|
| 1020 |
func TestPanickyIterator2(t testingT) { |
| 1021 |
var result []int |
| 1022 |
var expect = []int{100, 10, 1, 2} |
| 1023 |
defer func() { |
| 1024 |
matchErrorHelper(t, recover(), RERR_MISSING) |
| 1025 |
if !slicesEqual(expect, result) { |
| 1026 |
t.Error("Expected ", expect, ", got ", result) |
| 1027 |
} |
| 1028 |
}() |
| 1029 |
for _, x := range OfSliceIndex([]int{100, 200}) { |
| 1030 |
result = append(result, x) |
| 1031 |
Y: |
| 1032 |
|
| 1033 |
for _, y := range VeryBadOfSliceIndex([]int{10, 20}) { |
| 1034 |
result = append(result, y) |
| 1035 |
|
| 1036 |
|
| 1037 |
for k, z := range PanickyOfSliceIndex([]int{1, 2}) { |
| 1038 |
result = append(result, z) |
| 1039 |
if k == 1 { |
| 1040 |
break Y |
| 1041 |
} |
| 1042 |
} |
| 1043 |
} |
| 1044 |
} |
| 1045 |
} |
| 1046 |
|
| 1047 |
func TestPanickyIterator2Check(t testingT) { |
| 1048 |
var result []int |
| 1049 |
var expect = []int{100, 10, 1, 2} |
| 1050 |
defer func() { |
| 1051 |
matchErrorHelper(t, recover(), CERR_MISSING) |
| 1052 |
if !slicesEqual(expect, result) { |
| 1053 |
t.Error("Expected ", expect, ", got ", result) |
| 1054 |
} |
| 1055 |
}() |
| 1056 |
for _, x := range Check(OfSliceIndex([]int{100, 200})) { |
| 1057 |
result = append(result, x) |
| 1058 |
Y: |
| 1059 |
|
| 1060 |
for _, y := range Check(VeryBadOfSliceIndex([]int{10, 20})) { |
| 1061 |
result = append(result, y) |
| 1062 |
|
| 1063 |
|
| 1064 |
for k, z := range Check(PanickyOfSliceIndex([]int{1, 2})) { |
| 1065 |
result = append(result, z) |
| 1066 |
if k == 1 { |
| 1067 |
break Y |
| 1068 |
} |
| 1069 |
} |
| 1070 |
} |
| 1071 |
} |
| 1072 |
} |
| 1073 |
|
| 1074 |
func TestPanickyIterator3(t testingT) { |
| 1075 |
var result []int |
| 1076 |
var expect = []int{100, 10, 1, 2, 200, 10, 1, 2} |
| 1077 |
defer func() { |
| 1078 |
if r := recover(); r != nil { |
| 1079 |
t.Error("Unexpected panic ", r) |
| 1080 |
} |
| 1081 |
t.Log(result) |
| 1082 |
if !slicesEqual(expect, result) { |
| 1083 |
t.Error("Expected ", expect, ", got ", result) |
| 1084 |
} |
| 1085 |
}() |
| 1086 |
for _, x := range OfSliceIndex([]int{100, 200}) { |
| 1087 |
result = append(result, x) |
| 1088 |
Y: |
| 1089 |
|
| 1090 |
|
| 1091 |
for _, y := range VeryBadOfSliceIndex([]int{10, 20}) { |
| 1092 |
result = append(result, y) |
| 1093 |
|
| 1094 |
for k, z := range OfSliceIndex([]int{1, 2}) { |
| 1095 |
result = append(result, z) |
| 1096 |
if k == 1 { |
| 1097 |
break Y |
| 1098 |
} |
| 1099 |
} |
| 1100 |
} |
| 1101 |
} |
| 1102 |
} |
| 1103 |
func TestPanickyIterator3Check(t testingT) { |
| 1104 |
var result []int |
| 1105 |
var expect = []int{100, 10, 1, 2, 200, 10, 1, 2} |
| 1106 |
defer func() { |
| 1107 |
if r := recover(); r != nil { |
| 1108 |
t.Error("Unexpected panic ", r) |
| 1109 |
} |
| 1110 |
t.Log(result) |
| 1111 |
if !slicesEqual(expect, result) { |
| 1112 |
t.Error("Expected ", expect, ", got ", result) |
| 1113 |
} |
| 1114 |
}() |
| 1115 |
for _, x := range Check(OfSliceIndex([]int{100, 200})) { |
| 1116 |
result = append(result, x) |
| 1117 |
Y: |
| 1118 |
|
| 1119 |
for _, y := range Check(VeryBadOfSliceIndex([]int{10, 20})) { |
| 1120 |
result = append(result, y) |
| 1121 |
|
| 1122 |
for k, z := range Check(OfSliceIndex([]int{1, 2})) { |
| 1123 |
result = append(result, z) |
| 1124 |
if k == 1 { |
| 1125 |
break Y |
| 1126 |
} |
| 1127 |
} |
| 1128 |
} |
| 1129 |
} |
| 1130 |
} |
| 1131 |
|
| 1132 |
func TestPanickyIterator4(t testingT) { |
| 1133 |
var result []int |
| 1134 |
var expect = []int{1, 2, 3} |
| 1135 |
defer func() { |
| 1136 |
matchErrorHelper(t, recover(), RERR_MISSING) |
| 1137 |
if !slicesEqual(expect, result) { |
| 1138 |
t.Error("Expected ", expect, ", got ", result) |
| 1139 |
} |
| 1140 |
}() |
| 1141 |
for _, x := range SwallowPanicOfSliceIndex([]int{1, 2, 3, 4}) { |
| 1142 |
result = append(result, x) |
| 1143 |
if x == 3 { |
| 1144 |
panic("x is 3") |
| 1145 |
} |
| 1146 |
} |
| 1147 |
|
| 1148 |
} |
| 1149 |
|
| 1150 |
func TestPanickyIterator4Check(t testingT) { |
| 1151 |
var result []int |
| 1152 |
var expect = []int{1, 2, 3} |
| 1153 |
defer func() { |
| 1154 |
matchErrorHelper(t, recover(), CERR_MISSING) |
| 1155 |
if !slicesEqual(expect, result) { |
| 1156 |
t.Error("Expected ", expect, ", got ", result) |
| 1157 |
} |
| 1158 |
}() |
| 1159 |
for _, x := range Check(SwallowPanicOfSliceIndex([]int{1, 2, 3, 4})) { |
| 1160 |
result = append(result, x) |
| 1161 |
if x == 3 { |
| 1162 |
panic("x is 3") |
| 1163 |
} |
| 1164 |
} |
| 1165 |
|
| 1166 |
} |
| 1167 |
|
| 1168 |
|
| 1169 |
|
| 1170 |
|
| 1171 |
|
| 1172 |
func veryBad(s []int) []int { |
| 1173 |
var result []int |
| 1174 |
X: |
| 1175 |
for _, x := range OfSliceIndex([]int{1, 2, 3}) { |
| 1176 |
result = append(result, x) |
| 1177 |
for _, y := range VeryBadOfSliceIndex(s) { |
| 1178 |
result = append(result, y) |
| 1179 |
break X |
| 1180 |
} |
| 1181 |
for _, z := range OfSliceIndex([]int{100, 200, 300}) { |
| 1182 |
result = append(result, z) |
| 1183 |
if z == 100 { |
| 1184 |
break |
| 1185 |
} |
| 1186 |
} |
| 1187 |
} |
| 1188 |
return result |
| 1189 |
} |
| 1190 |
|
| 1191 |
|
| 1192 |
|
| 1193 |
|
| 1194 |
func veryBadCheck(s []int) []int { |
| 1195 |
var result []int |
| 1196 |
X: |
| 1197 |
for _, x := range OfSliceIndex([]int{1, 2, 3}) { |
| 1198 |
result = append(result, x) |
| 1199 |
for _, y := range Check(VeryBadOfSliceIndex(s)) { |
| 1200 |
result = append(result, y) |
| 1201 |
break X |
| 1202 |
} |
| 1203 |
for _, z := range OfSliceIndex([]int{100, 200, 300}) { |
| 1204 |
result = append(result, z) |
| 1205 |
if z == 100 { |
| 1206 |
break |
| 1207 |
} |
| 1208 |
} |
| 1209 |
} |
| 1210 |
return result |
| 1211 |
} |
| 1212 |
|
| 1213 |
|
| 1214 |
|
| 1215 |
func okay(s []int) []int { |
| 1216 |
var result []int |
| 1217 |
X: |
| 1218 |
for _, x := range OfSliceIndex([]int{1, 2, 3}) { |
| 1219 |
result = append(result, x) |
| 1220 |
for _, y := range OfSliceIndex(s) { |
| 1221 |
result = append(result, y) |
| 1222 |
break X |
| 1223 |
} |
| 1224 |
for _, z := range OfSliceIndex([]int{100, 200, 300}) { |
| 1225 |
result = append(result, z) |
| 1226 |
if z == 100 { |
| 1227 |
break |
| 1228 |
} |
| 1229 |
} |
| 1230 |
} |
| 1231 |
return result |
| 1232 |
} |
| 1233 |
|
| 1234 |
|
| 1235 |
func TestVeryBad1(t testingT) { |
| 1236 |
result := veryBad([]int{10, 20, 30, 40, 50}) |
| 1237 |
expect := []int{1, 10} |
| 1238 |
t.Log(result) |
| 1239 |
if !slicesEqual(expect, result) { |
| 1240 |
t.Error("Expected ", expect, ", got", result) |
| 1241 |
} |
| 1242 |
} |
| 1243 |
|
| 1244 |
|
| 1245 |
func TestVeryBad2(t testingT) { |
| 1246 |
result := veryBad([]int{10, 20, 30, 40}) |
| 1247 |
expect := []int{1, 10} |
| 1248 |
t.Log(result) |
| 1249 |
if !slicesEqual(expect, result) { |
| 1250 |
t.Error("Expected ", expect, ", got", result) |
| 1251 |
} |
| 1252 |
} |
| 1253 |
|
| 1254 |
|
| 1255 |
|
| 1256 |
func TestVeryBadCheck(t testingT) { |
| 1257 |
result := veryBadCheck([]int{10, 20, 30, 40}) |
| 1258 |
expect := []int{1, 10} |
| 1259 |
t.Log(result) |
| 1260 |
if !slicesEqual(expect, result) { |
| 1261 |
t.Error("Expected ", expect, ", got", result) |
| 1262 |
} |
| 1263 |
} |
| 1264 |
|
| 1265 |
|
| 1266 |
func TestOk(t testingT) { |
| 1267 |
result := okay([]int{10, 20, 30, 40, 50}) |
| 1268 |
expect := []int{1, 10} |
| 1269 |
t.Log(result) |
| 1270 |
if !slicesEqual(expect, result) { |
| 1271 |
t.Error("Expected ", expect, ", got", result) |
| 1272 |
} |
| 1273 |
} |
| 1274 |
|
| 1275 |
|
| 1276 |
|
| 1277 |
|
| 1278 |
func testBreak1BadDefer(t testingT) (result []int) { |
| 1279 |
var expect = []int{1, 2, -1, 1, 2, -2, 1, 2, -3, -30, -20, -10} |
| 1280 |
defer func() { |
| 1281 |
matchErrorHelper(t, recover(), RERR_DONE) |
| 1282 |
if !slicesEqual(expect, result) { |
| 1283 |
t.Error("(Inner) Expected ", expect, ", got", result) |
| 1284 |
} |
| 1285 |
}() |
| 1286 |
for _, x := range BadOfSliceIndex([]int{-1, -2, -3, -4, -5}) { |
| 1287 |
if x == -4 { |
| 1288 |
break |
| 1289 |
} |
| 1290 |
defer func() { |
| 1291 |
result = append(result, x*10) |
| 1292 |
}() |
| 1293 |
for _, y := range OfSliceIndex([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) { |
| 1294 |
if y == 3 { |
| 1295 |
break |
| 1296 |
} |
| 1297 |
result = append(result, y) |
| 1298 |
} |
| 1299 |
result = append(result, x) |
| 1300 |
} |
| 1301 |
return |
| 1302 |
} |
| 1303 |
|
| 1304 |
func TestBreak1BadDefer(t testingT) { |
| 1305 |
var result []int |
| 1306 |
var expect = []int{1, 2, -1, 1, 2, -2, 1, 2, -3, -30, -20, -10} |
| 1307 |
result = testBreak1BadDefer(t) |
| 1308 |
t.Log(result) |
| 1309 |
if !slicesEqual(expect, result) { |
| 1310 |
t.Error("(Outer) Expected ", expect, ", got ", result) |
| 1311 |
} |
| 1312 |
} |
| 1313 |
|
| 1314 |
|
| 1315 |
func testReturn1() (result []int, err any) { |
| 1316 |
defer func() { |
| 1317 |
err = recover() |
| 1318 |
}() |
| 1319 |
for _, x := range OfSliceIndex([]int{-1, -2, -3, -4, -5}) { |
| 1320 |
result = append(result, x) |
| 1321 |
if x == -4 { |
| 1322 |
break |
| 1323 |
} |
| 1324 |
defer func() { |
| 1325 |
result = append(result, x*10) |
| 1326 |
}() |
| 1327 |
for _, y := range OfSliceIndex([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) { |
| 1328 |
if y == 3 { |
| 1329 |
return |
| 1330 |
} |
| 1331 |
result = append(result, y) |
| 1332 |
} |
| 1333 |
result = append(result, x) |
| 1334 |
} |
| 1335 |
return |
| 1336 |
} |
| 1337 |
|
| 1338 |
|
| 1339 |
func testReturn2() (result []int, err any) { |
| 1340 |
defer func() { |
| 1341 |
err = recover() |
| 1342 |
}() |
| 1343 |
for _, x := range BadOfSliceIndex([]int{-1, -2, -3, -4, -5}) { |
| 1344 |
result = append(result, x) |
| 1345 |
if x == -4 { |
| 1346 |
break |
| 1347 |
} |
| 1348 |
defer func() { |
| 1349 |
result = append(result, x*10) |
| 1350 |
}() |
| 1351 |
for _, y := range OfSliceIndex([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) { |
| 1352 |
if y == 3 { |
| 1353 |
return |
| 1354 |
} |
| 1355 |
result = append(result, y) |
| 1356 |
} |
| 1357 |
result = append(result, x) |
| 1358 |
} |
| 1359 |
return |
| 1360 |
} |
| 1361 |
|
| 1362 |
|
| 1363 |
func testReturn3() (result []int, err any) { |
| 1364 |
defer func() { |
| 1365 |
err = recover() |
| 1366 |
}() |
| 1367 |
for _, x := range OfSliceIndex([]int{-1, -2, -3, -4, -5}) { |
| 1368 |
result = append(result, x) |
| 1369 |
if x == -4 { |
| 1370 |
break |
| 1371 |
} |
| 1372 |
defer func() { |
| 1373 |
result = append(result, x*10) |
| 1374 |
}() |
| 1375 |
for _, y := range BadOfSliceIndex([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) { |
| 1376 |
if y == 3 { |
| 1377 |
return |
| 1378 |
} |
| 1379 |
result = append(result, y) |
| 1380 |
} |
| 1381 |
} |
| 1382 |
return |
| 1383 |
} |
| 1384 |
|
| 1385 |
|
| 1386 |
|
| 1387 |
|
| 1388 |
func testReturn4(t testingT) (_ []int, _ []int, err any) { |
| 1389 |
var result []int |
| 1390 |
defer func() { |
| 1391 |
err = recover() |
| 1392 |
}() |
| 1393 |
for _, x := range OfSliceIndex([]int{-1, -2, -3, -4, -5}) { |
| 1394 |
result = append(result, x) |
| 1395 |
if x == -4 { |
| 1396 |
break |
| 1397 |
} |
| 1398 |
defer func() { |
| 1399 |
result = append(result, x*10) |
| 1400 |
}() |
| 1401 |
for _, y := range OfSliceIndex([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) { |
| 1402 |
if y == 3 { |
| 1403 |
return result, result, nil |
| 1404 |
} |
| 1405 |
result = append(result, y) |
| 1406 |
} |
| 1407 |
result = append(result, x) |
| 1408 |
} |
| 1409 |
return |
| 1410 |
} |
| 1411 |
|
| 1412 |
|
| 1413 |
|
| 1414 |
func TestReturns(t testingT) { |
| 1415 |
var result []int |
| 1416 |
var result2 []int |
| 1417 |
var expect = []int{-1, 1, 2, -10} |
| 1418 |
var expect2 = []int{-1, 1, 2} |
| 1419 |
var err any |
| 1420 |
result, err = testReturn1() |
| 1421 |
t.Log(result) |
| 1422 |
if !slicesEqual(expect, result) { |
| 1423 |
t.Error("Expected ", expect, ", got", result) |
| 1424 |
} |
| 1425 |
if err != nil { |
| 1426 |
t.Error("Unexpected error: ", err) |
| 1427 |
} |
| 1428 |
result, err = testReturn2() |
| 1429 |
t.Log(result) |
| 1430 |
if !slicesEqual(expect, result) { |
| 1431 |
t.Error("Expected ", expect, ", got", result) |
| 1432 |
} |
| 1433 |
if err == nil { |
| 1434 |
t.Error("Missing expected error") |
| 1435 |
} else { |
| 1436 |
matchErrorHelper(t, err, RERR_DONE) |
| 1437 |
} |
| 1438 |
result, err = testReturn3() |
| 1439 |
t.Log(result) |
| 1440 |
if !slicesEqual(expect, result) { |
| 1441 |
t.Error("Expected ", expect, ", got", result) |
| 1442 |
} |
| 1443 |
if err == nil { |
| 1444 |
t.Error("Missing expected error") |
| 1445 |
} else { |
| 1446 |
matchErrorHelper(t, err, RERR_DONE) |
| 1447 |
} |
| 1448 |
|
| 1449 |
result, result2, err = testReturn4(t) |
| 1450 |
if !slicesEqual(expect2, result) { |
| 1451 |
t.Error("Expected ", expect2, "got", result) |
| 1452 |
} |
| 1453 |
if !slicesEqual(expect2, result2) { |
| 1454 |
t.Error("Expected ", expect2, "got", result2) |
| 1455 |
} |
| 1456 |
if err != nil { |
| 1457 |
t.Error("Unexpected error ", err) |
| 1458 |
} |
| 1459 |
} |
| 1460 |
|
| 1461 |
|
| 1462 |
func testGotoA1() (result []int, err any) { |
| 1463 |
defer func() { |
| 1464 |
err = recover() |
| 1465 |
}() |
| 1466 |
for _, x := range OfSliceIndex([]int{-1, -2, -3, -4, -5}) { |
| 1467 |
result = append(result, x) |
| 1468 |
if x == -4 { |
| 1469 |
break |
| 1470 |
} |
| 1471 |
defer func() { |
| 1472 |
result = append(result, x*10) |
| 1473 |
}() |
| 1474 |
for _, y := range OfSliceIndex([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) { |
| 1475 |
if y == 3 { |
| 1476 |
goto A |
| 1477 |
} |
| 1478 |
result = append(result, y) |
| 1479 |
} |
| 1480 |
result = append(result, x) |
| 1481 |
A: |
| 1482 |
} |
| 1483 |
return |
| 1484 |
} |
| 1485 |
|
| 1486 |
|
| 1487 |
func testGotoA2() (result []int, err any) { |
| 1488 |
defer func() { |
| 1489 |
err = recover() |
| 1490 |
}() |
| 1491 |
for _, x := range BadOfSliceIndex([]int{-1, -2, -3, -4, -5}) { |
| 1492 |
result = append(result, x) |
| 1493 |
if x == -4 { |
| 1494 |
break |
| 1495 |
} |
| 1496 |
defer func() { |
| 1497 |
result = append(result, x*10) |
| 1498 |
}() |
| 1499 |
for _, y := range OfSliceIndex([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) { |
| 1500 |
if y == 3 { |
| 1501 |
goto A |
| 1502 |
} |
| 1503 |
result = append(result, y) |
| 1504 |
} |
| 1505 |
result = append(result, x) |
| 1506 |
A: |
| 1507 |
} |
| 1508 |
return |
| 1509 |
} |
| 1510 |
|
| 1511 |
|
| 1512 |
func testGotoA3() (result []int, err any) { |
| 1513 |
defer func() { |
| 1514 |
err = recover() |
| 1515 |
}() |
| 1516 |
for _, x := range OfSliceIndex([]int{-1, -2, -3, -4, -5}) { |
| 1517 |
result = append(result, x) |
| 1518 |
if x == -4 { |
| 1519 |
break |
| 1520 |
} |
| 1521 |
defer func() { |
| 1522 |
result = append(result, x*10) |
| 1523 |
}() |
| 1524 |
for _, y := range BadOfSliceIndex([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) { |
| 1525 |
if y == 3 { |
| 1526 |
goto A |
| 1527 |
} |
| 1528 |
result = append(result, y) |
| 1529 |
} |
| 1530 |
result = append(result, x) |
| 1531 |
A: |
| 1532 |
} |
| 1533 |
return |
| 1534 |
} |
| 1535 |
func TestGotoA(t testingT) { |
| 1536 |
var result []int |
| 1537 |
var expect = []int{-1, 1, 2, -2, 1, 2, -3, 1, 2, -4, -30, -20, -10} |
| 1538 |
var expect3 = []int{-1, 1, 2, -10} |
| 1539 |
var err any |
| 1540 |
result, err = testGotoA1() |
| 1541 |
t.Log("testGotoA1", result) |
| 1542 |
if !slicesEqual(expect, result) { |
| 1543 |
t.Error("Expected ", expect, ", got", result) |
| 1544 |
} |
| 1545 |
if err != nil { |
| 1546 |
t.Error("Unexpected error: ", err) |
| 1547 |
} |
| 1548 |
result, err = testGotoA2() |
| 1549 |
t.Log("testGotoA2", result) |
| 1550 |
if !slicesEqual(expect, result) { |
| 1551 |
t.Error("Expected ", expect, ", got", result) |
| 1552 |
} |
| 1553 |
if err == nil { |
| 1554 |
t.Error("Missing expected error") |
| 1555 |
} else { |
| 1556 |
matchErrorHelper(t, err, RERR_DONE) |
| 1557 |
} |
| 1558 |
result, err = testGotoA3() |
| 1559 |
t.Log("testGotoA3", result) |
| 1560 |
if !slicesEqual(expect3, result) { |
| 1561 |
t.Error("Expected %v, got %v", expect3, result) |
| 1562 |
} |
| 1563 |
if err == nil { |
| 1564 |
t.Error("Missing expected error") |
| 1565 |
} else { |
| 1566 |
matchErrorHelper(t, err, RERR_DONE) |
| 1567 |
} |
| 1568 |
} |
| 1569 |
|
| 1570 |
|
| 1571 |
func testGotoB1() (result []int, err any) { |
| 1572 |
defer func() { |
| 1573 |
err = recover() |
| 1574 |
}() |
| 1575 |
for _, x := range OfSliceIndex([]int{-1, -2, -3, -4, -5}) { |
| 1576 |
result = append(result, x) |
| 1577 |
if x == -4 { |
| 1578 |
break |
| 1579 |
} |
| 1580 |
defer func() { |
| 1581 |
result = append(result, x*10) |
| 1582 |
}() |
| 1583 |
for _, y := range OfSliceIndex([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) { |
| 1584 |
if y == 3 { |
| 1585 |
goto B |
| 1586 |
} |
| 1587 |
result = append(result, y) |
| 1588 |
} |
| 1589 |
result = append(result, x) |
| 1590 |
} |
| 1591 |
B: |
| 1592 |
result = append(result, 999) |
| 1593 |
return |
| 1594 |
} |
| 1595 |
|
| 1596 |
|
| 1597 |
func testGotoB2() (result []int, err any) { |
| 1598 |
defer func() { |
| 1599 |
err = recover() |
| 1600 |
}() |
| 1601 |
for _, x := range BadOfSliceIndex([]int{-1, -2, -3, -4, -5}) { |
| 1602 |
result = append(result, x) |
| 1603 |
if x == -4 { |
| 1604 |
break |
| 1605 |
} |
| 1606 |
defer func() { |
| 1607 |
result = append(result, x*10) |
| 1608 |
}() |
| 1609 |
for _, y := range OfSliceIndex([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) { |
| 1610 |
if y == 3 { |
| 1611 |
goto B |
| 1612 |
} |
| 1613 |
result = append(result, y) |
| 1614 |
} |
| 1615 |
result = append(result, x) |
| 1616 |
} |
| 1617 |
B: |
| 1618 |
result = append(result, 999) |
| 1619 |
return |
| 1620 |
} |
| 1621 |
|
| 1622 |
|
| 1623 |
func testGotoB3() (result []int, err any) { |
| 1624 |
defer func() { |
| 1625 |
err = recover() |
| 1626 |
}() |
| 1627 |
for _, x := range OfSliceIndex([]int{-1, -2, -3, -4, -5}) { |
| 1628 |
result = append(result, x) |
| 1629 |
if x == -4 { |
| 1630 |
break |
| 1631 |
} |
| 1632 |
defer func() { |
| 1633 |
result = append(result, x*10) |
| 1634 |
}() |
| 1635 |
for _, y := range BadOfSliceIndex([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) { |
| 1636 |
if y == 3 { |
| 1637 |
goto B |
| 1638 |
} |
| 1639 |
result = append(result, y) |
| 1640 |
} |
| 1641 |
result = append(result, x) |
| 1642 |
} |
| 1643 |
B: |
| 1644 |
result = append(result, 999) |
| 1645 |
return |
| 1646 |
} |
| 1647 |
|
| 1648 |
func TestGotoB(t testingT) { |
| 1649 |
var result []int |
| 1650 |
var expect = []int{-1, 1, 2, 999, -10} |
| 1651 |
var expectX = []int{-1, 1, 2, -10} |
| 1652 |
var err any |
| 1653 |
result, err = testGotoB1() |
| 1654 |
t.Log("testGotoB1", result) |
| 1655 |
if !slicesEqual(expect, result) { |
| 1656 |
t.Error("Expected ", expect, ", got", result) |
| 1657 |
} |
| 1658 |
if err != nil { |
| 1659 |
t.Error("Unexpected error: ", err) |
| 1660 |
} |
| 1661 |
result, err = testGotoB2() |
| 1662 |
t.Log("testGotoB2", result) |
| 1663 |
if !slicesEqual(expectX, result) { |
| 1664 |
t.Error("Expected %v, got %v", expectX, result) |
| 1665 |
} |
| 1666 |
if err == nil { |
| 1667 |
t.Error("Missing expected error") |
| 1668 |
} else { |
| 1669 |
matchErrorHelper(t, err, RERR_DONE) |
| 1670 |
} |
| 1671 |
|
| 1672 |
result, err = testGotoB3() |
| 1673 |
t.Log("testGotoB3", result) |
| 1674 |
if !slicesEqual(expectX, result) { |
| 1675 |
t.Error("Expected %v, got %v", expectX, result) |
| 1676 |
} |
| 1677 |
if err == nil { |
| 1678 |
t.Error("Missing expected error") |
| 1679 |
} else { |
| 1680 |
matchErrorHelper(t, err, RERR_DONE) |
| 1681 |
} |
| 1682 |
} |
| 1683 |
|
| 1684 |
|
| 1685 |
func once[T any](x T) Seq[T] { |
| 1686 |
return func(yield func(T) bool) { |
| 1687 |
yield(x) |
| 1688 |
} |
| 1689 |
} |
| 1690 |
|
| 1691 |
|
| 1692 |
|
| 1693 |
|
| 1694 |
func terrify[T any](s string, forall Seq[T]) Seq[T] { |
| 1695 |
return func(yield func(T) bool) { |
| 1696 |
forall(func(v T) bool { |
| 1697 |
if !yield(v) { |
| 1698 |
panic(s) |
| 1699 |
} |
| 1700 |
return true |
| 1701 |
}) |
| 1702 |
} |
| 1703 |
} |
| 1704 |
|
| 1705 |
func use[T any](T) { |
| 1706 |
} |
| 1707 |
|
| 1708 |
|
| 1709 |
|
| 1710 |
func f() string { |
| 1711 |
defer func() { recover() }() |
| 1712 |
defer panic("f panic") |
| 1713 |
for _, s := range []string{"f return"} { |
| 1714 |
return s |
| 1715 |
} |
| 1716 |
return "f not reached" |
| 1717 |
} |
| 1718 |
|
| 1719 |
|
| 1720 |
|
| 1721 |
func g() string { |
| 1722 |
defer func() { recover() }() |
| 1723 |
for s := range terrify("g panic", once("g return")) { |
| 1724 |
return s |
| 1725 |
} |
| 1726 |
return "g not reached" |
| 1727 |
} |
| 1728 |
|
| 1729 |
|
| 1730 |
|
| 1731 |
|
| 1732 |
func h() (hashS string) { |
| 1733 |
defer func() { recover() }() |
| 1734 |
for s := range terrify("h panic", once("h return")) { |
| 1735 |
hashS := s |
| 1736 |
use(hashS) |
| 1737 |
return s |
| 1738 |
} |
| 1739 |
return "h not reached" |
| 1740 |
} |
| 1741 |
|
| 1742 |
func j() (hashS string) { |
| 1743 |
defer func() { recover() }() |
| 1744 |
for s := range terrify("j panic", once("j return")) { |
| 1745 |
hashS = s |
| 1746 |
return |
| 1747 |
} |
| 1748 |
return "j not reached" |
| 1749 |
} |
| 1750 |
|
| 1751 |
|
| 1752 |
|
| 1753 |
|
| 1754 |
|
| 1755 |
func k() (hashS string) { |
| 1756 |
_return := func(s string) { hashS = s } |
| 1757 |
|
| 1758 |
defer func() { recover() }() |
| 1759 |
for s := range terrify("k panic", once("k return")) { |
| 1760 |
_return(s) |
| 1761 |
return |
| 1762 |
} |
| 1763 |
return "k not reached" |
| 1764 |
} |
| 1765 |
|
| 1766 |
func m() (hashS string) { |
| 1767 |
_return := func(s string) { hashS = s } |
| 1768 |
|
| 1769 |
defer func() { recover() }() |
| 1770 |
for s := range terrify("m panic", once("m return")) { |
| 1771 |
defer _return(s) |
| 1772 |
return s + ", but should be replaced in a defer" |
| 1773 |
} |
| 1774 |
return "m not reached" |
| 1775 |
} |
| 1776 |
|
| 1777 |
func n() string { |
| 1778 |
defer func() { recover() }() |
| 1779 |
for s := range terrify("n panic", once("n return")) { |
| 1780 |
return s + func(s string) string { |
| 1781 |
defer func() { recover() }() |
| 1782 |
for s := range terrify("n closure panic", once(s)) { |
| 1783 |
return s |
| 1784 |
} |
| 1785 |
return "n closure not reached" |
| 1786 |
}(" and n closure return") |
| 1787 |
} |
| 1788 |
return "n not reached" |
| 1789 |
} |
| 1790 |
|
| 1791 |
type terrifyTestCase struct { |
| 1792 |
f func() string |
| 1793 |
e string |
| 1794 |
} |
| 1795 |
|
| 1796 |
func TestPanicReturns(t testingT) { |
| 1797 |
tcs := []terrifyTestCase{ |
| 1798 |
{f, "f return"}, |
| 1799 |
{g, "g return"}, |
| 1800 |
{h, "h return"}, |
| 1801 |
{k, "k return"}, |
| 1802 |
{j, "j return"}, |
| 1803 |
{m, "m return"}, |
| 1804 |
{n, "n return and n closure return"}, |
| 1805 |
} |
| 1806 |
|
| 1807 |
for _, tc := range tcs { |
| 1808 |
got := tc.f() |
| 1809 |
if got != tc.e { |
| 1810 |
t.Error("Got '", got, "' expected ", tc.e) |
| 1811 |
} else { |
| 1812 |
t.Log("Got expected '", got, "'") |
| 1813 |
} |
| 1814 |
} |
| 1815 |
} |