forked from pganalyze/pg_query_go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
normalize_test.go
53 lines (45 loc) · 1.11 KB
/
normalize_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
package pg_query_test
import (
"errors"
"reflect"
"testing"
"github.com/lfittl/pg_query_go"
)
var normalizeTests = []struct {
input string
expected string
}{
{
"SELECT 1",
"SELECT $1",
},
}
func TestNormalize(t *testing.T) {
for _, test := range normalizeTests {
actual, err := pg_query.Normalize(test.input)
if err != nil {
t.Errorf("Normalize(%s)\nerror %s\n\n", test.input, err)
} else if !reflect.DeepEqual(actual, test.expected) {
t.Errorf("Normalize(%s)\nexpected %s\nactual %s\n\n", test.input, test.expected, actual)
}
}
}
var normalizeErrorTests = []struct {
input string
expectedErr error
}{
{
"SELECT $",
errors.New("syntax error at or near \"$\""),
},
}
func TestNormalizeError(t *testing.T) {
for _, test := range normalizeErrorTests {
_, actualErr := pg_query.Normalize(test.input)
if actualErr == nil {
t.Errorf("Normalize(%s)\nexpected error but none returned\n\n", test.input)
} else if !reflect.DeepEqual(actualErr, test.expectedErr) {
t.Errorf("Normalize(%s)\nexpected error %s\nactual error %s\n\n", test.input, test.expectedErr, actualErr)
}
}
}