2016-02-03 23:55:33 -08:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
2016-03-28 22:16:52 -07:00
|
|
|
"github.com/stretchr/testify/assert"
|
2016-02-03 23:55:33 -08:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestIntegerBigEndian(t *testing.T) {
|
2016-03-28 22:16:52 -07:00
|
|
|
assert := assert.New(t)
|
|
|
|
|
2016-02-03 23:55:33 -08:00
|
|
|
bytes := []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}
|
2016-03-28 22:16:52 -07:00
|
|
|
integer := Integer(bytes)
|
|
|
|
|
|
|
|
assert.Equal(integer, 1, "Integer() did not parse bytes big endian")
|
2016-02-03 23:55:33 -08:00
|
|
|
}
|
|
|
|
|
2016-03-28 22:16:52 -07:00
|
|
|
func TestWorksWithOneByte(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
integer := Integer([]byte{0x01})
|
|
|
|
|
|
|
|
assert.Equal(integer, 1, "Integer() did not correctly parse single byte slice")
|
2016-02-03 23:55:33 -08:00
|
|
|
}
|
2016-02-14 22:40:29 -08:00
|
|
|
|
|
|
|
func TestIsZeroWithNoData(t *testing.T) {
|
2016-03-28 22:16:52 -07:00
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
integer := Integer([]byte{})
|
|
|
|
|
|
|
|
assert.Equal(integer, 0, "Integer() did not correctly parse zero length byte slice")
|
2016-02-14 22:40:29 -08:00
|
|
|
}
|