MCPcopy Create free account
hub / github.com/buger/jsonparser / TestPropertyBlockStringEndBalanced

Function TestPropertyBlockStringEndBalanced

property_test.go:652–682  ·  view source on GitHub ↗

--------------------------------------------------------------------------- Property: blockEnd / stringEnd never panic on arbitrary bytes --------------------------------------------------------------------------- reqproof:proptest blockEnd, stringEnd Verifies: SYS-REQ-035 [property]

(t *testing.T)

Source from the content-addressed store, hash-verified

650// reqproof:proptest blockEnd, stringEnd
651// Verifies: SYS-REQ-035 [property]
652func TestPropertyBlockStringEndBalanced(t *testing.T) {
653 r := newRNG(jsonSeed + 11)
654 const iterations = 2000
655 for i := 0; i < iterations; i++ {
656 raw := randomBytes(r, 64)
657 // Every open/close pair from the JSON grammar must be panic-free.
658 for _, pair := range [][2]byte{{'{', '}'}, {'[', ']'}} {
659 if !recoverNoPanic(func() { _ = blockEnd(raw, pair[0], pair[1]) }) {
660 t.Fatalf("blockEnd panicked on %q pair=%v", raw, pair)
661 }
662 a := blockEnd(raw, pair[0], pair[1])
663 b := blockEnd(raw, pair[0], pair[1])
664 if a != b {
665 t.Fatalf("blockEnd non-deterministic on %q pair=%v: %d vs %d", raw, pair, a, b)
666 }
667 // blockEnd returns -1 when not found, otherwise a valid index in
668 // [0, len(raw)] (len means "scanned past end without finding").
669 if a != -1 && (a < 0 || a > len(raw)) {
670 t.Fatalf("blockEnd out-of-range %d on %q (len=%d)", a, raw, len(raw))
671 }
672 }
673 if !recoverNoPanic(func() { _, _ = stringEnd(raw) }) {
674 t.Fatalf("stringEnd panicked on %q", raw)
675 }
676 ea, oka := stringEnd(raw)
677 eb, okb := stringEnd(raw)
678 if ea != eb || oka != okb {
679 t.Fatalf("stringEnd non-deterministic on %q: (%d,%v) vs (%d,%v)", raw, ea, oka, eb, okb)
680 }
681 }
682}
683
684// ---------------------------------------------------------------------------
685// Property: sameTree is reflexive and symmetric

Callers

nothing calls this directly

Calls 5

newRNGFunction · 0.85
randomBytesFunction · 0.85
recoverNoPanicFunction · 0.85
blockEndFunction · 0.85
stringEndFunction · 0.85

Tested by

no test coverage detected