-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathfile_test.go
117 lines (107 loc) · 3.07 KB
/
file_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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// Copyright 2014 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package webdav
import (
"path/filepath"
"testing"
)
func TestDir(t *testing.T) {
testCases := []struct {
dir, name, want string
}{
{"/", "", "/"},
{"/", "/", "/"},
{"/", ".", "/"},
{"/", "./a", "/a"},
{"/", "..", "/"},
{"/", "..", "/"},
{"/", "../", "/"},
{"/", "../.", "/"},
{"/", "../a", "/a"},
{"/", "../..", "/"},
{"/", "../bar/a", "/bar/a"},
{"/", "../baz/a", "/baz/a"},
{"/", "...", "/..."},
{"/", ".../a", "/.../a"},
{"/", ".../..", "/"},
{"/", "a", "/a"},
{"/", "a/./b", "/a/b"},
{"/", "a/../../b", "/b"},
{"/", "a/../b", "/b"},
{"/", "a/b", "/a/b"},
{"/", "a/b/c/../../d", "/a/d"},
{"/", "a/b/c/../../../d", "/d"},
{"/", "a/b/c/../../../../d", "/d"},
{"/", "a/b/c/d", "/a/b/c/d"},
{"/foo/bar", "", "/foo/bar"},
{"/foo/bar", "/", "/foo/bar"},
{"/foo/bar", ".", "/foo/bar"},
{"/foo/bar", "./a", "/foo/bar/a"},
{"/foo/bar", "..", "/foo/bar"},
{"/foo/bar", "../", "/foo/bar"},
{"/foo/bar", "../.", "/foo/bar"},
{"/foo/bar", "../a", "/foo/bar/a"},
{"/foo/bar", "../..", "/foo/bar"},
{"/foo/bar", "../bar/a", "/foo/bar/bar/a"},
{"/foo/bar", "../baz/a", "/foo/bar/baz/a"},
{"/foo/bar", "...", "/foo/bar/..."},
{"/foo/bar", ".../a", "/foo/bar/.../a"},
{"/foo/bar", ".../..", "/foo/bar"},
{"/foo/bar", "a", "/foo/bar/a"},
{"/foo/bar", "a/./b", "/foo/bar/a/b"},
{"/foo/bar", "a/../../b", "/foo/bar/b"},
{"/foo/bar", "a/../b", "/foo/bar/b"},
{"/foo/bar", "a/b", "/foo/bar/a/b"},
{"/foo/bar", "a/b/c/../../d", "/foo/bar/a/d"},
{"/foo/bar", "a/b/c/../../../d", "/foo/bar/d"},
{"/foo/bar", "a/b/c/../../../../d", "/foo/bar/d"},
{"/foo/bar", "a/b/c/d", "/foo/bar/a/b/c/d"},
{"/foo/bar/", "", "/foo/bar"},
{"/foo/bar/", "/", "/foo/bar"},
{"/foo/bar/", ".", "/foo/bar"},
{"/foo/bar/", "./a", "/foo/bar/a"},
{"/foo/bar/", "..", "/foo/bar"},
{"/foo//bar///", "", "/foo/bar"},
{"/foo//bar///", "/", "/foo/bar"},
{"/foo//bar///", ".", "/foo/bar"},
{"/foo//bar///", "./a", "/foo/bar/a"},
{"/foo//bar///", "..", "/foo/bar"},
{"/x/y/z", "ab/c\x00d/ef", ""},
{".", "", "."},
{".", "/", "."},
{".", ".", "."},
{".", "./a", "a"},
{".", "..", "."},
{".", "..", "."},
{".", "../", "."},
{".", "../.", "."},
{".", "../a", "a"},
{".", "../..", "."},
{".", "../bar/a", "bar/a"},
{".", "../baz/a", "baz/a"},
{".", "...", "..."},
{".", ".../a", ".../a"},
{".", ".../..", "."},
{".", "a", "a"},
{".", "a/./b", "a/b"},
{".", "a/../../b", "b"},
{".", "a/../b", "b"},
{".", "a/b", "a/b"},
{".", "a/b/c/../../d", "a/d"},
{".", "a/b/c/../../../d", "d"},
{".", "a/b/c/../../../../d", "d"},
{".", "a/b/c/d", "a/b/c/d"},
{"", "", "."},
{"", "/", "."},
{"", ".", "."},
{"", "./a", "a"},
{"", "..", "."},
}
for _, tc := range testCases {
d := Dir(filepath.FromSlash(tc.dir))
if got := filepath.ToSlash(d.resolve(tc.name)); got != tc.want {
t.Errorf("dir=%q, name=%q: got %q, want %q", tc.dir, tc.name, got, tc.want)
}
}
}