aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/path/filepath/example_unix_test.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/path/filepath/example_unix_test.go b/src/path/filepath/example_unix_test.go
index f3fe076c3c..27d85d15c6 100644
--- a/src/path/filepath/example_unix_test.go
+++ b/src/path/filepath/example_unix_test.go
@@ -37,3 +37,31 @@ func ExampleRel() {
// "/b/c": "../b/c" <nil>
// "./b/c": "" Rel: can't make b/c relative to /a
}
+
+func ExampleSplit() {
+ paths := []string{
+ "/home/arnie/amelia.jpg",
+ "/mnt/photos/",
+ "rabbit.jpg",
+ "/usr/local//go",
+ }
+ fmt.Println("On Unix:")
+ for _, p := range paths {
+ dir, file := filepath.Split(p)
+ fmt.Printf("input: %q\n\tdir: %q\n\tfile: %q\n", p, dir, file)
+ }
+ // Output:
+ // On Unix:
+ // input: "/home/arnie/amelia.jpg"
+ // dir: "/home/arnie/"
+ // file: "amelia.jpg"
+ // input: "/mnt/photos/"
+ // dir: "/mnt/photos/"
+ // file: ""
+ // input: "rabbit.jpg"
+ // dir: ""
+ // file: "rabbit.jpg"
+ // input: "/usr/local//go"
+ // dir: "/usr/local//"
+ // file: "go"
+}