Skip to content

Commit

Permalink
fix fixed length check for ebcdic and bcd
Browse files Browse the repository at this point in the history
  • Loading branch information
alovak committed Sep 9, 2024
1 parent 159e294 commit 58dc624
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion prefix/bcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ type bcdFixedPrefixer struct {
}

func (p *bcdFixedPrefixer) EncodeLength(fixLen, dataLen int) ([]byte, error) {
if dataLen > fixLen {
if dataLen != fixLen {
return nil, fmt.Errorf("field length: %d should be fixed: %d", dataLen, fixLen)
}

Expand Down
6 changes: 6 additions & 0 deletions prefix/bcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,11 @@ func TestBCDFixedPrefixer_EncodeLengthValidation(t *testing.T) {

_, err := pref.EncodeLength(8, 12)

require.Error(t, err)
require.Contains(t, err.Error(), "field length: 12 should be fixed: 8")

_, err = pref.EncodeLength(8, 6)

require.Error(t, err)
require.Contains(t, err.Error(), "field length: 6 should be fixed: 8")
}
2 changes: 1 addition & 1 deletion prefix/ebcdic.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ type ebcdicFixedPrefixer struct {
}

func (p *ebcdicFixedPrefixer) EncodeLength(fixLen, dataLen int) ([]byte, error) {
if dataLen > fixLen {
if dataLen != fixLen {
return nil, fmt.Errorf("field length: %d should be fixed: %d", dataLen, fixLen)
}

Expand Down
6 changes: 6 additions & 0 deletions prefix/ebcdic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,11 @@ func TestEBCDICFixedPrefixer_EncodeLengthValidation(t *testing.T) {

_, err := pref.EncodeLength(8, 12)

require.Error(t, err)
require.Contains(t, err.Error(), "field length: 12 should be fixed: 8")

_, err = pref.EncodeLength(8, 6)

require.Error(t, err)
require.Contains(t, err.Error(), "field length: 6 should be fixed: 8")
}

0 comments on commit 58dc624

Please sign in to comment.