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

Function TestPropertyInternalGetConsistentWithGet

property_test.go:709–726  ·  view source on GitHub ↗

--------------------------------------------------------------------------- Property: internalGet agrees with Get (Get is a thin projection) --------------------------------------------------------------------------- reqproof:proptest internalGet Verifies: SYS-REQ-001 [property]

(t *testing.T)

Source from the content-addressed store, hash-verified

707// reqproof:proptest internalGet
708// Verifies: SYS-REQ-001 [property]
709func TestPropertyInternalGetConsistentWithGet(t *testing.T) {
710 r := newRNG(jsonSeed + 12)
711 const iterations = 1000
712 for i := 0; i < iterations; i++ {
713 raw := randomJSONBytes(r, 2)
714 keys := []string{randKey(r)}
715 // Get is `a, b, _, d, e := internalGet(...); return a, b, d, e` — i.e.
716 // Get's offset is internalGet's END offset, not its start offset.
717 // So we compare value, type, and error; offsets are related but
718 // not identical fields.
719 v1, t1, _, e1 := Get(raw, keys...)
720 v2, t2, _, _, e2 := internalGet(raw, keys...)
721 if !bytes.Equal(v1, v2) || t1 != t2 || (e1 == nil) != (e2 == nil) {
722 t.Fatalf("internalGet/Get disagree on input %q keys=%v: Get=(%q,%v,err=%v) iGet=(%q,%v,err=%v)",
723 raw, keys, v1, t1, e1, v2, t2, e2)
724 }
725 }
726}
727
728// ---------------------------------------------------------------------------
729// Property: WriteToBuffer / calcAllocateSpace / createInsertComponent are pure

Callers

nothing calls this directly

Calls 5

newRNGFunction · 0.85
randomJSONBytesFunction · 0.85
randKeyFunction · 0.85
GetFunction · 0.85
internalGetFunction · 0.85

Tested by

no test coverage detected