forked from nleof/goyesql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scanner_test.go
53 lines (45 loc) · 1.04 KB
/
scanner_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 goyesql
import (
"testing"
)
func TestScannerErrTags(t *testing.T) {
tests := map[string]error{
"missing": ErrTagMissing,
"doubloon": ErrTagOverwritten,
}
for key, expectedErr := range tests {
_, err := ParseFile("tests/samples/tag_" + key + ".sql")
if err != expectedErr {
t.Errorf(
"A %s tag should return a '%v' error, got '%v'",
key, expectedErr, err,
)
}
}
}
func TestScannerValid(t *testing.T) {
file := "tests/samples/valid.sql"
queries, err := ParseFile(file)
if err != nil {
t.Fatal(err)
}
expectedQueries := Queries{
"simple": "SELECT * FROM simple;",
"multiline": "SELECT * FROM multiline WHERE line = 42;",
"comments": "SELECT * FROM comments;",
}
if len(queries) != len(expectedQueries) {
t.Errorf(
"%s should return %d requests, got %d",
file, len(expectedQueries), len(queries),
)
}
for key, expectedQuery := range expectedQueries {
if queries[key] != expectedQuery {
t.Errorf(
"%s query should be '%s', got '%s'",
key, expectedQuery, queries[key],
)
}
}
}