@@ -70,48 +70,96 @@ func TestMarshalInt32Slice(t *testing.T) {
70
70
})
71
71
}
72
72
73
+ func TestMarshalInt32SliceNil (t * testing.T ) {
74
+ testMarshalBasicSlice (t , []int32 {}, func (v []byte ) (interface {}, error ) {
75
+ return ToInt32Slice (v )
76
+ })
77
+ }
78
+
73
79
func TestMarshalUInt32Slice (t * testing.T ) {
74
80
testMarshalBasicSlice (t , []uint32 {11 , 22 }, func (v []byte ) (interface {}, error ) {
75
81
return ToUInt32Slice (v )
76
82
})
77
83
}
78
84
85
+ func TestMarshalUInt32SliceNil (t * testing.T ) {
86
+ testMarshalBasicSlice (t , []uint32 {}, func (v []byte ) (interface {}, error ) {
87
+ return ToUInt32Slice (v )
88
+ })
89
+ }
90
+
79
91
func TestMarshalInt64Slice (t * testing.T ) {
80
92
testMarshalBasicSlice (t , []int64 {- 4097 , 255 }, func (v []byte ) (interface {}, error ) {
81
93
return ToInt64Slice (v )
82
94
})
83
95
}
84
96
97
+ func TestMarshalInt64SliceNil (t * testing.T ) {
98
+ testMarshalBasicSlice (t , []int64 {}, func (v []byte ) (interface {}, error ) {
99
+ return ToInt64Slice (v )
100
+ })
101
+ }
102
+
85
103
func TestMarshalUInt64Slice (t * testing.T ) {
86
104
testMarshalBasicSlice (t , []uint64 {0 , 1 }, func (v []byte ) (interface {}, error ) {
87
105
return ToUInt64Slice (v )
88
106
})
89
107
}
90
108
109
+ func TestMarshalUInt64SliceNil (t * testing.T ) {
110
+ testMarshalBasicSlice (t , []uint64 {}, func (v []byte ) (interface {}, error ) {
111
+ return ToUInt64Slice (v )
112
+ })
113
+ }
114
+
91
115
func TestMarshalFloat32Slice (t * testing.T ) {
92
116
testMarshalBasicSlice (t , []float32 {0.25 , 0.375 }, func (v []byte ) (interface {}, error ) {
93
117
return ToFloat32Slice (v )
94
118
})
95
119
}
96
120
121
+ func TestMarshalFloat32SliceNil (t * testing.T ) {
122
+ testMarshalBasicSlice (t , []float32 {}, func (v []byte ) (interface {}, error ) {
123
+ return ToFloat32Slice (v )
124
+ })
125
+ }
126
+
97
127
func TestMarshalFloat64Slice (t * testing.T ) {
98
128
testMarshalBasicSlice (t , []float64 {0.12 , 0.45 }, func (v []byte ) (interface {}, error ) {
99
129
return ToFloat64Slice (v )
100
130
})
101
131
}
102
132
133
+ func TestMarshalFloat64SliceNil (t * testing.T ) {
134
+ testMarshalBasicSlice (t , []float64 {}, func (v []byte ) (interface {}, error ) {
135
+ return ToFloat64Slice (v )
136
+ })
137
+ }
138
+
103
139
func TestMarshalBoolSlice (t * testing.T ) {
104
140
testMarshalBasicSlice (t , []bool {true , false }, func (v []byte ) (interface {}, error ) {
105
141
return ToBoolSlice (v )
106
142
})
107
143
}
108
144
145
+ func TestMarshalBoolSliceNil (t * testing.T ) {
146
+ testMarshalBasicSlice (t , []bool {}, func (v []byte ) (interface {}, error ) {
147
+ return ToBoolSlice (v )
148
+ })
149
+ }
150
+
109
151
func TestMarshalUTF8StringSlice (t * testing.T ) {
110
152
testMarshalBasicSlice (t , []string {"a" , "b" }, func (v []byte ) (interface {}, error ) {
111
153
return ToUTF8StringSlice (v )
112
154
})
113
155
}
114
156
157
+ func TestMarshalUTF8StringSliceNil (t * testing.T ) {
158
+ testMarshalBasicSlice (t , []string {}, func (v []byte ) (interface {}, error ) {
159
+ return ToUTF8StringSlice (v )
160
+ })
161
+ }
162
+
115
163
func testMarshalBasicSlice (t * testing.T , expected interface {}, converter func (v []byte ) (interface {}, error )) {
116
164
flag := false
117
165
@@ -263,6 +311,32 @@ func TestMarshalObjectSlice(t *testing.T) {
263
311
}
264
312
}
265
313
314
+ func TestMarshalObjectSliceNil (t * testing.T ) {
315
+ flag := false
316
+ input := exampleSliceNil {
317
+ Names : []string {},
318
+ }
319
+
320
+ codec := NewCodec (0x30 )
321
+ inputBuf , _ := codec .Marshal (input )
322
+ testPrintf ("inputBuf=%v\n " , utils .FormatBytes (inputBuf ))
323
+
324
+ testDecoder (0x10 , inputBuf , func (v []byte ) (interface {}, error ) {
325
+ flag = true
326
+ testPrintf ("v=%#x\n " , v )
327
+ var mold []string
328
+ err := ToObject (v , & mold )
329
+ assert .NoError (t , err , fmt .Sprintf ("decode error:%v" , err ))
330
+ testPrintf ("mold=%v\n " , mold )
331
+ assert .Equal (t , 0 , len (mold ), fmt .Sprintf ("value len does not match(%v): %v" , 0 , len (mold )))
332
+ return mold , err
333
+ })
334
+
335
+ if ! flag {
336
+ t .Errorf ("Observable does not listen to values" )
337
+ }
338
+ }
339
+
266
340
type exampleData struct {
267
341
Name string `y3:"0x10"`
268
342
Noise float32 `y3:"0x11"`
@@ -277,3 +351,7 @@ type thermometer struct {
277
351
type exampleSlice struct {
278
352
Therms []thermometer `y3:"0x12"`
279
353
}
354
+
355
+ type exampleSliceNil struct {
356
+ Names []string `y3:"0x10"`
357
+ }
0 commit comments