-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathempty_in_test.go
More file actions
35 lines (33 loc) · 1.1 KB
/
Copy pathempty_in_test.go
File metadata and controls
35 lines (33 loc) · 1.1 KB
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
package sqlparser
import (
"strings"
"testing"
)
func TestEmptyInSet(t *testing.T) {
for _, sql := range []string{
`SELECT id FROM records WHERE id IN ()`,
`SELECT id FROM records WHERE id NOT IN ( ) AND active = 1 ORDER BY id`,
`SELECT id FROM records WHERE active = 1 OR id IN ()`,
`WITH r AS (SELECT id FROM records WHERE id IN ()) SELECT id FROM r`,
`SELECT r.id FROM (SELECT id FROM records WHERE id IN ()) r`,
} {
t.Run(sql, func(t *testing.T) {
parsed, err := ParseQuery(sql)
if err != nil {
t.Fatal(err)
}
output := Stringify(parsed)
if !strings.Contains(output, "IN (") {
t.Fatalf("lost empty set: %s", output)
}
if strings.Contains(sql, "AND active") && (!strings.Contains(output, "active") || len(parsed.OrderBy) != 1) {
t.Fatalf("lost following predicate/order: %s", output)
}
})
}
for _, sql := range []string{`SELECT () FROM records`, `SELECT f(()) FROM records`, `SELECT id FROM records WHERE id IN (,)`, `SELECT id FROM records WHERE id IN (1,)`} {
if _, err := ParseQuery(sql); err == nil {
t.Fatalf("accepted malformed SQL: %s", sql)
}
}
}