Skip to content

Commit

Permalink
Remove unused/obsolete functions and tests for them: ReadStrEOS, Read…
Browse files Browse the repository at this point in the history
…StrByteLimit, ReadBitsArray
  • Loading branch information
GreyCat committed Mar 29, 2024
1 parent b7fec8e commit 5e3c2c2
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 100 deletions.
23 changes: 0 additions & 23 deletions kaitai/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,24 +305,6 @@ func (k *Stream) ReadBytesTerm(term byte, includeTerm, consumeTerm, eosError boo
return slice, nil
}

// ReadStrEOS reads the remaining bytes as a string.
func (k *Stream) ReadStrEOS(encoding string) (string, error) {
buf, err := ioutil.ReadAll(k)

// Go's string type can contain any bytes. The Go `range` operator
// assumes that the encoding is UTF-8 and some standard Go libraries
// also would like UTF-8. For now we'll leave any advanced
// conversions up to the user.
return string(buf), err
}

// ReadStrByteLimit reads limit number of bytes and returns those as a string.
func (k *Stream) ReadStrByteLimit(limit int, encoding string) (string, error) {
buf := make([]byte, limit)
n, err := k.Read(buf)
return string(buf[:n]), err
}

// AlignToByte discards the remaining bits and starts reading bits at the
// next byte.
func (k *Stream) AlignToByte() {
Expand Down Expand Up @@ -408,8 +390,3 @@ func (k *Stream) ReadBitsIntLe(n int) (res uint64, err error) {
res &= mask
return res, nil
}

// ReadBitsArray is not implemented yet.
func (k *Stream) ReadBitsArray(n uint) error {
return nil // TODO: implement
}
78 changes: 1 addition & 77 deletions kaitai/stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -650,61 +650,6 @@ func TestStream_ReadBytesTerm(t *testing.T) {
}
}

func TestStream_ReadStrEOS(t *testing.T) {
type args struct {
encoding string
}
tests := []struct {
name string
k *Stream
args args
want string
wantErr bool
}{
{"ReadStrEOS", NewStream(bytes.NewReader([]byte("fooo"))), args{""}, "fooo", false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := tt.k.ReadStrEOS(tt.args.encoding)
if (err != nil) != tt.wantErr {
t.Errorf("Stream.ReadStrEOS() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != tt.want {
t.Errorf("Stream.ReadStrEOS() = %v, want %v", got, tt.want)
}
})
}
}

func TestStream_ReadStrByteLimit(t *testing.T) {
type args struct {
limit int
encoding string
}
tests := []struct {
name string
k *Stream
args args
want string
wantErr bool
}{
{"ReadStrByteLimit", NewStream(bytes.NewReader([]byte("fooo"))), args{2, ""}, "fo", false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := tt.k.ReadStrByteLimit(tt.args.limit, tt.args.encoding)
if (err != nil) != tt.wantErr {
t.Errorf("Stream.ReadStrByteLimit() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != tt.want {
t.Errorf("Stream.ReadStrByteLimit() = %v, want %v", got, tt.want)
}
})
}
}

func TestStream_AlignToByte(t *testing.T) {
type bitInt struct {
bits int
Expand Down Expand Up @@ -757,7 +702,7 @@ func TestStream_AlignToByte(t *testing.T) {
}
}

func TestStream_ReadBitsIntBe(t *testing.T) {
func TestStream_ReadBitsInt(t *testing.T) {
type args struct {
totalBitsNeeded int
}
Expand Down Expand Up @@ -800,24 +745,3 @@ func TestStream_ReadBitsIntBe(t *testing.T) {
})
}
}

func TestStream_ReadBitsArray(t *testing.T) {
type args struct {
n uint
}
tests := []struct {
name string
k *Stream
args args
wantErr bool
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := tt.k.ReadBitsArray(tt.args.n); (err != nil) != tt.wantErr {
t.Errorf("Stream.ReadBitsArray() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}

0 comments on commit 5e3c2c2

Please sign in to comment.