aboutsummaryrefslogtreecommitdiff
path: root/ber/int_test.go
blob: ba1e5b02a0e116db73f79c77a9b55f35c2b6cb04 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package ber

import (
	"bytes"
	"testing"
)

type intTest struct {
	in  int
	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)
		}
	}
}