forked from denisenkom/go-mssqldb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser_test.go
50 lines (47 loc) · 1.57 KB
/
parser_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
package mssql
import (
"testing"
)
func TestParseParams(t *testing.T) {
values := []struct {
s string
d string
n int
}{
{"select ?", "select @p1", 1},
{"select ?, ?", "select @p1, @p2", 2},
{"select ? -- ?", "select @p1 -- ?", 1},
{"select ? -- ?\n, ?", "select @p1 -- ?\n, @p2", 2},
{"select ? - ?", "select @p1 - @p2", 2},
{"select ? /* ? */, ?", "select @p1 /* ? */, @p2", 2},
{"select ? /* ? * ? */, ?", "select @p1 /* ? * ? */, @p2", 2},
{"select \"foo?\", [foo?], 'foo?', ?", "select \"foo?\", [foo?], 'foo?', @p1", 1},
{"select \"x\"\"y\", [x]]y], 'x''y', ?", "select \"x\"\"y\", [x]]y], 'x''y', @p1", 1},
{"select \"foo?\", ?", "select \"foo?\", @p1", 1},
{"select 'foo?', ?", "select 'foo?', @p1", 1},
{"select [foo?], ?", "select [foo?], @p1", 1},
{"select $1", "select @p1", 1},
{"select $1, $2", "select @p1, @p2", 2},
{"select $1, $1", "select @p1, @p1", 1},
{"select :1", "select @p1", 1},
{"select :1, :2", "select @p1, @p2", 2},
{"select :1, :1", "select @p1, @p1", 1},
{"select ?1", "select @p1", 1},
{"select ?1, ?2", "select @p1, @p2", 2},
{"select ?1, ?1", "select @p1, @p1", 1},
{"select $12", "select @p12", 12},
{"select ? /* ? /* ? */ ? */ ?", "select @p1 /* ? /* ? */ ? */ @p2", 2},
{"select ? /* ? / ? */ ?", "select @p1 /* ? / ? */ @p2", 2},
{"select $", "select $", 0},
{"select x::y", "select x::y", 0},
}
for _, v := range values {
d, n := parseParams(v.s)
if d != v.d {
t.Error("Parse params don't match ", d, v.d)
}
if n != v.n {
t.Error("Parse number of params don't match", n, v.n)
}
}
}