=========================================================================== FuzzQuoteMetaStdlib - Fuzz QuoteMeta ===========================================================================
(f *testing.F)
| 709 | // =========================================================================== |
| 710 | |
| 711 | func FuzzQuoteMetaStdlib(f *testing.F) { |
| 712 | // Seed with strings containing special regex characters |
| 713 | seeds := []string{ |
| 714 | "", |
| 715 | "hello", |
| 716 | "hello.world", |
| 717 | "$100", |
| 718 | "a+b*c?", |
| 719 | "(foo)", |
| 720 | "[abc]", |
| 721 | "^start$", |
| 722 | `\d+`, |
| 723 | "a|b", |
| 724 | "日本語", |
| 725 | `!"#$%&'()*+,-./:;<=>?@[\]^_{|}~`, |
| 726 | } |
| 727 | |
| 728 | for _, s := range seeds { |
| 729 | f.Add(s) |
| 730 | } |
| 731 | |
| 732 | f.Fuzz(func(t *testing.T, input string) { |
| 733 | // Skip non-UTF8 strings |
| 734 | if !utf8.ValidString(input) { |
| 735 | return |
| 736 | } |
| 737 | |
| 738 | stdQuoted := regexp.QuoteMeta(input) |
| 739 | cgQuoted := QuoteMeta(input) |
| 740 | |
| 741 | if stdQuoted != cgQuoted { |
| 742 | t.Errorf("QuoteMeta(%q):\n stdlib: %q\n coregex: %q", |
| 743 | input, stdQuoted, cgQuoted) |
| 744 | } |
| 745 | |
| 746 | // Additionally verify that the quoted pattern matches the original |
| 747 | if input != "" && cgQuoted != "" { |
| 748 | stdRe := regexp.MustCompile(stdQuoted) |
| 749 | cgRe := MustCompile(cgQuoted) |
| 750 | |
| 751 | testInput := "prefix" + input + "suffix" |
| 752 | |
| 753 | stdMatch := stdRe.FindString(testInput) |
| 754 | cgMatch := cgRe.FindString(testInput) |
| 755 | |
| 756 | if stdMatch != cgMatch { |
| 757 | t.Errorf("QuoteMeta roundtrip mismatch for %q:\n stdlib match: %q\n coregex match: %q", |
| 758 | input, stdMatch, cgMatch) |
| 759 | } |
| 760 | } |
| 761 | }) |
| 762 | } |
| 763 | |
| 764 | // =========================================================================== |
| 765 | // Helper Functions |
nothing calls this directly
no test coverage detected