aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/path/filepath/path_test.go
diff options
context:
space:
mode:
authorAlex Brainman <alex.brainman@gmail.com>2011-07-18 17:08:12 +1000
committerAlex Brainman <alex.brainman@gmail.com>2011-07-18 17:08:12 +1000
commit3c4ca95da9faf2cfce93140ad88d7c65026c6ca3 (patch)
tree27f891dfa6bb6ef2de6f446e8a9fa2436d922cd6 /src/pkg/path/filepath/path_test.go
parent95323c59eaa6ffa8c76450c19a3831c88ecd19e3 (diff)
downloadgo-3c4ca95da9faf2cfce93140ad88d7c65026c6ca3.tar.xz
path/filepath: fixes for windows paths
- Clean and IsAbs to handle paths with drive letter properly. - Clean to replace / with \. R=golang-dev, adg CC=golang-dev, mattn.jp https://golang.org/cl/4758051
Diffstat (limited to 'src/pkg/path/filepath/path_test.go')
-rw-r--r--src/pkg/path/filepath/path_test.go46
1 files changed, 39 insertions, 7 deletions
diff --git a/src/pkg/path/filepath/path_test.go b/src/pkg/path/filepath/path_test.go
index 58c4c0301a..d2a10698e1 100644
--- a/src/pkg/path/filepath/path_test.go
+++ b/src/pkg/path/filepath/path_test.go
@@ -67,9 +67,27 @@ var cleantests = []PathTest{
{"abc/../../././../def", "../../def"},
}
+var wincleantests = []PathTest{
+ {`c:`, `c:.`},
+ {`c:\`, `c:\`},
+ {`c:\abc`, `c:\abc`},
+ {`c:abc\..\..\.\.\..\def`, `c:..\..\def`},
+ {`c:\abc\def\..\..`, `c:\`},
+ {`c:..\abc`, `c:..\abc`},
+ {`\`, `\`},
+ {`/`, `\`},
+}
+
func TestClean(t *testing.T) {
- for _, test := range cleantests {
- if s := filepath.ToSlash(filepath.Clean(test.path)); s != test.result {
+ tests := cleantests
+ if runtime.GOOS == "windows" {
+ for i, _ := range tests {
+ tests[i].result = filepath.FromSlash(tests[i].result)
+ }
+ tests = append(tests, wincleantests...)
+ }
+ for _, test := range tests {
+ if s := filepath.Clean(test.path); s != test.result {
t.Errorf("Clean(%q) = %q, want %q", test.path, s, test.result)
}
}
@@ -399,16 +417,30 @@ var winisabstests = []IsAbsTest{
{`C:\`, true},
{`c\`, false},
{`c::`, false},
- {`/`, true},
- {`\`, true},
- {`\Windows`, true},
+ {`c:`, false},
+ {`/`, false},
+ {`\`, false},
+ {`\Windows`, false},
+ {`c:a\b`, false},
}
func TestIsAbs(t *testing.T) {
+ var tests []IsAbsTest
if runtime.GOOS == "windows" {
- isabstests = append(isabstests, winisabstests...)
+ tests = append(tests, winisabstests...)
+ // All non-windows tests should fail, because they have no volume letter.
+ for _, test := range isabstests {
+ tests = append(tests, IsAbsTest{test.path, false})
+ }
+ // All non-windows test should work as intended if prefixed with volume letter.
+ for _, test := range isabstests {
+ tests = append(tests, IsAbsTest{"c:" + test.path, test.isAbs})
+ }
+ } else {
+ tests = isabstests
}
- for _, test := range isabstests {
+
+ for _, test := range tests {
if r := filepath.IsAbs(test.path); r != test.isAbs {
t.Errorf("IsAbs(%q) = %v, want %v", test.path, r, test.isAbs)
}