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

Function FuzzReplaceStdlib

fuzz_stdlib_test.go:529–573  ·  view source on GitHub ↗

=========================================================================== FuzzReplaceStdlib - Fuzz ReplaceAllLiteral/ReplaceAllLiteralString ===========================================================================

(f *testing.F)

Source from the content-addressed store, hash-verified

527// ===========================================================================
528
529func FuzzReplaceStdlib(f *testing.F) {
530 replacements := []string{"", "X", "[$0]", "replacement", "***"}
531
532 for _, p := range seedPatterns {
533 for _, i := range seedInputs {
534 for _, r := range replacements {
535 f.Add(p, i, r)
536 }
537 }
538 }
539
540 f.Fuzz(func(t *testing.T, pattern, input, replacement string) {
541 // Skip known differences: UTF-8 codepoint vs byte matching
542 if hasUTF8CodepointDifference(pattern, input) {
543 return
544 }
545
546 // Skip invalid patterns
547 stdRe, err := regexp.Compile(pattern)
548 if err != nil {
549 return
550 }
551
552 cgRe, err := Compile(pattern)
553 if err != nil {
554 t.Fatalf("coregex failed to compile valid pattern %q: %v", pattern, err)
555 }
556
557 // Compare ReplaceAllLiteral
558 stdReplace := stdRe.ReplaceAllLiteral([]byte(input), []byte(replacement))
559 cgReplace := cgRe.ReplaceAllLiteral([]byte(input), []byte(replacement))
560 if !bytes.Equal(stdReplace, cgReplace) {
561 t.Errorf("ReplaceAllLiteral(%q, %q, %q):\n stdlib: %q\n coregex: %q",
562 pattern, input, replacement, stdReplace, cgReplace)
563 }
564
565 // Compare ReplaceAllLiteralString
566 stdReplaceStr := stdRe.ReplaceAllLiteralString(input, replacement)
567 cgReplaceStr := cgRe.ReplaceAllLiteralString(input, replacement)
568 if stdReplaceStr != cgReplaceStr {
569 t.Errorf("ReplaceAllLiteralString(%q, %q, %q):\n stdlib: %q\n coregex: %q",
570 pattern, input, replacement, stdReplaceStr, cgReplaceStr)
571 }
572 })
573}
574
575// ===========================================================================
576// FuzzSplitStdlib - Fuzz Split

Callers

nothing calls this directly

Calls 6

AddMethod · 0.80
CompileMethod · 0.80
ReplaceAllLiteralMethod · 0.80
CompileFunction · 0.70

Tested by

no test coverage detected