-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathscanner_test.go
49 lines (42 loc) · 966 Bytes
/
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
package dotsql
import (
"bufio"
"strings"
"testing"
)
func TestGetTag(t *testing.T) {
var tests = []struct {
line string
want string
}{
{"SELECT 1+1", ""},
{"-- Some Comment", ""},
{"-- name: ", ""},
{"-- name: find-users-by-name", "find-users-by-name"},
{" -- name: save-user ", "save-user"},
}
for _, c := range tests {
got := getTag(c.line)
if got != c.want {
t.Errorf("isTag('%s') == %s, expect %v", c.line, got, c.want)
}
}
}
func TestScannerRun(t *testing.T) {
sqlFile := `
-- name: all-users
-- Finds all users
SELECT * from USER
-- name: empty-query-should-not-be-stored
-- name: save-user
INSERT INTO users (?, ?, ?)
`
scanner := &Scanner{}
queries := scanner.Run(bufio.NewScanner(strings.NewReader(sqlFile)))
numberOfQueries := len(queries)
expectedQueries := 2
if numberOfQueries != expectedQueries {
t.Errorf("Scanner/Run() has %d queries instead of %d",
numberOfQueries, expectedQueries)
}
}