Simplify unmarshalling.

This commit is contained in:
Henrik, Sölver
2021-06-09 19:51:48 +02:00
committed by Henrik Sölver
parent 61abe8dbd4
commit 71fcac40f0
17 changed files with 452 additions and 179 deletions

View File

@@ -3,24 +3,51 @@
package ipp
import (
"bufio"
"bytes"
"testing"
"github.com/stretchr/testify/assert"
)
func TestUnMarshalSingleRange(T *testing.T) {
func TestUnmarshalSingleRange(T *testing.T) {
testdata := []byte{
0x00, 0x04,
0x66, 0x6c, 0x6f, 0x70, //flop
0x00, 0x08,
0x00, 0x0, 0x0, 0x4, 0x00, 0x0, 0x0, 0x5,
}
b := bytes.NewBuffer(testdata)
buf := bufio.NewReader(b)
buf := bytes.NewBuffer(testdata)
var r RangeOfInteger
r.unmarshal(buf)
assert.Equal(T, "flop", r.name, "Should be equal")
assert.Equal(T, int32(4), r.values[0].lower, "Should be equal")
assert.Equal(T, int32(5), r.values[0].upper, "Should be equal")
}
func TestUnmarshalDualRanges(T *testing.T) {
testdata := []byte{
0x00, 0x04,
0x66, 0x6c, 0x6f, 0x70, //flop
0x00, 0x08,
0x00, 0x0, 0x0, 0x4, 0x00, 0x0, 0x0, 0x5,
0x33, 0x00, 0x00,
0x00, 0x08,
0x00, 0x0, 0x0, 0x6, 0x00, 0x0, 0x0, 0x9,
}
b := bytes.NewBuffer(testdata)
buf := bufio.NewReader(b)
var r RangeOfInteger
r.unmarshal(buf)
assert.Equal(T, "flop", r.name, "Should be equal")
assert.Equal(T, int32(4), r.values[0].lower, "Should be equal")
assert.Equal(T, int32(5), r.values[0].upper, "Should be equal")
assert.Equal(T, int32(6), r.values[1].lower, "Should be equal")
assert.Equal(T, int32(9), r.values[1].upper, "Should be equal")
n, v := unmarshalSingleRangeOfInteger(buf)
assert.Equal(T, "flop", n, "Should be equal")
assert.Equal(T, int32(4), v.lower, "Should be equal")
assert.Equal(T, int32(5), v.upper, "Should be equal")
}