forked from mailru/go-clickhouse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
encoder_test.go
71 lines (64 loc) · 1.58 KB
/
encoder_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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package clickhouse
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
type TestEmbedTuple struct {
C bool
private int
}
type TestTuple struct {
A int
B string
TestEmbedTuple
}
type TestNestedTuple struct {
A *TestTuple
D int
}
func TestTextEncoder(t *testing.T) {
dt := time.Date(2011, 3, 6, 6, 20, 0, 0, time.UTC)
d := time.Date(2012, 5, 31, 0, 0, 0, 0, time.UTC)
testCases := []struct {
value interface{}
expected string
}{
{true, "1"},
{int8(1), "1"},
{int16(1), "1"},
{int32(1), "1"},
{int64(1), "1"},
{int(-1), "-1"},
{uint8(1), "1"},
{uint16(1), "1"},
{uint32(1), "1"},
{uint64(1), "1"},
{uint(1), "1"},
{float32(1), "1"},
{float64(1), "1"},
{dt, "'2011-03-06 06:20:00'"},
{d, "'2012-05-31 00:00:00'"},
{"hello", "'hello'"},
{[]byte("hello"), "hello"},
{`\\'hello`, `'\\\\\'hello'`},
{[]byte(`\\'hello`), `\\'hello`},
{[]int32{1, 2}, "[1,2]"},
{[]int32{}, "[]"},
{Array([]int8{1}), "[1]"},
{Array([]interface{}{Array([]int8{1})}), "[[1]]"},
{[][]int16{{1}}, "[[1]]"},
{[]int16(nil), "[]"},
{(*int16)(nil), "NULL"},
{Tuple(TestTuple{A: 1, B: "2", TestEmbedTuple: TestEmbedTuple{C: true, private: 5}}), "(1,'2',1)"},
{Tuple(TestNestedTuple{A: &TestTuple{A: 1, B: "2", TestEmbedTuple: TestEmbedTuple{C: true}}, D: 4}), "((1,'2',1),4)"},
{[]TestTuple{{A: 1, B: "2", TestEmbedTuple: TestEmbedTuple{C: true, private: 5}}}, "[(1,'2',1)]"},
}
enc := new(textEncoder)
for _, tc := range testCases {
v, err := enc.Encode(tc.value)
if assert.NoError(t, err) {
assert.Equal(t, tc.expected, string(v))
}
}
}