TestValueEncode tests Value.decode for all value types
(t *testing.T)
| 188 | |
| 189 | // TestValueEncode tests Value.decode for all value types |
| 190 | func TestValueDecode(t *testing.T) { |
| 191 | noError := errors.New("") |
| 192 | loc1 := time.FixedZone("UTC+3:30", 3*3600+1800) |
| 193 | tm1, _ := time.ParseInLocation(time.RFC3339, "2025-03-29T16:48:53+03:30", loc1) |
| 194 | loc2 := time.FixedZone("UTC-3", -3*3600) |
| 195 | tm2, _ := time.ParseInLocation(time.RFC3339, "2025-03-29T16:48:53-03:00", loc2) |
| 196 | |
| 197 | type testData struct { |
| 198 | data []byte // Input data |
| 199 | v Value // Expected output value |
| 200 | err string // Expected error string ("" if no error) |
| 201 | } |
| 202 | |
| 203 | tests := []testData{ |
| 204 | // Simple types |
| 205 | {[]byte{}, Binary{}, ""}, |
| 206 | {[]byte{1, 2, 3, 4}, Binary{1, 2, 3, 4}, ""}, |
| 207 | {[]byte{0}, Boolean(false), ""}, |
| 208 | {[]byte{1}, Boolean(true), ""}, |
| 209 | {[]byte{0, 1}, Boolean(false), "value must be 1 byte"}, |
| 210 | {[]byte{1, 2, 3, 4}, Integer(0x01020304), ""}, |
| 211 | {[]byte{0xff, 0xff, 0xff, 0xff}, Integer(-1), ""}, |
| 212 | {[]byte{}, Integer(0), "value must be 4 bytes"}, |
| 213 | {[]byte{1, 2, 3, 4, 5}, Integer(0), "value must be 4 bytes"}, |
| 214 | {[]byte{}, Void{}, ""}, |
| 215 | {[]byte("hello"), String("hello"), ""}, |
| 216 | {[]byte{1, 2, 3, 4, 5}, Void{}, ""}, |
| 217 | |
| 218 | // Range |
| 219 | { |
| 220 | data: []byte{1, 2, 3, 4, 5, 6, 7, 8}, |
| 221 | v: Range{0x01020304, 0x05060708}, |
| 222 | }, |
| 223 | |
| 224 | { |
| 225 | data: []byte{ |
| 226 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
| 227 | }, |
| 228 | v: Range{-1, -1}, |
| 229 | }, |
| 230 | |
| 231 | { |
| 232 | data: []byte{1, 2, 3, 4, 5, 6, 7}, |
| 233 | v: Range{}, |
| 234 | err: "value must be 8 bytes", |
| 235 | }, |
| 236 | |
| 237 | { |
| 238 | data: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9}, |
| 239 | v: Range{}, |
| 240 | err: "value must be 8 bytes", |
| 241 | }, |
| 242 | |
| 243 | // Resolution |
| 244 | { |
| 245 | data: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9}, |
| 246 | v: Resolution{0x01020304, 0x05060708, 0x09}, |
| 247 | }, |