--------------------------------------------------------------------------- Property: EachKey dispatches to matching paths without panic --------------------------------------------------------------------------- reqproof:proptest parser.EachKey Verifies: SYS-REQ-008 [property]
(t *testing.T)
| 405 | // reqproof:proptest parser.EachKey |
| 406 | // Verifies: SYS-REQ-008 [property] |
| 407 | func 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 | |
| 435 | func randomExistingJSONPath(r *mathrand.Rand, value interface{}) []string { |
| 436 | var path []string |
nothing calls this directly
no test coverage detected