-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscan_sql_test.go
More file actions
71 lines (66 loc) · 1.42 KB
/
Copy pathscan_sql_test.go
File metadata and controls
71 lines (66 loc) · 1.42 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
66
67
68
69
70
71
package highlight
import (
"testing"
"github.com/croaky/is"
)
func TestScanSQL(t *testing.T) {
for _, tt := range []struct {
name string
in state
line string
want string
out state
}{
{
name: "keywords are case-insensitive",
line: "select id from jobs WHERE n = 1",
want: "k:select|: id |k:from|: jobs |k:WHERE|: n = |m:1",
},
{
name: "line comment",
line: "commit; -- why",
want: "k:commit|:; |c:-- why",
},
{
name: "string on one line",
line: "where state = 'queued'",
want: "k:where|: state = |s:'queued'",
},
{
name: "string left open",
line: "insert into notes values ('first",
want: "k:insert|: |k:into|: notes |k:values|: (|s:'first",
out: stateSingleQuote,
},
{
name: "string closing",
in: stateSingleQuote,
line: "second');",
want: "s:second'|:);",
},
{
name: "block comment left open",
line: "/* the index is",
want: "c:/* the index is",
out: stateBlockComment,
},
{
name: "block comment closing",
in: stateBlockComment,
line: "for the dashboard */ create index",
want: "c:for the dashboard */|: |k:create|: |k:index",
},
{
name: "quoted identifier",
line: `select "order" from t`,
want: `k:select|: |n:"order"|: |k:from|: t`,
},
} {
t.Run(tt.name, func(t *testing.T) {
is := is.NewRelaxed(t)
ts, out := scanSQL(tt.in, tt.line)
is.Eq(formatTokens(ts), tt.want)
is.Eq(out, tt.out)
})
}
}