-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathmeta_test.go
More file actions
65 lines (57 loc) · 1.49 KB
/
meta_test.go
File metadata and controls
65 lines (57 loc) · 1.49 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
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
61
62
63
64
65
package metadata
import "testing"
func TestParseQueryNameAndType(t *testing.T) {
for _, query := range []string{
`-- name: CreateFoo, :one`,
`-- name: 9Foo_, :one`,
`-- name: CreateFoo :two`,
`-- name: CreateFoo`,
`-- name: CreateFoo :one something`,
`-- name: `,
`--name: CreateFoo :one`,
`--name CreateFoo :one`,
`--name: CreateFoo :two`,
"-- name:CreateFoo",
`--name:CreateFoo :two`,
} {
if _, _, err := ParseQueryNameAndType(query, CommentSyntax{Dash: true}); err == nil {
t.Errorf("expected invalid metadata: %q", query)
}
}
for _, query := range []string{
`-- some comment`,
`-- name comment`,
`--name comment`,
} {
if _, _, err := ParseQueryNameAndType(query, CommentSyntax{Dash: true}); err != nil {
t.Errorf("expected valid comment: %q", query)
}
}
query := `-- name: CreateFoo :one`
queryName, queryType, err := ParseQueryNameAndType(query, CommentSyntax{Dash: true})
if err != nil {
t.Errorf("expected valid metadata: %q", query)
}
if queryName != "CreateFoo" {
t.Errorf("incorrect queryName parsed: %q", query)
}
if queryType != CmdOne {
t.Errorf("incorrect queryType parsed: %q", query)
}
}
func TestParseQueryFlags(t *testing.T) {
for _, comments := range [][]string{
{
"-- name: CreateFoo :one",
"-- @flag-foo",
},
} {
flags, _, err := ParseQueryFlags(comments)
if err != nil {
t.Errorf("expected query flags to parse, got error: %s", err)
}
if !flags["@flag-foo"] {
t.Errorf("expected flag not found")
}
}
}