Skip to content

Commit

Permalink
move stream objects and pools into internal package (in next PR will …
Browse files Browse the repository at this point in the history
…use it from roaring64 package)
  • Loading branch information
AskAlexSharov committed Nov 21, 2020
1 parent 3700649 commit 5033e34
Show file tree
Hide file tree
Showing 6 changed files with 241 additions and 221 deletions.
161 changes: 0 additions & 161 deletions byte_input.go

This file was deleted.

34 changes: 18 additions & 16 deletions byte_input_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,63 +2,65 @@ package roaring

import (
"bytes"
"github.com/stretchr/testify/assert"
"testing"

"github.com/RoaringBitmap/roaring/internal"
"github.com/stretchr/testify/assert"
)

func TestByteInputFlow(t *testing.T) {
t.Run("Test should be an error on empty data", func(t *testing.T) {
buf := bytes.NewBuffer([]byte{})

instances := []byteInput{
newByteInput(buf.Bytes()),
newByteInputFromReader(buf),
instances := []internal.ByteInput{
internal.NewByteInput(buf.Bytes()),
internal.NewByteInputFromReader(buf),
}

for _, input := range instances {
n, err := input.readUInt16()
n, err := input.ReadUInt16()

assert.EqualValues(t, 0, n)
assert.Error(t, err)

p, err := input.readUInt32()
p, err := input.ReadUInt32()
assert.EqualValues(t, 0, p)
assert.Error(t, err)

b, err := input.next(10)
b, err := input.Next(10)
assert.Nil(t, b)
assert.Error(t, err)

err = input.skipBytes(10)
err = input.SkipBytes(10)
assert.Error(t, err)
}
})

t.Run("Test on nonempty data", func(t *testing.T) {
buf := bytes.NewBuffer(uint16SliceAsByteSlice([]uint16{1, 10, 32, 66, 23}))

instances := []byteInput{
newByteInput(buf.Bytes()),
newByteInputFromReader(buf),
instances := []internal.ByteInput{
internal.NewByteInput(buf.Bytes()),
internal.NewByteInputFromReader(buf),
}

for _, input := range instances {
n, err := input.readUInt16()
n, err := input.ReadUInt16()
assert.EqualValues(t, 1, n)
assert.NoError(t, err)

p, err := input.readUInt32()
p, err := input.ReadUInt32()
assert.EqualValues(t, 2097162, p) // 32 << 16 | 10
assert.NoError(t, err)

b, err := input.next(2)
b, err := input.Next(2)
assert.EqualValues(t, []byte{66, 0}, b)
assert.NoError(t, err)

err = input.skipBytes(2)
err = input.SkipBytes(2)
assert.NoError(t, err)

b, err = input.next(1)
b, err = input.Next(1)
assert.Nil(t, b)
assert.Error(t, err)
}
Expand Down
Loading

0 comments on commit 5033e34

Please sign in to comment.