(r *mathrand.Rand, value interface{})
| 433 | } |
| 434 | |
| 435 | func randomExistingJSONPath(r *mathrand.Rand, value interface{}) []string { |
| 436 | var path []string |
| 437 | current := value |
| 438 | |
| 439 | for len(path) < 16 { |
| 440 | switch node := current.(type) { |
| 441 | case map[string]interface{}: |
| 442 | if len(node) == 0 || (len(path) > 0 && r.Intn(4) == 0) { |
| 443 | return path |
| 444 | } |
| 445 | keys := make([]string, 0, len(node)) |
| 446 | for key := range node { |
| 447 | keys = append(keys, key) |
| 448 | } |
| 449 | sort.Strings(keys) |
| 450 | key := keys[r.Intn(len(keys))] |
| 451 | path = append(path, key) |
| 452 | current = node[key] |
| 453 | case []interface{}: |
| 454 | if len(node) == 0 || (len(path) > 0 && r.Intn(4) == 0) { |
| 455 | return path |
| 456 | } |
| 457 | index := r.Intn(len(node)) |
| 458 | path = append(path, fmt.Sprintf("[%d]", index)) |
| 459 | current = node[index] |
| 460 | default: |
| 461 | return path |
| 462 | } |
| 463 | } |
| 464 | |
| 465 | return path |
| 466 | } |
| 467 | |
| 468 | // Verifies: SYS-REQ-008 |
| 469 | // reqproof:proptest parser.EachKey, parser.Get |
no outgoing calls
no test coverage detected