aboutsummaryrefslogtreecommitdiff
path: root/ber
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-06-29 17:33:16 +0200
committerDimitri Sokolyuk <demon@dim13.org>2015-06-29 17:33:16 +0200
commitc067dca4a86c638add29d0ca920b6697d593c814 (patch)
tree33f8c56c5af94d02760980c14d0c1b5011b1d8bc /ber
parent858afe322b6b24871630d04deeabe74b4d7802f2 (diff)
Adjust int test
Diffstat (limited to 'ber')
-rw-r--r--ber/int_test.go44
1 files changed, 24 insertions, 20 deletions
diff --git a/ber/int_test.go b/ber/int_test.go
index 9a015c5..c7f4ee2 100644
--- a/ber/int_test.go
+++ b/ber/int_test.go
@@ -5,28 +5,32 @@ import (
"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)
- }
+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) {
- 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})
+ 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)
+ }
+ }
}