package ber import ( "bytes" "testing" ) func testInt(t *testing.T, i int64, b []byte) { a := marshalInt(i) if !bytes.Equal(a, b) { t.Error("BER", i, "expected", b, "got", a) } n := unmarshalInt(b) if n != i { t.Error("UnBER", b, "expected", i, "got", n) } } func TestInt(t *testing.T) { testInt(t, 0, []byte{0x00}) testInt(t, 127, []byte{0x7F}) testInt(t, 128, []byte{0x00, 0x80}) testInt(t, 256, []byte{0x01, 0x00}) testInt(t, -128, []byte{0x80}) testInt(t, -129, []byte{0xFF, 0x7F}) testInt(t, 8388607, []byte{0x7f, 0xFF, 0xFF}) testInt(t, -136, []byte{0xFF, 0x78}) testInt(t, -8388607, []byte{0x80, 0x00, 0x01}) }