Skip to content

Commit

Permalink
add prefix to quoters tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ninedraft committed Dec 9, 2024
1 parent 9a33a62 commit 85d5a4d
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions internal/sanitize/sanitize_fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,46 @@ import (
)

func FuzzQuoteString(f *testing.F) {
f.Add("")
f.Add("\n")
const prefix = "prefix"
f.Add("new\nline")
f.Add("sample text")
f.Add("sample q'u'o't'e's")
f.Add("select 'quoted $42', $1")

f.Fuzz(func(t *testing.T, input string) {
got := sanitize.QuoteString(nil, input)
got := string(sanitize.QuoteString([]byte(prefix), input))
want := oldQuoteString(input)

if want != string(got) {
quoted, ok := strings.CutPrefix(got, prefix)
if !ok {
t.Fatalf("result has no prefix")
}

if want != quoted {
t.Errorf("got %q", got)
t.Fatalf("want %q", want)
}
})
}

func FuzzQuoteBytes(f *testing.F) {
const prefix = "prefix"
f.Add([]byte(nil))
f.Add([]byte("\n"))
f.Add([]byte("sample text"))
f.Add([]byte("sample q'u'o't'e's"))
f.Add([]byte("select 'quoted $42', $1"))

f.Fuzz(func(t *testing.T, input []byte) {
got := sanitize.QuoteBytes(nil, input)
got := string(sanitize.QuoteBytes([]byte(prefix), input))
want := oldQuoteBytes(input)

if want != string(got) {
quoted, ok := strings.CutPrefix(got, prefix)
if !ok {
t.Fatalf("result has no prefix")
}

if want != quoted {
t.Errorf("got %q", got)
t.Fatalf("want %q", want)
}
Expand Down

0 comments on commit 85d5a4d

Please sign in to comment.