forked from ClickHouse/clickhouse-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers_test.go
40 lines (36 loc) · 1.52 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
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,
} {
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")
}
}