forked from ClickHouse/clickhouse-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers_test.go
53 lines (48 loc) · 1.86 KB
/
helpers_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
51
52
53
package clickhouse
import (
"testing"
"github.com/stretchr/testify/assert"
)
func Test_NumInput(t *testing.T) {
for query, num := range map[string]int{
"SELECT * FROM example WHERE os_id = 42": 0,
"SELECT * FROM example WHERE email = 'name@mail'": 0,
"SELECT * FROM example WHERE os_id = @os_id AND browser_id = @os_id": 1,
"SELECT * FROM example WHERE os_id = @os_id AND browser_id = @os_id2": 2,
"SELECT * FROM example WHERE os_id in (@os_id,@browser_id) browser_id = @browser_id": 2,
"SELECT * FROM example WHERE os_id IN (@os_id, @browser_id) AND browser_id = @browser_id": 2,
"SELECT * FROM example WHERE os_id = ? AND browser_id = ?": 2,
"SELECT * FROM example WHERE os_id in (?,?) browser_id = ?": 3,
"SELECT * FROM example WHERE os_id IN (?, ?) AND browser_id = ?": 3,
"SELECT a ? '+' : '-'": 0,
"SELECT a ? '+' : '-' FROM example WHERE a = ? AND b IN(?)": 2,
`SELECT
a ? '+' : '-'
FROM example WHERE a = 42 and b in(
?,
?,
?
)
`: 3,
"SELECT * from EXAMPLE LIMIT ?": 1,
"SELECT * from EXAMPLE LIMIT ?, ?": 2,
} {
assert.Equal(t, num, numInput(query), query)
}
}
func Benchmark_NumInput(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
numInput("SELECT * FROM example WHERE os_id in (@os_id,@browser_id) browser_id = @browser_id")
}
}
func Test_Quote(t *testing.T) {
for expected, value := range map[string]interface{}{
"'a'": "a",
"1": 1,
"'a', 'b', 'c'": []string{"a", "b", "c"},
"1, 2, 3, 4, 5": []int{1, 2, 3, 4, 5},
} {
assert.Equal(t, expected, quote(value))
}
}