============================================================================= Gate I: Marshal determinism on round-tripped values ============================================================================= encoding/json's Marshal uses sorted map iteration (since Go 1.12), so the same value should
(t *testing.T, data []byte)
| 507 | // differential surface. |
| 508 | |
| 509 | func runMarshalDeterminismGate(t *testing.T, data []byte) { |
| 510 | t.Helper() |
| 511 | if !json.Valid(data) { |
| 512 | return |
| 513 | } |
| 514 | var v interface{} |
| 515 | dec := json.NewDecoder(bytes.NewReader(data)) |
| 516 | dec.UseNumber() |
| 517 | if err := dec.Decode(&v); err != nil { |
| 518 | return |
| 519 | } |
| 520 | encodingJSONNoPanic(t, "MarshalDeterminism/Marshal1", data, func() { |
| 521 | b1, e1 := json.Marshal(v) |
| 522 | b2, e2 := json.Marshal(v) |
| 523 | if e1 != nil || e2 != nil { |
| 524 | return |
| 525 | } |
| 526 | if !bytes.Equal(b1, b2) { |
| 527 | t.Errorf("Gate I: Marshal non-deterministic on value from %s: "+ |
| 528 | "b1=%s b2=%s (DETERMINISM violation)", |
| 529 | truncateForMsg(data), truncateForMsg(b1), truncateForMsg(b2)) |
| 530 | } |
| 531 | }) |
| 532 | } |
| 533 | |
| 534 | // ============================================================================= |
| 535 | // Gate G: Differential — jsonparser vs encoding/json number parsing |
no test coverage detected