add prefix to quoters tests

pull/2136/head
merlin 2024-10-20 18:00:59 +03:00
parent 47cbd8edb8
commit 057937db27
No known key found for this signature in database
GPG Key ID: 7EDDCEA6A90062E0
1 changed files with 17 additions and 6 deletions

View File

@ -7,17 +7,22 @@ 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)
}
@ -25,6 +30,7 @@ func FuzzQuoteString(f *testing.F) {
}
func FuzzQuoteBytes(f *testing.F) {
const prefix = "prefix"
f.Add([]byte(nil))
f.Add([]byte("\n"))
f.Add([]byte("sample text"))
@ -32,10 +38,15 @@ func FuzzQuoteBytes(f *testing.F) {
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)
}