1 // Copyright 2009 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.
11 type PathTest struct {
15 var cleantests = []PathTest{
19 {"abc/def", "abc/def"},
24 {"../../abc", "../../abc"},
28 // Remove trailing slash
30 {"abc/def/", "abc/def"},
37 // Remove doubled slash
38 {"abc//def//ghi", "abc/def/ghi"},
45 {"abc/./def", "abc/def"},
46 {"/./abc/def", "/abc/def"},
50 {"abc/def/ghi/../jkl", "abc/def/jkl"},
51 {"abc/def/../ghi/../jkl", "abc/jkl"},
52 {"abc/def/..", "abc"},
53 {"abc/def/../..", "."},
54 {"/abc/def/../..", "/"},
55 {"abc/def/../../..", ".."},
56 {"/abc/def/../../..", "/"},
57 {"abc/def/../../../ghi/jkl/../../../mno", "../../mno"},
60 {"abc/./../def", "def"},
61 {"abc//./../def", "def"},
62 {"abc/../../././../def", "../../def"},
65 func TestClean(t *testing.T) {
66 for _, test := range cleantests {
67 if s := Clean(test.path); s != test.result {
68 t.Errorf("Clean(%q) = %q, want %q", test.path, s, test.result)
73 type SplitTest struct {
74 path, dir, file string
77 var splittests = []SplitTest{
85 func TestSplit(t *testing.T) {
86 for _, test := range splittests {
87 if d, f := Split(test.path); d != test.dir || f != test.file {
88 t.Errorf("Split(%q) = %q, %q, want %q, %q", test.path, d, f, test.dir, test.file)
93 type JoinTest struct {
98 var jointests = []JoinTest{
104 {[]string{"a"}, "a"},
107 {[]string{"a", "b"}, "a/b"},
108 {[]string{"a", ""}, "a"},
109 {[]string{"", "b"}, "b"},
110 {[]string{"/", "a"}, "/a"},
111 {[]string{"/", ""}, "/"},
112 {[]string{"a/", "b"}, "a/b"},
113 {[]string{"a/", ""}, "a"},
114 {[]string{"", ""}, ""},
117 // join takes a []string and passes it to Join.
118 func join(elem []string, args ...string) string {
123 func TestJoin(t *testing.T) {
124 for _, test := range jointests {
125 if p := join(test.elem); p != test.path {
126 t.Errorf("join(%q) = %q, want %q", test.elem, p, test.path)
131 type ExtTest struct {
135 var exttests = []ExtTest{
137 {"path.pb.go", ".go"},
139 {"a.dir/b.go", ".go"},
143 func TestExt(t *testing.T) {
144 for _, test := range exttests {
145 if x := Ext(test.path); x != test.ext {
146 t.Errorf("Ext(%q) = %q, want %q", test.path, x, test.ext)
151 var basetests = []PathTest{
166 func TestBase(t *testing.T) {
167 for _, test := range basetests {
168 if s := Base(test.path); s != test.result {
169 t.Errorf("Base(%q) = %q, want %q", test.path, s, test.result)
174 var dirtests = []PathTest{
184 {"abc////def", "abc"},
190 func TestDir(t *testing.T) {
191 for _, test := range dirtests {
192 if s := Dir(test.path); s != test.result {
193 t.Errorf("Dir(%q) = %q, want %q", test.path, s, test.result)
198 type IsAbsTest struct {
203 var isAbsTests = []IsAbsTest{
206 {"/usr/bin/gcc", true},
214 func TestIsAbs(t *testing.T) {
215 for _, test := range isAbsTests {
216 if r := IsAbs(test.path); r != test.isAbs {
217 t.Errorf("IsAbs(%q) = %v, want %v", test.path, r, test.isAbs)