TestValueEncode tests Value.encode for all value types
(t *testing.T)
| 19 | |
| 20 | // TestValueEncode tests Value.encode for all value types |
| 21 | func TestValueEncode(t *testing.T) { |
| 22 | noError := errors.New("") |
| 23 | longstr := strings.Repeat("x", 65536) |
| 24 | loc1 := time.FixedZone("UTC+3:30", 3*3600+1800) |
| 25 | tm1, _ := time.ParseInLocation(time.RFC3339, "2025-03-29T16:48:53+03:30", loc1) |
| 26 | loc2 := time.FixedZone("UTC-3", -3*3600) |
| 27 | tm2, _ := time.ParseInLocation(time.RFC3339, "2025-03-29T16:48:53-03:00", loc2) |
| 28 | |
| 29 | type testData struct { |
| 30 | v Value // Input value |
| 31 | data []byte // Expected output data |
| 32 | err string // Expected error string ("" if no error) |
| 33 | } |
| 34 | |
| 35 | tests := []testData{ |
| 36 | // Simple values |
| 37 | {Binary{}, []byte{}, ""}, |
| 38 | {Binary{1, 2, 3}, []byte{1, 2, 3}, ""}, |
| 39 | {Boolean(false), []byte{0}, ""}, |
| 40 | {Boolean(true), []byte{1}, ""}, |
| 41 | {Integer(0), []byte{0, 0, 0, 0}, ""}, |
| 42 | {Integer(0x01020304), []byte{1, 2, 3, 4}, ""}, |
| 43 | {String(""), []byte{}, ""}, |
| 44 | {String("Hello"), []byte("Hello"), ""}, |
| 45 | {Void{}, []byte{}, ""}, |
| 46 | |
| 47 | // Range |
| 48 | { |
| 49 | v: Range{0x01020304, 0x05060708}, |
| 50 | data: []byte{1, 2, 3, 4, 5, 6, 7, 8}, |
| 51 | }, |
| 52 | { |
| 53 | v: Range{-100, 100}, |
| 54 | data: []byte{ |
| 55 | 0xff, 0xff, 0xff, 0x9c, 0x00, 0x00, 0x00, 0x64, |
| 56 | }, |
| 57 | }, |
| 58 | |
| 59 | // Resolution |
| 60 | { |
| 61 | v: Resolution{0x01020304, 0x05060708, 0x09}, |
| 62 | data: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9}, |
| 63 | }, |
| 64 | { |
| 65 | v: Resolution{150, 300, UnitsDpi}, |
| 66 | data: []byte{ |
| 67 | 0x00, 0x00, 0x00, 0x96, // 150 |
| 68 | 0x00, 0x00, 0x01, 0x2c, // 300 |
| 69 | 0x03, |
| 70 | }, |
| 71 | }, |
| 72 | |
| 73 | // TextWithLang |
| 74 | { |
| 75 | v: TextWithLang{"en-US", "Hello!"}, |
| 76 | data: []byte{ |
| 77 | 0x00, 0x05, |
| 78 | 'e', 'n', '-', 'U', 'S', |