forked from ClickHouse/clickhouse-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenum_test.go
70 lines (67 loc) · 1.88 KB
/
enum_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
package clickhouse
import (
"testing"
"github.com/stretchr/testify/assert"
)
func Test_Parse_Enum(t *testing.T) {
{
if enum, err := parseEnum("Enum8('a' = 2, 'b' = 1)"); assert.NoError(t, err) {
if value, err := enum.toValue("b"); assert.NoError(t, err) {
if v, ok := value.(int8); assert.True(t, ok) {
if assert.Equal(t, int8(1), v) {
if _, err := enum.toValue("z"); !assert.Error(t, err) {
return
}
}
}
}
if value, err := enum.toValue("a"); assert.NoError(t, err) {
if v, ok := value.(int8); assert.True(t, ok) {
assert.Equal(t, int8(2), v)
}
}
}
if enum, err := parseEnum("Enum8('a' = 2, 'b' = 1)"); assert.NoError(t, err) {
if ident, err := enum.toIdent(int8(1)); assert.NoError(t, err) {
assert.Equal(t, "b", ident)
}
if ident, err := enum.toIdent(int8(2)); assert.NoError(t, err) {
if assert.Equal(t, "a", ident) {
if _, err := enum.toIdent(int8(100)); !assert.Error(t, err) {
return
}
}
}
}
}
{
if enum, err := parseEnum("Enum16('a' = 2, 'b' = 1)"); assert.NoError(t, err) {
if value, err := enum.toValue("b"); assert.NoError(t, err) {
if v, ok := value.(int16); assert.True(t, ok) {
if assert.Equal(t, int16(1), v) {
if _, err := enum.toValue("z"); !assert.Error(t, err) {
return
}
}
}
}
if value, err := enum.toValue("a"); assert.NoError(t, err) {
if v, ok := value.(int16); assert.True(t, ok) {
assert.Equal(t, int16(2), v)
}
}
}
if enum, err := parseEnum("Enum16('a' = 2, 'b' = 1)"); assert.NoError(t, err) {
if ident, err := enum.toIdent(int16(1)); assert.NoError(t, err) {
assert.Equal(t, "b", ident)
}
if ident, err := enum.toIdent(int16(2)); assert.NoError(t, err) {
if assert.Equal(t, "a", ident) {
if _, err := enum.toIdent(int16(100)); !assert.Error(t, err) {
return
}
}
}
}
}
}