(t *testing.T)
| 113 | } |
| 114 | |
| 115 | func TestEncodeInt32(t *testing.T) { |
| 116 | cases := []struct { |
| 117 | name string |
| 118 | fieldNum int |
| 119 | v int32 |
| 120 | expected []byte |
| 121 | }{ |
| 122 | { |
| 123 | name: "zero", |
| 124 | fieldNum: 1, |
| 125 | v: 0, |
| 126 | expected: []byte{0x8, 0x0}, |
| 127 | }, |
| 128 | { |
| 129 | name: "max int", |
| 130 | fieldNum: 2, |
| 131 | v: math.MaxInt32, |
| 132 | expected: []byte{0x10, 0xFF, 0xFF, 0xFF, 0xFF, 0x07}, |
| 133 | }, |
| 134 | { |
| 135 | name: "min int", |
| 136 | fieldNum: 2, |
| 137 | v: math.MinInt32, |
| 138 | expected: []byte{0x10, 0x80, 0x80, 0x80, 0x80, 0xf8, 0xff, 0xff, 0xff, 0xff, 0x1}, |
| 139 | }, |
| 140 | { |
| 141 | name: "regular value", |
| 142 | fieldNum: 3, |
| 143 | v: 42, |
| 144 | expected: []byte{0x18, 0x2A}, |
| 145 | }, |
| 146 | { |
| 147 | name: "negative value", |
| 148 | fieldNum: 4, |
| 149 | v: -42, |
| 150 | expected: []byte{0x20, 0xd6, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1}, |
| 151 | }, |
| 152 | } |
| 153 | for _, tc := range cases { |
| 154 | t.Run(tc.name, func(t *testing.T) { |
| 155 | dest := make([]byte, len(tc.expected)) |
| 156 | csproto.NewEncoder(dest).EncodeInt32(tc.fieldNum, tc.v) |
| 157 | assert.Equal(t, tc.expected, dest) |
| 158 | }) |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | func TestEncodePackedInt32(t *testing.T) { |
| 163 | dest := make([]byte, 9) |
nothing calls this directly
no test coverage detected