diff options
author | Ondřej Surý <ondrej@sury.org> | 2011-09-13 13:11:55 +0200 |
---|---|---|
committer | Ondřej Surý <ondrej@sury.org> | 2011-09-13 13:11:55 +0200 |
commit | 80f18fc933cf3f3e829c5455a1023d69f7b86e52 (patch) | |
tree | 4b825dc642cb6eb9a060e54bf8d69288fbee4904 /src/pkg/path/path_test.go | |
parent | 28592ee1ea1f5cdffcf85472f9de0285d928cf12 (diff) | |
download | golang-80f18fc933cf3f3e829c5455a1023d69f7b86e52.tar.gz |
Imported Upstream version 60
Diffstat (limited to 'src/pkg/path/path_test.go')
-rw-r--r-- | src/pkg/path/path_test.go | 196 |
1 files changed, 0 insertions, 196 deletions
diff --git a/src/pkg/path/path_test.go b/src/pkg/path/path_test.go deleted file mode 100644 index 1fd57cc80..000000000 --- a/src/pkg/path/path_test.go +++ /dev/null @@ -1,196 +0,0 @@ -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package path - -import ( - "testing" -) - -type CleanTest struct { - path, clean string -} - -var cleantests = []CleanTest{ - // Already clean - {"", "."}, - {"abc", "abc"}, - {"abc/def", "abc/def"}, - {"a/b/c", "a/b/c"}, - {".", "."}, - {"..", ".."}, - {"../..", "../.."}, - {"../../abc", "../../abc"}, - {"/abc", "/abc"}, - {"/", "/"}, - - // Remove trailing slash - {"abc/", "abc"}, - {"abc/def/", "abc/def"}, - {"a/b/c/", "a/b/c"}, - {"./", "."}, - {"../", ".."}, - {"../../", "../.."}, - {"/abc/", "/abc"}, - - // Remove doubled slash - {"abc//def//ghi", "abc/def/ghi"}, - {"//abc", "/abc"}, - {"///abc", "/abc"}, - {"//abc//", "/abc"}, - {"abc//", "abc"}, - - // Remove . elements - {"abc/./def", "abc/def"}, - {"/./abc/def", "/abc/def"}, - {"abc/.", "abc"}, - - // Remove .. elements - {"abc/def/ghi/../jkl", "abc/def/jkl"}, - {"abc/def/../ghi/../jkl", "abc/jkl"}, - {"abc/def/..", "abc"}, - {"abc/def/../..", "."}, - {"/abc/def/../..", "/"}, - {"abc/def/../../..", ".."}, - {"/abc/def/../../..", "/"}, - {"abc/def/../../../ghi/jkl/../../../mno", "../../mno"}, - - // Combinations - {"abc/./../def", "def"}, - {"abc//./../def", "def"}, - {"abc/../../././../def", "../../def"}, -} - -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) - } - } -} - -type SplitTest struct { - path, dir, file string -} - -var splittests = []SplitTest{ - {"a/b", "a/", "b"}, - {"a/b/", "a/b/", ""}, - {"a/", "a/", ""}, - {"a", "", "a"}, - {"/", "/", ""}, -} - -func TestSplit(t *testing.T) { - for _, test := range splittests { - if d, f := Split(test.path); d != test.dir || f != test.file { - t.Errorf("Split(%q) = %q, %q, want %q, %q", test.path, d, f, test.dir, test.file) - } - } -} - -type JoinTest struct { - elem []string - path string -} - -var jointests = []JoinTest{ - // zero parameters - {[]string{}, ""}, - - // one parameter - {[]string{""}, ""}, - {[]string{"a"}, "a"}, - - // two parameters - {[]string{"a", "b"}, "a/b"}, - {[]string{"a", ""}, "a"}, - {[]string{"", "b"}, "b"}, - {[]string{"/", "a"}, "/a"}, - {[]string{"/", ""}, "/"}, - {[]string{"a/", "b"}, "a/b"}, - {[]string{"a/", ""}, "a"}, - {[]string{"", ""}, ""}, -} - -// join takes a []string and passes it to Join. -func join(elem []string, args ...string) string { - args = elem - return Join(args...) -} - -func TestJoin(t *testing.T) { - for _, test := range jointests { - if p := join(test.elem); p != test.path { - t.Errorf("join(%q) = %q, want %q", test.elem, p, test.path) - } - } -} - -type ExtTest struct { - path, ext string -} - -var exttests = []ExtTest{ - {"path.go", ".go"}, - {"path.pb.go", ".go"}, - {"a.dir/b", ""}, - {"a.dir/b.go", ".go"}, - {"a.dir/", ""}, -} - -func TestExt(t *testing.T) { - for _, test := range exttests { - if x := Ext(test.path); x != test.ext { - t.Errorf("Ext(%q) = %q, want %q", test.path, x, test.ext) - } - } -} - -var basetests = []CleanTest{ - // Already clean - {"", "."}, - {".", "."}, - {"/.", "."}, - {"/", "/"}, - {"////", "/"}, - {"x/", "x"}, - {"abc", "abc"}, - {"abc/def", "def"}, - {"a/b/.x", ".x"}, - {"a/b/c.", "c."}, - {"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) - } - } -} - -type IsAbsTest struct { - path string - isAbs bool -} - -var isAbsTests = []IsAbsTest{ - {"", false}, - {"/", true}, - {"/usr/bin/gcc", true}, - {"..", false}, - {"/a/../bb", true}, - {".", false}, - {"./", false}, - {"lala", false}, -} - -func TestIsAbs(t *testing.T) { - for _, test := range isAbsTests { - if r := IsAbs(test.path); r != test.isAbs { - t.Errorf("IsAbs(%q) = %v, want %v", test.path, r, test.isAbs) - } - } -} |