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

Function TestPropertyEachKeyDispatch

property_test.go:407–433  ·  view source on GitHub ↗

--------------------------------------------------------------------------- Property: EachKey dispatches to matching paths without panic --------------------------------------------------------------------------- reqproof:proptest parser.EachKey Verifies: SYS-REQ-008 [property]

(t *testing.T)

Source from the content-addressed store, hash-verified

405// reqproof:proptest parser.EachKey
406// Verifies: SYS-REQ-008 [property]
407func TestPropertyEachKeyDispatch(t *testing.T) {
408 r := newRNG(jsonSeed + 4)
409 const iterations = 500
410 for i := 0; i < iterations; i++ {
411 raw, obj := randomObjectJSONBytes(r, 2)
412 // Build paths from the object's own keys (shallow).
413 var paths [][]string
414 for k := range obj {
415 paths = append(paths, []string{k})
416 }
417 if len(paths) == 0 {
418 continue
419 }
420 hits := make([]int, len(paths))
421 EachKey(raw, func(idx int, value []byte, vt ValueType, err error) {
422 if idx >= 0 && idx < len(hits) {
423 hits[idx]++
424 }
425 }, paths...)
426 // Each hit count must be exactly 0 or 1 (jsonparser finds at most one).
427 for i, h := range hits {
428 if h < 0 || h > 1 {
429 t.Fatalf("EachKey hit count out of range [%d]=%d on input %q", i, h, raw)
430 }
431 }
432 }
433}
434
435func randomExistingJSONPath(r *mathrand.Rand, value interface{}) []string {
436 var path []string

Callers

nothing calls this directly

Calls 3

newRNGFunction · 0.85
randomObjectJSONBytesFunction · 0.85
EachKeyFunction · 0.85

Tested by

no test coverage detected