forked from grindlemire/go-lucene
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fuzz_test.go
60 lines (52 loc) · 1.37 KB
/
fuzz_test.go
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package lucene
import (
"strings"
"testing"
"github.com/AlxBystrov/go-lucene/pkg/driverclick"
pg_query "github.com/pganalyze/pg_query_go/v4"
)
func FuzzPostgresDriver(f *testing.F) {
tcs := []string{
"A:B AND C:D",
"+foo OR (NOT(B))",
"A:bar",
"NOT(b:c)",
"z:[* TO 10]",
"x:[10 TO *] AND NOT(y:[1 TO 5]",
"(+a:b -c:d) OR (z:[1 TO *] NOT(foo))",
`+bbq:"woo yay"`,
`-bbq:"woo"`,
`(a:b)^10`,
`a:foo~`,
}
for _, tc := range tcs {
f.Add(tc)
}
f.Fuzz(func(t *testing.T, in string) {
e, err := Parse(in)
if err != nil {
// Ignore invalid expressions.
return
}
f, err := driverclick.NewClickhouseDriver().Render(e)
if err != nil {
// Ignore errors that are expected.
if strings.Contains(err.Error(), "unable to render operator") ||
strings.Contains(err.Error(), "literal contains invalid utf8") ||
strings.Contains(err.Error(), "literal contains null byte") ||
strings.Contains(err.Error(), "column name contains a double quote") ||
strings.Contains(err.Error(), "column name is empty") ||
strings.Contains(err.Error(), "the BETWEEN operator needs a two item list in the right hand side") {
return
}
t.Fatal(err)
}
j, err := pg_query.ParseToJSON("SELECT * FROM test WHERE a = b AND (" + f + ")")
if err != nil {
t.Fatal(err)
}
if strings.Contains(j, "CommentStmt") {
t.Fatal("CommentStmt found")
}
})
}