Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(340)

Side by Side Diff: webdav/file_test.go

Issue 173100044: code review 173100044: x/net/webdav: add a Dir type, analogous to http.Dir. (Closed)
Patch Set: diff -r 8fd8d3a0313cb59e495106ac76df5da29381fa24 https://code.google.com/p/go.net Created 10 years, 4 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webdav/file.go ('k') | webdav/webdav.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package webdav
6
7 import (
8 "path/filepath"
9 "testing"
10 )
11
12 func TestDir(t *testing.T) {
13 testCases := []struct {
14 dir, name, want string
15 }{
16 {"/", "", "/"},
17 {"/", "/", "/"},
18 {"/", ".", "/"},
19 {"/", "./a", "/a"},
20 {"/", "..", "/"},
21 {"/", "..", "/"},
22 {"/", "../", "/"},
23 {"/", "../.", "/"},
24 {"/", "../a", "/a"},
25 {"/", "../..", "/"},
26 {"/", "../bar/a", "/bar/a"},
27 {"/", "../baz/a", "/baz/a"},
28 {"/", "...", "/..."},
29 {"/", ".../a", "/.../a"},
30 {"/", ".../..", "/"},
31 {"/", "a", "/a"},
32 {"/", "a/./b", "/a/b"},
33 {"/", "a/../../b", "/b"},
34 {"/", "a/../b", "/b"},
35 {"/", "a/b", "/a/b"},
36 {"/", "a/b/c/../../d", "/a/d"},
37 {"/", "a/b/c/../../../d", "/d"},
38 {"/", "a/b/c/../../../../d", "/d"},
39 {"/", "a/b/c/d", "/a/b/c/d"},
40
41 {"/foo/bar", "", "/foo/bar"},
42 {"/foo/bar", "/", "/foo/bar"},
43 {"/foo/bar", ".", "/foo/bar"},
44 {"/foo/bar", "./a", "/foo/bar/a"},
45 {"/foo/bar", "..", "/foo/bar"},
46 {"/foo/bar", "../", "/foo/bar"},
47 {"/foo/bar", "../.", "/foo/bar"},
48 {"/foo/bar", "../a", "/foo/bar/a"},
49 {"/foo/bar", "../..", "/foo/bar"},
50 {"/foo/bar", "../bar/a", "/foo/bar/bar/a"},
51 {"/foo/bar", "../baz/a", "/foo/bar/baz/a"},
52 {"/foo/bar", "...", "/foo/bar/..."},
53 {"/foo/bar", ".../a", "/foo/bar/.../a"},
54 {"/foo/bar", ".../..", "/foo/bar"},
55 {"/foo/bar", "a", "/foo/bar/a"},
56 {"/foo/bar", "a/./b", "/foo/bar/a/b"},
57 {"/foo/bar", "a/../../b", "/foo/bar/b"},
58 {"/foo/bar", "a/../b", "/foo/bar/b"},
59 {"/foo/bar", "a/b", "/foo/bar/a/b"},
60 {"/foo/bar", "a/b/c/../../d", "/foo/bar/a/d"},
61 {"/foo/bar", "a/b/c/../../../d", "/foo/bar/d"},
62 {"/foo/bar", "a/b/c/../../../../d", "/foo/bar/d"},
63 {"/foo/bar", "a/b/c/d", "/foo/bar/a/b/c/d"},
64
65 {"/foo/bar/", "", "/foo/bar"},
66 {"/foo/bar/", "/", "/foo/bar"},
67 {"/foo/bar/", ".", "/foo/bar"},
68 {"/foo/bar/", "./a", "/foo/bar/a"},
69 {"/foo/bar/", "..", "/foo/bar"},
70
71 {"/foo//bar///", "", "/foo/bar"},
72 {"/foo//bar///", "/", "/foo/bar"},
73 {"/foo//bar///", ".", "/foo/bar"},
74 {"/foo//bar///", "./a", "/foo/bar/a"},
75 {"/foo//bar///", "..", "/foo/bar"},
76
77 {"/x/y/z", "ab/c\x00d/ef", ""},
78
79 {".", "", "."},
80 {".", "/", "."},
81 {".", ".", "."},
82 {".", "./a", "a"},
83 {".", "..", "."},
84 {".", "..", "."},
85 {".", "../", "."},
86 {".", "../.", "."},
87 {".", "../a", "a"},
88 {".", "../..", "."},
89 {".", "../bar/a", "bar/a"},
90 {".", "../baz/a", "baz/a"},
91 {".", "...", "..."},
92 {".", ".../a", ".../a"},
93 {".", ".../..", "."},
94 {".", "a", "a"},
95 {".", "a/./b", "a/b"},
96 {".", "a/../../b", "b"},
97 {".", "a/../b", "b"},
98 {".", "a/b", "a/b"},
99 {".", "a/b/c/../../d", "a/d"},
100 {".", "a/b/c/../../../d", "d"},
101 {".", "a/b/c/../../../../d", "d"},
102 {".", "a/b/c/d", "a/b/c/d"},
103
104 {"", "", "."},
105 {"", "/", "."},
106 {"", ".", "."},
107 {"", "./a", "a"},
108 {"", "..", "."},
109 }
110
111 for _, tc := range testCases {
112 d := Dir(filepath.FromSlash(tc.dir))
113 if got := filepath.ToSlash(d.resolve(tc.name)); got != tc.want {
114 t.Errorf("dir=%q, name=%q: got %q, want %q", tc.dir, tc. name, got, tc.want)
115 }
116 }
117 }
OLDNEW
« no previous file with comments | « webdav/file.go ('k') | webdav/webdav.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b