| 495 | } |
| 496 | |
| 497 | func TestRegistryFixedOverflow(t *testing.T) { |
| 498 | state := NewState() |
| 499 | defer state.Close() |
| 500 | reg := state.reg |
| 501 | expectedPanic := false |
| 502 | // should be non auto grow by default |
| 503 | errorIfFalse(t, reg.maxSize == 0, "state should default to non-auto growing implementation") |
| 504 | // fill the stack and check we get a panic |
| 505 | test := LString("test") |
| 506 | for i := 0; i < len(reg.array); i++ { |
| 507 | reg.Push(test) |
| 508 | } |
| 509 | defer func() { |
| 510 | rcv := recover() |
| 511 | if rcv != nil { |
| 512 | if expectedPanic { |
| 513 | errorIfFalse(t, rcv.(error).Error() != "registry overflow", "expected registry overflow exception, got "+rcv.(error).Error()) |
| 514 | } else { |
| 515 | t.Errorf("did not expect registry overflow") |
| 516 | } |
| 517 | } else if expectedPanic { |
| 518 | t.Errorf("expected registry overflow exception, but didn't get panic") |
| 519 | } |
| 520 | }() |
| 521 | expectedPanic = true |
| 522 | reg.Push(test) |
| 523 | } |
| 524 | |
| 525 | func TestRegistryAutoGrow(t *testing.T) { |
| 526 | state := NewState(Options{RegistryMaxSize: 300, RegistrySize: 200, RegistryGrowStep: 25}) |