package ber import ( "bytes" "testing" ) type intTest struct { in int64 out []byte } var intTestData = []intTest{ {0, []byte{0x00}}, {127, []byte{0x7F}}, {128, []byte{0x00, 0x80}}, {256, []byte{0x01, 0x00}}, {-128, []byte{0x80}}, {-129, []byte{0xFF, 0x7F}}, {8388607, []byte{0x7f, 0xFF, 0xFF}}, {-136, []byte{0xFF, 0x78}}, {-8388607, []byte{0x80, 0x00, 0x01}}, } func TestInt(t *testing.T) { for _, test := range intTestData { a := marshalInt(test.in) if !bytes.Equal(a, test.out) { t.Error(test.in, "expected", test.out, "got", a) } n := unmarshalInt(test.out) if n != test.in { t.Error(test.out, "expected", test.in, "got", n) } } }