Verifies: SYS-REQ-045
(t *testing.T)
| 80 | |
| 81 | // Verifies: SYS-REQ-045 |
| 82 | func TestStringEnd_FastPathEquivalence_Random(t *testing.T) { |
| 83 | r := rand.New(rand.NewSource(1)) |
| 84 | alphabets := [][]byte{ |
| 85 | []byte(`abcXYZ 123`), |
| 86 | []byte(`abc\"\\`), |
| 87 | []byte(`abc"`), |
| 88 | } |
| 89 | const iterations = 20000 |
| 90 | maxLen := 32 |
| 91 | |
| 92 | for i := 0; i < iterations; i++ { |
| 93 | n := 1 + r.Intn(maxLen) |
| 94 | buf := make([]byte, n) |
| 95 | for j := range buf { |
| 96 | alphabet := alphabets[r.Intn(len(alphabets))] |
| 97 | buf[j] = alphabet[r.Intn(len(alphabet))] |
| 98 | } |
| 99 | gotEnd, gotEsc := stringEnd(buf) |
| 100 | wantEnd, wantEsc := referenceStringEnd(buf) |
| 101 | if gotEnd != wantEnd || gotEsc != wantEsc { |
| 102 | t.Fatalf("iter %d input=%q: stringEnd=(%d,%v) want=(%d,%v)", |
| 103 | i, buf, gotEnd, gotEsc, wantEnd, wantEsc) |
| 104 | } |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | // Directly exercise the fast-path branches with long inputs that would be |
| 109 | // expensive under per-byte scanning. |
nothing calls this directly
no test coverage detected