--------------------------------------------------------------------------- Property: WriteToBuffer / calcAllocateSpace / createInsertComponent are pure --------------------------------------------------------------------------- reqproof:proptest WriteToBuffer, calcAllocateSpace, createInsertCompon
(t *testing.T)
| 732 | // reqproof:proptest WriteToBuffer, calcAllocateSpace, createInsertComponent |
| 733 | // Verifies: SYS-REQ-009 [property] |
| 734 | func TestPropertyBufferOpsPure(t *testing.T) { |
| 735 | r := newRNG(jsonSeed + 13) |
| 736 | const iterations = 500 |
| 737 | // WriteToBuffer: deterministic for a fixed buffer + string, never overflows. |
| 738 | writeDeterministic := func(bufLen int, s string) bool { |
| 739 | if bufLen < 0 || bufLen > 4096 { |
| 740 | return true |
| 741 | } |
| 742 | buf1 := make([]byte, bufLen) |
| 743 | buf2 := make([]byte, bufLen) |
| 744 | n1 := WriteToBuffer(buf1, s) |
| 745 | n2 := WriteToBuffer(buf2, s) |
| 746 | if n1 != n2 { |
| 747 | return false |
| 748 | } |
| 749 | return bytes.Equal(buf1, buf2) |
| 750 | } |
| 751 | if err := quick.Check(writeDeterministic, &quick.Config{MaxCount: iterations}); err != nil { |
| 752 | t.Fatalf("WriteToBuffer not deterministic: %v", err) |
| 753 | } |
| 754 | |
| 755 | // calcAllocateSpace / createInsertComponent: determinism + no panic. |
| 756 | for i := 0; i < iterations; i++ { |
| 757 | keys := []string{randKey(r), randKey(r)} |
| 758 | setValue := []byte(strconv.FormatInt(r.Int63(), 10)) |
| 759 | for _, comma := range []bool{true, false} { |
| 760 | for _, object := range []bool{true, false} { |
| 761 | a := calcAllocateSpace(keys, setValue, comma, object) |
| 762 | b := calcAllocateSpace(keys, setValue, comma, object) |
| 763 | if a != b { |
| 764 | t.Fatalf("calcAllocateSpace non-deterministic: %d vs %d (keys=%v val=%q comma=%v obj=%v)", a, b, keys, setValue, comma, object) |
| 765 | } |
| 766 | if a < 0 { |
| 767 | t.Fatalf("calcAllocateSpace negative: %d", a) |
| 768 | } |
| 769 | if !recoverNoPanic(func() { |
| 770 | _ = createInsertComponent(keys, setValue, comma, object) |
| 771 | }) { |
| 772 | t.Fatalf("createInsertComponent panicked on keys=%v val=%q comma=%v obj=%v", keys, setValue, comma, object) |
| 773 | } |
| 774 | out1 := createInsertComponent(keys, setValue, comma, object) |
| 775 | out2 := createInsertComponent(keys, setValue, comma, object) |
| 776 | if !bytes.Equal(out1, out2) { |
| 777 | t.Fatalf("createInsertComponent non-deterministic on keys=%v val=%q comma=%v obj=%v", keys, setValue, comma, object) |
| 778 | } |
| 779 | } |
| 780 | } |
| 781 | } |
| 782 | } |
| 783 | |
| 784 | // --------------------------------------------------------------------------- |
| 785 | // Property: ValueType.String round-trips for all enumerated tags |
nothing calls this directly
no test coverage detected