path: Dir

There was Base but not Dir, so fill in the gap.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5504076
diff --git a/src/pkg/path/path_test.go b/src/pkg/path/path_test.go
index 1fd57cc..77f0804 100644
--- a/src/pkg/path/path_test.go
+++ b/src/pkg/path/path_test.go
@@ -8,11 +8,11 @@
 	"testing"
 )
 
-type CleanTest struct {
-	path, clean string
+type PathTest struct {
+	path, result string
 }
 
-var cleantests = []CleanTest{
+var cleantests = []PathTest{
 	// Already clean
 	{"", "."},
 	{"abc", "abc"},
@@ -64,8 +64,8 @@
 
 func TestClean(t *testing.T) {
 	for _, test := range cleantests {
-		if s := Clean(test.path); s != test.clean {
-			t.Errorf("Clean(%q) = %q, want %q", test.path, s, test.clean)
+		if s := Clean(test.path); s != test.result {
+			t.Errorf("Clean(%q) = %q, want %q", test.path, s, test.result)
 		}
 	}
 }
@@ -148,7 +148,7 @@
 	}
 }
 
-var basetests = []CleanTest{
+var basetests = []PathTest{
 	// Already clean
 	{"", "."},
 	{".", "."},
@@ -165,8 +165,31 @@
 
 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)
+		if s := Base(test.path); s != test.result {
+			t.Errorf("Base(%q) = %q, want %q", test.path, s, test.result)
+		}
+	}
+}
+
+var dirtests = []PathTest{
+	{"", "."},
+	{".", "."},
+	{"/.", "/"},
+	{"/", "/"},
+	{"////", "/"},
+	{"/foo", "/"},
+	{"x/", "x"},
+	{"abc", "."},
+	{"abc/def", "abc"},
+	{"a/b/.x", "a/b"},
+	{"a/b/c.", "a/b"},
+	{"a/b/c.x", "a/b"},
+}
+
+func TestDir(t *testing.T) {
+	for _, test := range dirtests {
+		if s := Dir(test.path); s != test.result {
+			t.Errorf("Dir(%q) = %q, want %q", test.path, s, test.result)
 		}
 	}
 }