diff options
| author | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2024-07-09 21:36:27 -0700 |
|---|---|---|
| committer | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2024-07-09 21:42:05 -0700 |
| commit | d9bc63a10d0978d9a5222cf7be74044e55f409b7 (patch) | |
| tree | 1797c9593c279bf1334ed8285de8054a92a28dcb /hotline/field_test.go | |
| parent | 8fa166777cbcd92e871e937d9557f0f1a732c04d (diff) | |
Extensive refactor and clean up
Diffstat (limited to 'hotline/field_test.go')
| -rw-r--r-- | hotline/field_test.go | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/hotline/field_test.go b/hotline/field_test.go index ecae9c7..abb4d44 100644 --- a/hotline/field_test.go +++ b/hotline/field_test.go @@ -172,7 +172,7 @@ func TestField_Read(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { f := &Field{ - ID: tt.fields.ID, + Type: tt.fields.ID, FieldSize: tt.fields.FieldSize, Data: tt.fields.Data, readOffset: tt.fields.readOffset, @@ -186,3 +186,46 @@ func TestField_Read(t *testing.T) { }) } } + +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()") + }) + } +} |