Commit 7cbec417 authored by Russ Cox's avatar Russ Cox

fumbly fingers + non-working ^C

submitted CL without applying edits.

make changes from CL 27142 review

R=r
DELTA=26  (17 added, 3 deleted, 6 changed)
OCL=27155
CL=27199
parent f13ce3ab
...@@ -12,9 +12,9 @@ import "io" ...@@ -12,9 +12,9 @@ import "io"
// by purely lexical processing. It applies the following rules // by purely lexical processing. It applies the following rules
// iteratively until no further processing can be done: // iteratively until no further processing can be done:
// //
// 1. Replace multiple slashes by a single slash. // 1. Replace multiple slashes with a single slash.
// 2. Eliminate each . path name element (the current directory). // 2. Eliminate each . path name element (the current directory).
// 3. Eliminate each .. path name element (the parent directory) // 3. Eliminate each inner .. path name element (the parent directory)
// along with the non-.. element that precedes it. // along with the non-.. element that precedes it.
// 4. Eliminate .. elements that begin a rooted path: // 4. Eliminate .. elements that begin a rooted path:
// that is, replace "/.." by "/" at the beginning of a path. // that is, replace "/.." by "/" at the beginning of a path.
...@@ -114,13 +114,10 @@ func Split(path string) (dir, file string) { ...@@ -114,13 +114,10 @@ func Split(path string) (dir, file string) {
// Join joins dir and file into a single path, adding a separating // Join joins dir and file into a single path, adding a separating
// slash if necessary. If dir is empty, it returns file. // slash if necessary. If dir is empty, it returns file.
func Join(dir, file string) string { func Join(dir, file string) string {
switch { if dir == "" {
case dir == "":
return file; return file;
case dir[len(dir)-1] == '/':
return dir + file;
} }
return dir + "/" + file; return Clean(dir + "/" + file);
} }
// Ext returns the file name extension used by path. // Ext returns the file name extension used by path.
......
...@@ -97,12 +97,20 @@ type JoinTest struct { ...@@ -97,12 +97,20 @@ type JoinTest struct {
var jointests = []JoinTest { var jointests = []JoinTest {
JoinTest{"a", "b", "a/b"}, JoinTest{"a", "b", "a/b"},
JoinTest{"a", "", "a/"}, JoinTest{"a", "", "a"},
JoinTest{"", "b", "b"}, JoinTest{"", "b", "b"},
JoinTest{"/", "a", "/a"}, JoinTest{"/", "a", "/a"},
JoinTest{"/", "", "/"}, JoinTest{"/", "", "/"},
JoinTest{"a/", "b", "a/b"}, JoinTest{"a/", "b", "a/b"},
JoinTest{"a/", "", "a/"}, JoinTest{"a/", "", "a"},
}
func TestJoin(t *testing.T) {
for i, test := range jointests {
if p := Join(test.dir, test.file); p != test.path {
t.Errorf("Join(%q, %q) = %q, want %q", test.dir, test.file, p, test.path);
}
}
} }
type ExtTest struct { type ExtTest struct {
...@@ -117,3 +125,12 @@ var exttests = []ExtTest { ...@@ -117,3 +125,12 @@ var exttests = []ExtTest {
ExtTest{"a.dir/b.go", ".go"}, ExtTest{"a.dir/b.go", ".go"},
ExtTest{"a.dir/", ""}, ExtTest{"a.dir/", ""},
} }
func TestExt(t *testing.T) {
for i, test := range exttests {
if x := Ext(test.path); x != test.ext {
t.Errorf("Ext(%q) = %q, want %q", test.path, x, test.ext);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment