MCPcopy Create free account
hub / github.com/buger/jsonparser / TestStringEnd_FastPathEquivalence_Random

Function TestStringEnd_FastPathEquivalence_Random

optimization_equiv_test.go:82–106  ·  view source on GitHub ↗

Verifies: SYS-REQ-045

(t *testing.T)

Source from the content-addressed store, hash-verified

80
81// Verifies: SYS-REQ-045
82func 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.

Callers

nothing calls this directly

Calls 2

stringEndFunction · 0.85
referenceStringEndFunction · 0.85

Tested by

no test coverage detected