MCPcopy Create free account
hub / github.com/segmentio/encoding / TestTokenizer_invalidInput

Function TestTokenizer_invalidInput

json/token_test.go:199–231  ·  view source on GitHub ↗

Regression test for syntax that caused panics in Next.

(t *testing.T)

Source from the content-addressed store, hash-verified

197
198// Regression test for syntax that caused panics in Next.
199func TestTokenizer_invalidInput(t *testing.T) {
200 tests := []struct {
201 scenario string
202 payload []byte
203 }{
204 {
205 scenario: "bare comma",
206 payload: []byte(","),
207 },
208 {
209 scenario: "comma after array",
210 payload: []byte("[],"),
211 },
212 {
213 scenario: "comma after object",
214 payload: []byte("{},"),
215 },
216 }
217
218 for _, test := range tests {
219 t.Run(test.scenario, func(t *testing.T) {
220 tkn := NewTokenizer(test.payload)
221
222 // This shouldn't panic
223 for tkn.Next() {
224 }
225
226 if tkn.Err == nil {
227 t.Error("expected Err to be set, got nil")
228 }
229 })
230 }
231}
232
233func BenchmarkTokenizer(b *testing.B) {
234 values := []struct {

Callers

nothing calls this directly

Calls 3

NextMethod · 0.95
NewTokenizerFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…