File: template_fuzz_test.go

package info (click to toggle)
golang-github-grpc-ecosystem-grpc-gateway 2.20.0-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid, trixie
  • size: 7,236 kB
  • sloc: javascript: 357; makefile: 147; sh: 26
file content (26 lines) | stat: -rw-r--r-- 795 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
//go:build go1.18
// +build go1.18

package genopenapi

import (
	"regexp"
	"testing"
)

var replaceInternalCommentsRegex = regexp.MustCompile(`(?s)(\r?\n)?[ \t]*(\(--)((.*?--\))|.*$)?`)

func FuzzRemoveInternalComments(f *testing.F) {
	f.Add("Text\n\n(-- Comment --)\n\nMore Text\n")
	f.Add("Text\n\n(-- Multi\nLine\n\nComment --)\n\nMore Text\n")
	f.Add("(-- Starting with comment --)\n\nMore Text\n")
	f.Add("\n\n(-- Starting with new line and comment --)\n\nMore Text\n")
	f.Add("Ending with\n\n(-- Comment --)")
	f.Fuzz(func(t *testing.T, s string) {
		s1 := removeInternalComments(s)
		s2 := replaceInternalCommentsRegex.ReplaceAllString(s, "")
		if s1 != s2 {
			t.Errorf("Unexpected comment removal difference: our function produced %q but regex produced %q on %q", s1, s2, s)
		}
	})
}