=========================================================================== FuzzFindAllSubmatchStdlib - Fuzz FindAllSubmatch/FindAllStringSubmatch ===========================================================================
(f *testing.F)
| 450 | // =========================================================================== |
| 451 | |
| 452 | func FuzzFindAllSubmatchStdlib(f *testing.F) { |
| 453 | // Add seed corpus with capture patterns |
| 454 | capturePatterns := []string{ |
| 455 | `(a)`, |
| 456 | `(.)`, |
| 457 | `(\d+)`, |
| 458 | `(\w+)`, |
| 459 | `(\w+)=(\d+)`, |
| 460 | `(\w+)@(\w+)`, |
| 461 | } |
| 462 | |
| 463 | for _, p := range capturePatterns { |
| 464 | for _, i := range seedInputs { |
| 465 | f.Add(p, i) |
| 466 | } |
| 467 | } |
| 468 | |
| 469 | f.Fuzz(func(t *testing.T, pattern, input string) { |
| 470 | // Skip known differences: UTF-8 codepoint vs byte matching |
| 471 | if hasUTF8CodepointDifference(pattern, input) { |
| 472 | return |
| 473 | } |
| 474 | |
| 475 | // Skip known differences: repeated capture groups |
| 476 | if hasRepeatedCaptureGroupDifference(pattern) { |
| 477 | return |
| 478 | } |
| 479 | |
| 480 | // Skip invalid patterns |
| 481 | stdRe, err := regexp.Compile(pattern) |
| 482 | if err != nil { |
| 483 | return |
| 484 | } |
| 485 | |
| 486 | cgRe, err := Compile(pattern) |
| 487 | if err != nil { |
| 488 | t.Fatalf("coregex failed to compile valid pattern %q: %v", pattern, err) |
| 489 | } |
| 490 | |
| 491 | // Compare FindAllSubmatch |
| 492 | stdAllSubmatch := stdRe.FindAllSubmatch([]byte(input), -1) |
| 493 | cgAllSubmatch := cgRe.FindAllSubmatch([]byte(input), -1) |
| 494 | if !equalNestedByteSlices(stdAllSubmatch, cgAllSubmatch) { |
| 495 | t.Errorf("FindAllSubmatch(%q, %q) count mismatch or content mismatch", |
| 496 | pattern, input) |
| 497 | } |
| 498 | |
| 499 | // Compare FindAllStringSubmatch |
| 500 | stdAllStrSubmatch := stdRe.FindAllStringSubmatch(input, -1) |
| 501 | cgAllStrSubmatch := cgRe.FindAllStringSubmatch(input, -1) |
| 502 | if !reflect.DeepEqual(stdAllStrSubmatch, cgAllStrSubmatch) { |
| 503 | t.Errorf("FindAllStringSubmatch(%q, %q):\n stdlib: %v\n coregex: %v", |
| 504 | pattern, input, stdAllStrSubmatch, cgAllStrSubmatch) |
| 505 | } |
| 506 | |
| 507 | // Compare FindAllSubmatchIndex |
| 508 | stdAllSubmatchIdx := stdRe.FindAllSubmatchIndex([]byte(input), -1) |
| 509 | cgAllSubmatchIdx := cgRe.FindAllSubmatchIndex([]byte(input), -1) |
nothing calls this directly
no test coverage detected