Regression test for syntax that caused panics in Next.
(t *testing.T)
| 197 | |
| 198 | // Regression test for syntax that caused panics in Next. |
| 199 | func 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 | |
| 233 | func BenchmarkTokenizer(b *testing.B) { |
| 234 | values := []struct { |
nothing calls this directly
no test coverage detected
searching dependent graphs…