-
Notifications
You must be signed in to change notification settings - Fork 89
/
typeparser_test.go
148 lines (144 loc) · 2.72 KB
/
typeparser_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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package clickhouse
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestParseTypeDesc(t *testing.T) {
type testCase struct {
name string
input string
output *TypeDesc
fail bool
}
testCases := []*testCase{
{
name: "plain type",
input: "String",
output: &TypeDesc{Name: "String"},
},
{
name: "nullable type",
input: "Nullable(Nothing)",
output: &TypeDesc{
Name: "Nullable",
Args: []*TypeDesc{{Name: "Nothing"}},
},
},
{
name: "empty arg",
input: "DateTime()",
output: &TypeDesc{Name: "DateTime"},
},
{
name: "numeric arg",
input: "FixedString(42)",
output: &TypeDesc{
Name: "FixedString",
Args: []*TypeDesc{{Name: "42"}},
},
},
{
name: "args are ignored for Enum",
input: "Enum8(you can = put, 'whatever' here)",
output: &TypeDesc{Name: "Enum8"},
},
{
name: "quoted arg",
input: "DateTime('UTC')",
output: &TypeDesc{
Name: "DateTime",
Args: []*TypeDesc{{Name: "UTC"}},
},
},
{
name: "decimal",
input: "Decimal(9,4)",
output: &TypeDesc{
Name: "Decimal",
Args: []*TypeDesc{{Name: "9"}, {Name: "4"}},
},
},
{
name: "quoted escaped arg",
input: `DateTime('UTC\b\r\n\'\f\t\0')`,
output: &TypeDesc{
Name: "DateTime",
Args: []*TypeDesc{{Name: "UTC\b\r\n'\f\t\x00"}},
},
},
{
name: "nested args",
input: "Array(Tuple(Tuple(String, String), Tuple(String, UInt64)))",
output: &TypeDesc{
Name: "Array",
Args: []*TypeDesc{
{
Name: "Tuple",
Args: []*TypeDesc{
{
Name: "Tuple",
Args: []*TypeDesc{{Name: "String"}, {Name: "String"}},
},
{
Name: "Tuple",
Args: []*TypeDesc{{Name: "String"}, {Name: "UInt64"}},
},
},
},
},
},
},
{
name: "map args",
input: "Map(String, Array(Int64))",
output: &TypeDesc{
Name: "Map",
Args: []*TypeDesc{
{
Name: "String",
},
{
Name: "Array",
Args: []*TypeDesc{{Name: "Int64"}},
},
},
},
},
{
name: "unfinished arg list",
input: "Array(Tuple(Tuple(String, String), Tuple(String, UInt64))",
fail: true,
},
{
name: "left paren without name",
input: "(",
fail: true,
},
{
name: "unfinished quote",
input: "Array(')",
fail: true,
},
{
name: "unfinished escape",
input: `Array(\`,
fail: true,
},
{
name: "stuff after end",
input: `Array() String`,
fail: true,
},
}
for _, tc := range testCases {
t.Run(tc.name, func(tt *testing.T) {
output, err := ParseTypeDesc(tc.input)
if tc.fail {
assert.Error(tt, err)
} else {
assert.NoError(tt, err)
}
assert.Equal(tt, tc.output, output)
})
}
}