=========================================================================== FuzzFindSubmatchStdlib - Fuzz FindSubmatch/FindStringSubmatch ===========================================================================
(f *testing.F)
| 367 | // =========================================================================== |
| 368 | |
| 369 | func FuzzFindSubmatchStdlib(f *testing.F) { |
| 370 | // Add seed corpus with patterns that have capture groups |
| 371 | capturePatterns := []string{ |
| 372 | `(a)`, |
| 373 | `(a)(b)`, |
| 374 | `(a|b)`, |
| 375 | `(.*)`, |
| 376 | `(.+)`, |
| 377 | `(\d+)`, |
| 378 | `(\w+)`, |
| 379 | `(\w+)@(\w+)`, |
| 380 | `(\w+)-(\d+)`, |
| 381 | `^(.+)-(\d+)$`, |
| 382 | `(([a-z]+)(\d+))`, |
| 383 | `(?P<name>\w+)`, |
| 384 | `(?P<first>\w+)\s+(?P<second>\w+)`, |
| 385 | `(a)*`, |
| 386 | `(a)+`, |
| 387 | `(a)?`, |
| 388 | `((a|b)*)`, |
| 389 | } |
| 390 | |
| 391 | for _, p := range capturePatterns { |
| 392 | for _, i := range seedInputs { |
| 393 | f.Add(p, i) |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | f.Fuzz(func(t *testing.T, pattern, input string) { |
| 398 | // Skip known differences: repeated capture groups |
| 399 | if hasRepeatedCaptureGroupDifference(pattern) { |
| 400 | return |
| 401 | } |
| 402 | |
| 403 | // Skip invalid patterns |
| 404 | stdRe, err := regexp.Compile(pattern) |
| 405 | if err != nil { |
| 406 | return |
| 407 | } |
| 408 | |
| 409 | cgRe, err := Compile(pattern) |
| 410 | if err != nil { |
| 411 | t.Fatalf("coregex failed to compile valid pattern %q: %v", pattern, err) |
| 412 | } |
| 413 | |
| 414 | // Compare FindSubmatch |
| 415 | stdSubmatch := stdRe.FindSubmatch([]byte(input)) |
| 416 | cgSubmatch := cgRe.FindSubmatch([]byte(input)) |
| 417 | if !equalByteSlices(stdSubmatch, cgSubmatch) { |
| 418 | t.Errorf("FindSubmatch(%q, %q):\n stdlib: %v\n coregex: %v", |
| 419 | pattern, input, toStringSlice(stdSubmatch), toStringSlice(cgSubmatch)) |
| 420 | } |
| 421 | |
| 422 | // Compare FindStringSubmatch |
| 423 | stdStrSubmatch := stdRe.FindStringSubmatch(input) |
| 424 | cgStrSubmatch := cgRe.FindStringSubmatch(input) |
| 425 | if !reflect.DeepEqual(stdStrSubmatch, cgStrSubmatch) { |
| 426 | t.Errorf("FindStringSubmatch(%q, %q):\n stdlib: %v\n coregex: %v", |
nothing calls this directly
no test coverage detected