github.com/grpc-ecosystem/grpc-gateway/v2@v2.19.1/protoc-gen-openapiv2/internal/genopenapi/template_fuzz_test.go (about) 1 //go:build go1.18 2 // +build go1.18 3 4 package genopenapi 5 6 import ( 7 "regexp" 8 "testing" 9 ) 10 11 var replaceInternalCommentsRegex = regexp.MustCompile(`(?s)(\r?\n)?[ \t]*(\(--)((.*?--\))|.*$)?`) 12 13 func FuzzRemoveInternalComments(f *testing.F) { 14 f.Add("Text\n\n(-- Comment --)\n\nMore Text\n") 15 f.Add("Text\n\n(-- Multi\nLine\n\nComment --)\n\nMore Text\n") 16 f.Add("(-- Starting with comment --)\n\nMore Text\n") 17 f.Add("\n\n(-- Starting with new line and comment --)\n\nMore Text\n") 18 f.Add("Ending with\n\n(-- Comment --)") 19 f.Fuzz(func(t *testing.T, s string) { 20 s1 := removeInternalComments(s) 21 s2 := replaceInternalCommentsRegex.ReplaceAllString(s, "") 22 if s1 != s2 { 23 t.Errorf("Unexpected comment removal difference: our function produced %q but regex produced %q on %q", s1, s2, s) 24 } 25 }) 26 }