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

Function TestPropertyBlockStringEndBalanced

property_test.go:765–795  ·  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

763// reqproof:proptest blockEnd, stringEnd
764// Verifies: SYS-REQ-035 [property]
765func TestPropertyBlockStringEndBalanced(t *testing.T) {
766 r := newRNG(jsonSeed + 11)
767 const iterations = 2000
768 for i := 0; i < iterations; i++ {
769 raw := randomBytes(r, 64)
770 // Every open/close pair from the JSON grammar must be panic-free.
771 for _, pair := range [][2]byte{{'{', '}'}, {'[', ']'}} {
772 if !recoverNoPanic(func() { _ = blockEnd(raw, pair[0], pair[1]) }) {
773 t.Fatalf("blockEnd panicked on %q pair=%v", raw, pair)
774 }
775 a := blockEnd(raw, pair[0], pair[1])
776 b := blockEnd(raw, pair[0], pair[1])
777 if a != b {
778 t.Fatalf("blockEnd non-deterministic on %q pair=%v: %d vs %d", raw, pair, a, b)
779 }
780 // blockEnd returns -1 when not found, otherwise a valid index in
781 // [0, len(raw)] (len means "scanned past end without finding").
782 if a != -1 && (a < 0 || a > len(raw)) {
783 t.Fatalf("blockEnd out-of-range %d on %q (len=%d)", a, raw, len(raw))
784 }
785 }
786 if !recoverNoPanic(func() { _, _ = stringEnd(raw) }) {
787 t.Fatalf("stringEnd panicked on %q", raw)
788 }
789 ea, oka := stringEnd(raw)
790 eb, okb := stringEnd(raw)
791 if ea != eb || oka != okb {
792 t.Fatalf("stringEnd non-deterministic on %q: (%d,%v) vs (%d,%v)", raw, ea, oka, eb, okb)
793 }
794 }
795}
796
797// ---------------------------------------------------------------------------
798// 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