8 qt "github.com/frankban/quicktest"
11 func TestEscapePath(t *testing.T) {
14 parts []string, result string,
16 unescaper func(string) (string, error),
18 unescaped, err := unescaper(escaper(parts))
19 if !c.Check(err, qt.IsNil) {
22 c.Check(unescaped, qt.Equals, result)
25 // Test with nil escapers (always uses url.QueryEscape)
28 []string{"a_b-c", "d + e.f"},
34 []string{"a_1-b_c2", "d 3. (e, f).g"},
35 "a_1-b_c2/d 3. (e, f).g",
40 // Test with custom escapers
43 []string{"a_b-c", "d + e.f"},
45 func(s []string) string {
47 for _, comp := range s {
48 ret = append(ret, url.PathEscape(comp))
50 return path.Join(ret...)
55 []string{"a_1-b_c2", "d 3. (e, f).g"},
56 "a_1-b_c2/d 3. (e, f).g",
57 func(s []string) string {
59 for _, comp := range s {
60 ret = append(ret, url.PathEscape(comp))
62 return path.Join(ret...)
68 func TestEscapePathForEmptyInfoName(t *testing.T) {
69 qt.Check(t, defaultPathEscaper([]string{`ノ┬─┬ノ ︵ ( \o°o)\`}), qt.Equals, "%E3%83%8E%E2%94%AC%E2%94%80%E2%94%AC%E3%83%8E+%EF%B8%B5+%28+%5Co%C2%B0o%29%5C")
70 qt.Check(t, defaultPathEscaper([]string{"hello", "world"}), qt.Equals, "hello/world")
71 qt.Check(t, defaultPathEscaper([]string{"war", "and", "peace"}), qt.Equals, "war/and/peace")