-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils_test.go
48 lines (44 loc) · 963 Bytes
/
utils_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
package main
import (
"crypto"
"testing"
)
func Test_initHash(t *testing.T) {
hashes := []*Checksum{{hash: crypto.SHA256}, {hash: crypto.SHA512}}
for _, h := range hashes {
initHash(h)
if h == nil {
t.Errorf("initHash(%v) = nil", h)
}
}
}
func Test_escapeFilename(t *testing.T) {
xwant := map[string]string{
"abc": "abc",
"a\\c": "a\\\\c",
"a\nc": "a\\nc",
"a\\b\nc": "a\\\\b\\nc",
"a\nb\\c": "a\\nb\\\\c",
}
for str, want := range xwant {
got := escapeFilename(str)
if got != want {
t.Errorf("escapeFilename(%q) got %q; want %q", str, got, want)
}
}
}
func Test_unescapeFilename(t *testing.T) {
xwant := map[string]string{
"abc": "abc",
"a\\\\c": "a\\c",
"a\\nc": "a\nc",
"a\\\\b\\nc": "a\\b\nc",
"a\\nb\\\\c": "a\nb\\c",
}
for str, want := range xwant {
got := unescapeFilename(str)
if got != want {
t.Errorf("unescapeFilename(%q) got %q; want %q", str, got, want)
}
}
}