Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alist-org
GitHub Repository: alist-org/alist
Path: blob/main/pkg/gowebdav/utils_test.go
1560 views
1
package gowebdav
2
3
import (
4
"fmt"
5
"net/url"
6
"testing"
7
)
8
9
func TestJoin(t *testing.T) {
10
eq(t, "/", "", "")
11
eq(t, "/", "/", "/")
12
eq(t, "/foo", "", "/foo")
13
eq(t, "foo/foo", "foo/", "/foo")
14
eq(t, "foo/foo", "foo/", "foo")
15
}
16
17
func eq(t *testing.T, expected string, s0 string, s1 string) {
18
s := Join(s0, s1)
19
if s != expected {
20
t.Error("For", "'"+s0+"','"+s1+"'", "expected", "'"+expected+"'", "got", "'"+s+"'")
21
}
22
}
23
24
func ExamplePathEscape() {
25
fmt.Println(PathEscape(""))
26
fmt.Println(PathEscape("/"))
27
fmt.Println(PathEscape("/web"))
28
fmt.Println(PathEscape("/web/"))
29
fmt.Println(PathEscape("/w e b/d a v/s%u&c#k:s/"))
30
31
// Output:
32
//
33
// /
34
// /web
35
// /web/
36
// /w%20e%20b/d%20a%20v/s%25u&c%23k:s/
37
}
38
39
func TestEscapeURL(t *testing.T) {
40
ex := "https://foo.com/w%20e%20b/d%20a%20v/s%25u&c%23k:s/"
41
u, _ := url.Parse("https://foo.com" + PathEscape("/w e b/d a v/s%u&c#k:s/"))
42
if ex != u.String() {
43
t.Error("expected: " + ex + " got: " + u.String())
44
}
45
}
46
47
func TestFixSlashes(t *testing.T) {
48
expected := "/"
49
50
if got := FixSlashes(""); got != expected {
51
t.Errorf("expected: %q, got: %q", expected, got)
52
}
53
54
expected = "/path/"
55
56
if got := FixSlashes("path"); got != expected {
57
t.Errorf("expected: %q, got: %q", expected, got)
58
}
59
60
if got := FixSlashes("/path"); got != expected {
61
t.Errorf("expected: %q, got: %q", expected, got)
62
}
63
64
if got := FixSlashes("path/"); got != expected {
65
t.Errorf("expected: %q, got: %q", expected, got)
66
}
67
}
68
69