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

Function TestOracleGetRoundTrip

reference_oracle_test.go:454–490  ·  view source on GitHub ↗

--------------------------------------------------------------------------- Property 1: Get round-trip — jsonparser.Get matches encoding/json. --------------------------------------------------------------------------- reqproof:proptest Get Verifies: SYS-REQ-001 [property]

(t *testing.T)

Source from the content-addressed store, hash-verified

452// reqproof:proptest Get
453// Verifies: SYS-REQ-001 [property]
454func TestOracleGetRoundTrip(t *testing.T) {
455 r := oracleNewRNG(oracleSeed)
456 const iterations = 10000
457 for i := 0; i < iterations; i++ {
458 raw, v := oracleRandomJSONBytes(r, 3)
459 // Walk the tree to pick a path that exists.
460 path, expected := pickExistingPath(r, v)
461 var got []byte
462 var dt ValueType
463 var gerr error
464 func() {
465 defer func() {
466 if rec := recover(); rec != nil {
467 t.Fatalf("Get panicked on input %q path=%v: %v", raw, path, rec)
468 }
469 }()
470 got, dt, _, gerr = Get(raw, path...)
471 }()
472 if !compareGetToOracle(got, dt, gerr, expected) {
473 t.Fatalf("Get diverges from oracle on input %q path=%v:\n got=(%q, %v, err=%v)\n want=%v",
474 raw, path, got, dt, gerr, expected)
475 }
476 }
477 // Also: Get on a missing path MUST NOT panic. Sample adversarial paths.
478 for i := 0; i < 1000; i++ {
479 raw, v := oracleRandomJSONBytes(r, 2)
480 path := pickAdversarialPath(r, v)
481 func() {
482 defer func() {
483 if rec := recover(); rec != nil {
484 t.Fatalf("Get panicked on adversarial input %q path=%v: %v", raw, path, rec)
485 }
486 }()
487 _, _, _, _ = Get(raw, path...)
488 }()
489 }
490}
491
492// ---------------------------------------------------------------------------
493// Property 2: Set append/replace — Set then Get returns the set value.

Callers

nothing calls this directly

Calls 6

oracleNewRNGFunction · 0.85
oracleRandomJSONBytesFunction · 0.85
pickExistingPathFunction · 0.85
GetFunction · 0.85
compareGetToOracleFunction · 0.85
pickAdversarialPathFunction · 0.85

Tested by

no test coverage detected