+
+func TestField_DecodeInt(t *testing.T) {
+ type fields struct {
+ Data []byte
+ }
+ tests := []struct {
+ name string
+ fields fields
+ want int
+ wantErr assert.ErrorAssertionFunc
+ }{
+ {
+ name: "with 2 bytes of input",
+ fields: fields{Data: []byte{0, 1}},
+ want: 1,
+ wantErr: assert.NoError,
+ },
+ {
+ name: "with 4 bytes of input",
+ fields: fields{Data: []byte{0, 1, 0, 0}},
+ want: 65536,
+ wantErr: assert.NoError,
+ },
+ {
+ name: "with invalid number of bytes of input",
+ fields: fields{Data: []byte{1, 0, 0, 0, 0, 0, 0, 0}},
+ want: 0,
+ wantErr: assert.Error,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ f := &Field{
+ Data: tt.fields.Data,
+ }
+ got, err := f.DecodeInt()
+ if !tt.wantErr(t, err, fmt.Sprintf("DecodeInt()")) {
+ return
+ }
+ assert.Equalf(t, tt.want, got, "DecodeInt()")
+ })
+ }
+}