forked from twpayne/go-pinentry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pinentry_test.go
76 lines (72 loc) · 1.29 KB
/
pinentry_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
75
76
package pinentry
import (
"strconv"
"testing"
"github.com/stretchr/testify/assert"
)
func TestEscapeUnescape(t *testing.T) {
for i, tc := range []struct {
unescaped string
escaped string
}{
{
unescaped: "",
escaped: "",
},
{
unescaped: "a",
escaped: "a",
},
{
unescaped: "\n",
escaped: "%0A",
},
{
unescaped: "\r",
escaped: "%0D",
},
{
unescaped: "%",
escaped: "%25",
},
{
unescaped: "a\r\n%b",
escaped: "a%0D%0A%25b",
},
} {
t.Run(strconv.Itoa(i), func(t *testing.T) {
actualEscaped := escape(tc.unescaped)
assert.Equal(t, tc.escaped, actualEscaped)
actualUnescaped := unescape([]byte(tc.escaped))
assert.Equal(t, tc.unescaped, string(actualUnescaped))
})
}
}
func TestUnescape(t *testing.T) {
for i, tc := range []struct {
s string
expectedUnescaped string
}{
{
s: "%",
expectedUnescaped: "%",
},
{
s: "%0",
expectedUnescaped: "%0",
},
{
s: "%0a",
expectedUnescaped: "%0a",
},
{
s: "%0A%",
expectedUnescaped: "\n%",
},
} {
t.Run(strconv.Itoa(i), func(t *testing.T) {
actualUnescaped := unescape([]byte(tc.s))
assert.Equal(t, tc.expectedUnescaped, string(actualUnescaped))
})
}
}