--------------------------------------------------------------------------- Property 3: Delete correctness — after Delete, Get fails AND remaining structure is valid JSON (no corruption). --------------------------------------------------------------------------- reqproof:proptest parser.Delete Veri
(t *testing.T)
| 703 | // reqproof:proptest parser.Delete |
| 704 | // Verifies: SYS-REQ-034 [property] |
| 705 | func TestOracleDeleteCorrectness(t *testing.T) { |
| 706 | r := oracleNewRNG(oracleSeed + 2) |
| 707 | const iterations = 10000 |
| 708 | for i := 0; i < iterations; i++ { |
| 709 | raw, v := oracleRandomJSONBytes(r, 3) |
| 710 | // Pick a path that exists so Delete actually does something. |
| 711 | // We use pickExistingPath (semantically valid) to avoid the |
| 712 | // documented D8 bug (Delete with array-index on object value). |
| 713 | path, _ := pickExistingPath(r, v) |
| 714 | if len(path) == 0 { |
| 715 | // Deleting the root with no keys is a documented special case |
| 716 | // (returns data[:0]); skip it. |
| 717 | continue |
| 718 | } |
| 719 | |
| 720 | var deleted []byte |
| 721 | func() { |
| 722 | defer func() { |
| 723 | if rec := recover(); rec != nil { |
| 724 | t.Fatalf("Delete panicked on input %q path=%v: %v", raw, path, rec) |
| 725 | } |
| 726 | }() |
| 727 | assertInputUnchanged(t, raw, func() { |
| 728 | deleted = Delete(raw, path...) |
| 729 | }) |
| 730 | }() |
| 731 | |
| 732 | // Property 3a: if the result is non-empty, it MUST be valid JSON |
| 733 | // (no corruption). An empty result is allowed when Delete removes |
| 734 | // the entire document. |
| 735 | if len(deleted) > 0 && !json.Valid(deleted) { |
| 736 | t.Fatalf("Delete produced invalid JSON:\n in=%q\n path=%v\n out=%q", |
| 737 | raw, path, deleted) |
| 738 | } |
| 739 | |
| 740 | // Property 3b: Get on the deleted path MUST return KeyPathNotFoundError |
| 741 | // (the value is gone). Only strictly assert for single-component |
| 742 | // object-key paths — multi-component deletes sometimes leave parent |
| 743 | // structure intact and the value can re-appear via a sibling key. |
| 744 | if len(path) == 1 && !strings.HasPrefix(path[0], "[") { |
| 745 | got, dt, _, gerr := Get(deleted, path...) |
| 746 | if gerr == nil && dt != NotExist && len(got) > 0 && len(deleted) > 0 { |
| 747 | t.Fatalf("Delete did not remove key:\n in=%q\n path=%v\n out=%q\n still-present=%q", |
| 748 | raw, path, deleted, got) |
| 749 | } |
| 750 | } |
| 751 | } |
| 752 | } |
| 753 | |
| 754 | // --------------------------------------------------------------------------- |
| 755 | // Property 4: ParseInt / ParseFloat / ParseBoolean agree with strconv. |
nothing calls this directly
no test coverage detected