MCPcopy
hub / github.com/RoaringBitmap/roaring / TestByteInputFlow

Function TestByteInputFlow

byte_input_test.go:12–69  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

10)
11
12func TestByteInputFlow(t *testing.T) {
13 t.Run("Test should be an error on empty data", func(t *testing.T) {
14 buf := bytes.NewBuffer([]byte{})
15
16 instances := []internal.ByteInput{
17 internal.NewByteInput(buf.Bytes()),
18 internal.NewByteInputFromReader(buf),
19 }
20
21 for _, input := range instances {
22 n, err := input.ReadUInt16()
23
24 assert.EqualValues(t, 0, n)
25 assert.Error(t, err)
26
27 p, err := input.ReadUInt32()
28 assert.EqualValues(t, 0, p)
29 assert.Error(t, err)
30
31 b, err := input.Next(10)
32 assert.Nil(t, b)
33 assert.Error(t, err)
34
35 err = input.SkipBytes(10)
36 assert.Error(t, err)
37 }
38 })
39
40 t.Run("Test on nonempty data", func(t *testing.T) {
41 buf := bytes.NewBuffer(uint16SliceAsByteSlice([]uint16{1, 10, 32, 66, 23}))
42
43 instances := []internal.ByteInput{
44 internal.NewByteInput(buf.Bytes()),
45 internal.NewByteInputFromReader(buf),
46 }
47
48 for _, input := range instances {
49 n, err := input.ReadUInt16()
50 assert.EqualValues(t, 1, n)
51 require.NoError(t, err)
52
53 p, err := input.ReadUInt32()
54 assert.EqualValues(t, 2097162, p) // 32 << 16 | 10
55 require.NoError(t, err)
56
57 b, err := input.Next(2)
58 assert.EqualValues(t, []byte{66, 0}, b)
59 require.NoError(t, err)
60
61 err = input.SkipBytes(2)
62 require.NoError(t, err)
63
64 b, err = input.Next(1)
65 assert.Nil(t, b)
66 assert.Error(t, err)
67 }
68 })
69}

Callers

nothing calls this directly

Calls 7

NewByteInputFunction · 0.92
NewByteInputFromReaderFunction · 0.92
uint16SliceAsByteSliceFunction · 0.70
ReadUInt16Method · 0.65
ReadUInt32Method · 0.65
NextMethod · 0.65
SkipBytesMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…