============================================================================= Focused equivalence tests for the stringEnd fast path (PR #285-style "fast path for the provably-safe common case" pattern). These tests pin the contract that stringEnd's new SIMD fast path returns EXACTLY the same (endIn
(data []byte)
| 24 | // referenceStringEnd is the original byte-at-a-time implementation, kept here |
| 25 | // as an oracle. Do NOT modify — it is the semantic reference. |
| 26 | func referenceStringEnd(data []byte) (int, bool) { |
| 27 | escaped := false |
| 28 | for i, c := range data { |
| 29 | if c == '"' { |
| 30 | if !escaped { |
| 31 | return i + 1, false |
| 32 | } else { |
| 33 | j := i - 1 |
| 34 | for { |
| 35 | if j < 0 || data[j] != '\\' { |
| 36 | return i + 1, true |
| 37 | } |
| 38 | j-- |
| 39 | if j < 0 || data[j] != '\\' { |
| 40 | break |
| 41 | } |
| 42 | j-- |
| 43 | } |
| 44 | } |
| 45 | } else if c == '\\' { |
| 46 | escaped = true |
| 47 | } |
| 48 | } |
| 49 | return -1, escaped |
| 50 | } |
| 51 | |
| 52 | // Verifies: SYS-REQ-045 |
| 53 | func TestStringEnd_FastPathEquivalence_Cases(t *testing.T) { |
no outgoing calls
no test coverage detected