@@ -17,6 +17,7 @@ limitations under the License.
1717package types
1818
1919import (
20+ "bytes"
2021 "testing"
2122)
2223
@@ -52,9 +53,56 @@ func TestByteForOctalString(t *testing.T) {
5253 }
5354 for _ , test := range tests {
5455 t .Run (test .input , func (t * testing.T ) {
55- actual := ByteForOctalString (test .input )
56- if actual != test .expected {
57- t .Errorf ("got %x; want %x" , test .expected , actual )
56+ got := ByteForOctalString (test .input )
57+ if got != test .expected {
58+ t .Errorf ("got %x; want %x" , got , test .expected )
59+ }
60+ })
61+ }
62+ }
63+
64+ func TestUnescapeStringWithOctal (t * testing.T ) {
65+ tests := []struct {
66+ input string
67+ expected []byte
68+ }{
69+ {
70+ "\\ 5" ,
71+ []byte {0x05 },
72+ },
73+ {
74+ "\\ 5a" ,
75+ []byte {0x05 , 'a' },
76+ },
77+ {
78+ "\\ 5\\ 5" ,
79+ []byte {0x05 , 0x05 },
80+ },
81+ {
82+ "\\ 53" ,
83+ []byte {'+' },
84+ },
85+ {
86+ "\\ 53a" ,
87+ []byte {'+' , 'a' },
88+ },
89+ {
90+ "\\ 053" ,
91+ []byte {'+' },
92+ },
93+ {
94+ "\\ 0053" ,
95+ []byte {0x05 , '3' },
96+ },
97+ }
98+ for _ , test := range tests {
99+ t .Run (test .input , func (t * testing.T ) {
100+ got , err := Unescape (test .input )
101+ if err != nil {
102+ t .Fail ()
103+ }
104+ if ! bytes .Equal (got , test .expected ) {
105+ t .Errorf ("got %x; want %x" , got , test .expected )
58106 }
59107 })
60108 }
@@ -116,12 +164,12 @@ func TestDecodeName(t *testing.T) {
116164 }
117165 for _ , test := range tests {
118166 t .Run (test .input , func (t * testing.T ) {
119- actual , err := DecodeName (test .input )
167+ got , err := DecodeName (test .input )
120168 if err != nil {
121169 t .Fail ()
122170 }
123- if actual != test .expected {
124- t .Errorf ("got %x; want %x" , test .expected , actual )
171+ if got != test .expected {
172+ t .Errorf ("got %x; want %x" , got , test .expected )
125173 }
126174 })
127175 }
0 commit comments