-
Notifications
You must be signed in to change notification settings - Fork 31
/
string_test.go
74 lines (70 loc) · 2.1 KB
/
string_test.go
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package ber
import (
"testing"
)
func TestIA5String(t *testing.T) {
for _, test := range []struct {
value string
expectedErr string
}{
{"asdfgh", ""},
{"asdfgå", "invalid character for IA5String at pos 5: å"},
} {
pkt := NewString(ClassUniversal, TypePrimitive, TagIA5String, test.value, test.value)
dec, err := DecodePacketErr(pkt.Bytes())
if err == nil {
if test.expectedErr != "" {
t.Errorf("got unexpected error for `%s`: %s", test.value, err)
}
if dec.Value.(string) != test.value {
t.Errorf("did not get back original value: %s <=> %s", dec.Value.(string), test.value)
}
} else if err.Error() != test.expectedErr {
t.Errorf("got unexpected error for `%s`: %s", test.value, err)
}
}
}
func TestPrintableString(t *testing.T) {
for _, test := range []struct {
value string
expectedErr string
}{
{"asdfgh", ""},
{"asdfgå", "invalid character in position 5"},
} {
pkt := NewString(ClassUniversal, TypePrimitive, TagPrintableString, test.value, test.value)
dec, err := DecodePacketErr(pkt.Bytes())
if err == nil {
if test.expectedErr != "" {
t.Errorf("got unexpected error for `%s`: %s", test.value, err)
}
if dec.Value.(string) != test.value {
t.Errorf("did not get back original value: %s <=> %s", dec.Value.(string), test.value)
}
} else if err.Error() != test.expectedErr {
t.Errorf("got unexpected error for `%s`: %s", test.value, err)
}
}
}
func TestUTF8String(t *testing.T) {
for _, test := range []struct {
value string
expectedErr string
}{
{"åäöüß", ""},
{"asdfg\xFF", "invalid UTF-8 string"},
} {
pkt := NewString(ClassUniversal, TypePrimitive, TagUTF8String, test.value, test.value)
dec, err := DecodePacketErr(pkt.Bytes())
if err == nil {
if test.expectedErr != "" {
t.Errorf("got unexpected error for `%s`: %s", test.value, err)
}
if dec.Value.(string) != test.value {
t.Errorf("did not get back original value: %s <=> %s", dec.Value.(string), test.value)
}
} else if err.Error() != test.expectedErr {
t.Errorf("got unexpected error for `%s`: %s", test.value, err)
}
}
}