--------------------------------------------------------------------------- Property: EachKey dispatches to matching paths without panic --------------------------------------------------------------------------- reqproof:proptest EachKey Verifies: SYS-REQ-008 [property]
(t *testing.T)
| 390 | // reqproof:proptest EachKey |
| 391 | // Verifies: SYS-REQ-008 [property] |
| 392 | func TestPropertyEachKeyDispatch(t *testing.T) { |
| 393 | r := newRNG(jsonSeed + 4) |
| 394 | const iterations = 500 |
| 395 | for i := 0; i < iterations; i++ { |
| 396 | raw, obj := randomObjectJSONBytes(r, 2) |
| 397 | // Build paths from the object's own keys (shallow). |
| 398 | var paths [][]string |
| 399 | for k := range obj { |
| 400 | paths = append(paths, []string{k}) |
| 401 | } |
| 402 | if len(paths) == 0 { |
| 403 | continue |
| 404 | } |
| 405 | hits := make([]int, len(paths)) |
| 406 | EachKey(raw, func(idx int, value []byte, vt ValueType, err error) { |
| 407 | if idx >= 0 && idx < len(hits) { |
| 408 | hits[idx]++ |
| 409 | } |
| 410 | }, paths...) |
| 411 | // Each hit count must be exactly 0 or 1 (jsonparser finds at most one). |
| 412 | for i, h := range hits { |
| 413 | if h < 0 || h > 1 { |
| 414 | t.Fatalf("EachKey hit count out of range [%d]=%d on input %q", i, h, raw) |
| 415 | } |
| 416 | } |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | // --------------------------------------------------------------------------- |
| 421 | // Property: Set then Get returns the set value (round-trip) |
nothing calls this directly
no test coverage detected