Skip to content

Commit 0398d35

Browse files
committed
add test cases
1 parent 5883e6f commit 0398d35

File tree

1 file changed

+75
-5
lines changed

1 file changed

+75
-5
lines changed

internal/value/value_test.go

Lines changed: 75 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,105 @@
11
package value
22

33
import (
4-
"bytes"
54
"testing"
65
)
76

87
func TestValueToString(t *testing.T) {
9-
for _, test := range []struct {
8+
for _, tt := range []struct {
109
value V
1110
exp string
1211
}{
1312
{
1413
value: VoidValue,
14+
exp: "Void(NULL)",
15+
},
16+
{
17+
value: UTF8Value("foo"),
18+
exp: "Utf8(foo)",
19+
},
20+
{
21+
value: StringValue([]byte("foo")),
22+
exp: "String([102 111 111])",
23+
},
24+
{
25+
value: BoolValue(true),
26+
exp: "Bool(true)",
27+
},
28+
{
29+
value: Int8Value(42),
30+
exp: "Int8(42)",
31+
},
32+
{
33+
value: Uint8Value(42),
34+
exp: "Uint8(42)",
35+
},
36+
{
37+
value: Int16Value(42),
38+
exp: "Int16(42)",
39+
},
40+
{
41+
value: Uint16Value(42),
42+
exp: "Uint16(42)",
1543
},
1644
{
1745
value: Int32Value(42),
46+
exp: "Int32(42)",
47+
},
48+
{
49+
value: Uint32Value(42),
50+
exp: "Uint32(42)",
51+
},
52+
{
53+
value: Int64Value(42),
54+
exp: "Int64(42)",
55+
},
56+
{
57+
value: Uint64Value(42),
58+
exp: "Uint64(42)",
59+
},
60+
{
61+
value: FloatValue(42),
62+
exp: "Float(42)",
63+
},
64+
{
65+
value: DoubleValue(42),
66+
exp: "Double(42)",
67+
},
68+
{
69+
value: IntervalValue(42),
70+
exp: "Interval(42)",
71+
},
72+
{
73+
value: TimestampValue(42),
74+
exp: "Timestamp(42)",
1875
},
1976
{
2077
value: NullValue(TypeInt32),
78+
exp: "Optional<Int32>(NULL)",
2179
},
2280
{
2381
value: NullValue(OptionalType{T: TypeBool}),
82+
exp: "Optional<Optional<Bool>>((NULL))",
2483
},
2584
{
2685
value: OptionalValue(OptionalValue(Int32Value(42))),
86+
exp: "Optional<Optional<Int32>>((42))",
2787
},
2888
{
2989
value: OptionalValue(OptionalValue(OptionalValue(Int32Value(42)))),
90+
exp: "Optional<Optional<Optional<Int32>>>(((42)))",
3091
},
3192
{
3293
value: ListValue(4, func(i int) V {
3394
return Int32Value(int32(i))
3495
}),
96+
exp: "List<Int32>((0)(1)(2)(3))",
3597
},
3698
{
3799
value: TupleValue(4, func(i int) V {
38100
return Int32Value(int32(i))
39101
}),
102+
exp: "Tuple<Int32,Int32,Int32,Int32>((0)(1)(2)(3))",
40103
},
41104
{
42105
value: VariantValue(Int32Value(42), 1, VariantType{T: TupleType{
@@ -45,6 +108,7 @@ func TestValueToString(t *testing.T) {
45108
TypeInt32,
46109
},
47110
}}),
111+
exp: "Variant<Tuple<String,Int32>>(1=(42))",
48112
},
49113
{
50114
value: VariantValue(Int32Value(42), 1, VariantType{S: StructType{
@@ -53,6 +117,7 @@ func TestValueToString(t *testing.T) {
53117
{"bar", TypeInt32},
54118
},
55119
}}),
120+
exp: "Variant<Struct<foo:String,bar:Int32>>(bar=(42))",
56121
},
57122
{
58123
value: DictValue(4, func(i int) V {
@@ -72,6 +137,7 @@ func TestValueToString(t *testing.T) {
72137
}
73138
panic("whoa")
74139
}),
140+
exp: "Dict<Utf8,Int32>(((foo)(42))((bar)(43)))",
75141
},
76142
{
77143
value: DictValue(4, func(i int) V {
@@ -88,21 +154,25 @@ func TestValueToString(t *testing.T) {
88154
}
89155
panic("whoa")
90156
}),
157+
exp: "Dict<Utf8,Void>(((foo)(NULL))((bar)(NULL)))",
91158
},
92159
{
93160
value: ZeroValue(OptionalType{T: TypeBool}),
161+
exp: "Optional<Bool>(NULL)",
94162
},
95163
{
96164
value: ZeroValue(ListType{T: TypeBool}),
165+
exp: "List<Bool>()",
97166
},
98167
{
99168
value: ZeroValue(TypeUUID),
169+
exp: "Uuid([0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0])",
100170
},
101171
} {
102172
t.Run("", func(t *testing.T) {
103-
var buf bytes.Buffer
104-
test.value.toString(&buf)
105-
t.Logf("STRING: %q", buf.String())
173+
if got := tt.value.String(); got != tt.exp {
174+
t.Errorf("got: %s, want: %s", got, tt.exp)
175+
}
106176
})
107177
}
108178
}

0 commit comments

Comments
 (0)