(t *testing.T)
| 141 | } |
| 142 | |
| 143 | func TestRealFlexibleDecoderGetNullableInt32Array(t *testing.T) { |
| 144 | tests := []struct { |
| 145 | name string |
| 146 | input []byte |
| 147 | want []int32 |
| 148 | wantErr error |
| 149 | }{ |
| 150 | { |
| 151 | name: "null array", |
| 152 | input: []byte{0x00}, |
| 153 | }, |
| 154 | { |
| 155 | name: "empty array", |
| 156 | input: []byte{0x01}, |
| 157 | want: []int32{}, |
| 158 | }, |
| 159 | { |
| 160 | name: "valid array", |
| 161 | input: []byte{0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02}, |
| 162 | want: []int32{1, 2}, |
| 163 | }, |
| 164 | { |
| 165 | name: "insufficient data", |
| 166 | input: []byte{0x03}, |
| 167 | wantErr: ErrInsufficientData, |
| 168 | }, |
| 169 | } |
| 170 | |
| 171 | for _, tt := range tests { |
| 172 | t.Run(tt.name, func(t *testing.T) { |
| 173 | rd := &realFlexibleDecoder{&realDecoder{raw: tt.input}} |
| 174 | got, err := rd.getNullableInt32Array() |
| 175 | require.ErrorIs(t, err, tt.wantErr) |
| 176 | assert.Equal(t, tt.want, got) |
| 177 | }) |
| 178 | } |
| 179 | t.Run("returns insufficient data for compact length exceeding int64", func(t *testing.T) { |
| 180 | var input [binary.MaxVarintLen64]byte |
| 181 | n := binary.PutUvarint(input[:], 1<<63) |
| 182 | |
| 183 | rd := &realFlexibleDecoder{&realDecoder{raw: input[:n]}} |
| 184 | array, err := rd.getNullableInt32Array() |
| 185 | |
| 186 | require.ErrorIs(t, err, ErrInsufficientData) |
| 187 | assert.Nil(t, array) |
| 188 | }) |
| 189 | } |
| 190 | |
| 191 | // getInt32Array only diverges from getNullableInt32Array on null input |
| 192 | func TestRealFlexibleDecoderGetInt32Array(t *testing.T) { |
nothing calls this directly
no test coverage detected