aboutsummaryrefslogtreecommitdiff
path: root/src/path/filepath/path_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/path/filepath/path_test.go')
-rw-r--r--src/path/filepath/path_test.go54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/path/filepath/path_test.go b/src/path/filepath/path_test.go
index 382381eb4e..771416770e 100644
--- a/src/path/filepath/path_test.go
+++ b/src/path/filepath/path_test.go
@@ -143,6 +143,60 @@ func TestClean(t *testing.T) {
}
}
+type IsLocalTest struct {
+ path string
+ isLocal bool
+}
+
+var islocaltests = []IsLocalTest{
+ {"", false},
+ {".", true},
+ {"..", false},
+ {"../a", false},
+ {"/", false},
+ {"/a", false},
+ {"/a/../..", false},
+ {"a", true},
+ {"a/../a", true},
+ {"a/", true},
+ {"a/.", true},
+ {"a/./b/./c", true},
+}
+
+var winislocaltests = []IsLocalTest{
+ {"NUL", false},
+ {"nul", false},
+ {"nul.", false},
+ {"nul.txt", false},
+ {"com1", false},
+ {"./nul", false},
+ {"a/nul.txt/b", false},
+ {`\`, false},
+ {`\a`, false},
+ {`C:`, false},
+ {`C:\a`, false},
+ {`..\a`, false},
+}
+
+var plan9islocaltests = []IsLocalTest{
+ {"#a", false},
+}
+
+func TestIsLocal(t *testing.T) {
+ tests := islocaltests
+ if runtime.GOOS == "windows" {
+ tests = append(tests, winislocaltests...)
+ }
+ if runtime.GOOS == "plan9" {
+ tests = append(tests, plan9islocaltests...)
+ }
+ for _, test := range tests {
+ if got := filepath.IsLocal(test.path); got != test.isLocal {
+ t.Errorf("IsLocal(%q) = %v, want %v", test.path, got, test.isLocal)
+ }
+ }
+}
+
const sep = filepath.Separator
var slashtests = []PathTest{