aboutsummaryrefslogtreecommitdiff
path: root/ber
diff options
context:
space:
mode:
Diffstat (limited to 'ber')
-rw-r--r--ber/string.go4
-rw-r--r--ber/string_test.go29
2 files changed, 20 insertions, 13 deletions
diff --git a/ber/string.go b/ber/string.go
index 77d0ea4..98eb617 100644
--- a/ber/string.go
+++ b/ber/string.go
@@ -1,9 +1,9 @@
package ber
-func marshalString(s string) []byte {
+func MarshalString(s string) []byte {
return []byte(s)
}
-func unmarshalString(b []byte) string {
+func UnmarshalString(b []byte) string {
return string(b)
}
diff --git a/ber/string_test.go b/ber/string_test.go
index c783918..04d1fa1 100644
--- a/ber/string_test.go
+++ b/ber/string_test.go
@@ -5,19 +5,26 @@ import (
"testing"
)
-func testString(t *testing.T, s string, e []byte) {
- a := marshalString(s)
- if !bytes.Equal(a, e) {
- t.Error("String", s, "expexted", e, "got", a)
- }
+type stringTest struct {
+ in string
+ out []byte
+}
- b := unmarshalString(e)
- if b != s {
- t.Error("DeString", e, "expexted", s, "got", b)
- }
+var stringTestData = []stringTest{
+ {"111", []byte{0x31, 0x31, 0x31}},
+ {"0A16", []byte{0x30, 0x41, 0x31, 0x36}},
}
func TestString(t *testing.T) {
- testString(t, "111", []byte{0x31, 0x31, 0x31})
- testString(t, "0A16", []byte{0x30, 0x41, 0x31, 0x36})
+ for _, test := range stringTestData {
+ a := MarshalString(test.in)
+ if !bytes.Equal(a, test.out) {
+ t.Error(test.in, "expexted", test.out, "got", a)
+ }
+
+ b := UnmarshalString(test.out)
+ if b != test.in {
+ t.Error(test.out, "expexted", test.in, "got", b)
+ }
+ }
}