mirror of https://github.com/jackc/pgx.git
add prefix to quoters tests
parent
47cbd8edb8
commit
057937db27
|
@ -7,17 +7,22 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func FuzzQuoteString(f *testing.F) {
|
func FuzzQuoteString(f *testing.F) {
|
||||||
f.Add("")
|
const prefix = "prefix"
|
||||||
f.Add("\n")
|
f.Add("new\nline")
|
||||||
f.Add("sample text")
|
f.Add("sample text")
|
||||||
f.Add("sample q'u'o't'e's")
|
f.Add("sample q'u'o't'e's")
|
||||||
f.Add("select 'quoted $42', $1")
|
f.Add("select 'quoted $42', $1")
|
||||||
|
|
||||||
f.Fuzz(func(t *testing.T, input string) {
|
f.Fuzz(func(t *testing.T, input string) {
|
||||||
got := sanitize.QuoteString(nil, input)
|
got := string(sanitize.QuoteString([]byte(prefix), input))
|
||||||
want := oldQuoteString(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.Errorf("got %q", got)
|
||||||
t.Fatalf("want %q", want)
|
t.Fatalf("want %q", want)
|
||||||
}
|
}
|
||||||
|
@ -25,6 +30,7 @@ func FuzzQuoteString(f *testing.F) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func FuzzQuoteBytes(f *testing.F) {
|
func FuzzQuoteBytes(f *testing.F) {
|
||||||
|
const prefix = "prefix"
|
||||||
f.Add([]byte(nil))
|
f.Add([]byte(nil))
|
||||||
f.Add([]byte("\n"))
|
f.Add([]byte("\n"))
|
||||||
f.Add([]byte("sample text"))
|
f.Add([]byte("sample text"))
|
||||||
|
@ -32,10 +38,15 @@ func FuzzQuoteBytes(f *testing.F) {
|
||||||
f.Add([]byte("select 'quoted $42', $1"))
|
f.Add([]byte("select 'quoted $42', $1"))
|
||||||
|
|
||||||
f.Fuzz(func(t *testing.T, input []byte) {
|
f.Fuzz(func(t *testing.T, input []byte) {
|
||||||
got := sanitize.QuoteBytes(nil, input)
|
got := string(sanitize.QuoteBytes([]byte(prefix), input))
|
||||||
want := oldQuoteBytes(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.Errorf("got %q", got)
|
||||||
t.Fatalf("want %q", want)
|
t.Fatalf("want %q", want)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue