forked from sqlc-dev/sqlc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquery_comments_test.go
More file actions
62 lines (52 loc) · 1.47 KB
/
Copy pathquery_comments_test.go
File metadata and controls
62 lines (52 loc) · 1.47 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
package cmd
import (
"testing"
"github.com/google/go-cmp/cmp"
"github.com/sqlc-dev/sqlc/internal/config"
"github.com/sqlc-dev/sqlc/internal/plugin"
)
func TestApplyQueryComments(t *testing.T) {
req := &plugin.GenerateRequest{
Queries: []*plugin.Query{
{
Name: "GetAuthor",
Cmd: ":one",
Filename: "query.sql",
Text: "SELECT * FROM authors WHERE id = $1",
},
},
}
applyQueryComments(req, config.QueryComments{
Enabled: true,
Tags: []string{"name", "cmd", "filename"},
})
want := "/*sqlc_name='GetAuthor',sqlc_cmd='%3Aone',sqlc_filename='query.sql'*/ SELECT * FROM authors WHERE id = $1"
if diff := cmp.Diff(want, req.Queries[0].Text); diff != "" {
t.Errorf("query text differed (-want +got):\n%s", diff)
}
}
func TestApplyQueryCommentsMarginalia(t *testing.T) {
req := &plugin.GenerateRequest{
Queries: []*plugin.Query{
{
Name: "GetAuthor",
Text: "SELECT * FROM authors WHERE id = $1",
},
},
}
applyQueryComments(req, config.QueryComments{
Enabled: true,
Format: "marginalia",
})
want := "/*sqlc_name:GetAuthor*/ SELECT * FROM authors WHERE id = $1"
if diff := cmp.Diff(want, req.Queries[0].Text); diff != "" {
t.Errorf("query text differed (-want +got):\n%s", diff)
}
}
func TestEscapeQueryCommentValue(t *testing.T) {
got := escapeQueryCommentValue("a'b,c:d\n*/")
want := "a%27b%2Cc%3Ad * /"
if diff := cmp.Diff(want, got); diff != "" {
t.Errorf("escaped value differed (-want +got):\n%s", diff)
}
}