MCPcopy Create free account
hub / github.com/coregx/coregex / FuzzFindSubmatchStdlib

Function FuzzFindSubmatchStdlib

fuzz_stdlib_test.go:369–446  ·  view source on GitHub ↗

=========================================================================== FuzzFindSubmatchStdlib - Fuzz FindSubmatch/FindStringSubmatch ===========================================================================

(f *testing.F)

Source from the content-addressed store, hash-verified

367// ===========================================================================
368
369func 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",

Callers

nothing calls this directly

Calls 10

equalByteSlicesFunction · 0.85
toStringSliceFunction · 0.85
AddMethod · 0.80
CompileMethod · 0.80
FindStringSubmatchMethod · 0.80
FindSubmatchIndexMethod · 0.80
CompileFunction · 0.70
FindSubmatchMethod · 0.45

Tested by

no test coverage detected