add path.Base, analogous to Unix basename
R=rsc
CC=golang-dev
https://golang.org/cl/1633042
diff --git a/src/pkg/path/path_test.go b/src/pkg/path/path_test.go
index e2458f20..6915b48 100644
--- a/src/pkg/path/path_test.go
+++ b/src/pkg/path/path_test.go
@@ -284,3 +284,26 @@
t.Errorf("removeTree: %v", err)
}
}
+
+var basetests = []CleanTest{
+ // Already clean
+ CleanTest{"", "."},
+ CleanTest{".", "."},
+ CleanTest{"/.", "."},
+ CleanTest{"/", "/"},
+ CleanTest{"////", "/"},
+ CleanTest{"x/", "x"},
+ CleanTest{"abc", "abc"},
+ CleanTest{"abc/def", "def"},
+ CleanTest{"a/b/.x", ".x"},
+ CleanTest{"a/b/c.", "c."},
+ CleanTest{"a/b/c.x", "c.x"},
+}
+
+func TestBase(t *testing.T) {
+ for _, test := range basetests {
+ if s := Base(test.path); s != test.clean {
+ t.Errorf("Base(%q) = %q, want %q", test.path, s, test.clean)
+ }
+ }
+}