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

Function TestPropertySetRoundTrip

property_test.go:529–553  ·  view source on GitHub ↗

--------------------------------------------------------------------------- Property: Set then Get returns the set value (round-trip) --------------------------------------------------------------------------- reqproof:proptest parser.Set Verifies: SYS-REQ-009 [property]

(t *testing.T)

Source from the content-addressed store, hash-verified

527// reqproof:proptest parser.Set
528// Verifies: SYS-REQ-009 [property]
529func TestPropertySetRoundTrip(t *testing.T) {
530 r := newRNG(jsonSeed + 5)
531 const iterations = 500
532 for i := 0; i < iterations; i++ {
533 // Start from an object (possibly empty) so Set has a target.
534 base := []byte(`{}`)
535 key := randKey(r)
536 setVal := []byte(strconv.FormatInt(r.Int63(), 10))
537 var out []byte
538 var err error
539 assertInputUnchanged(t, base, func() {
540 out, err = Set(base, setVal, key)
541 })
542 if err != nil {
543 t.Fatalf("Set errored on key=%q val=%q base=%q: %v", key, setVal, base, err)
544 }
545 got, _, _, gerr := Get(out, key)
546 if gerr != nil {
547 t.Fatalf("Set→Get failed to find key=%q in output %q: %v", key, out, gerr)
548 }
549 if !bytes.Equal(got, setVal) {
550 t.Fatalf("Set→Get value mismatch on key=%q: got=%q want=%q (out=%q)", key, got, setVal, out)
551 }
552 }
553}
554
555// ---------------------------------------------------------------------------
556// Property: Delete is idempotent (Delete twice == Delete once)

Callers

nothing calls this directly

Calls 5

newRNGFunction · 0.85
randKeyFunction · 0.85
assertInputUnchangedFunction · 0.85
SetFunction · 0.85
GetFunction · 0.85

Tested by

no test coverage detected