]> Cypherpunks.ru repositories - gostls13.git/commitdiff
path/filepath: add example for filepath.Split
authorAndrew Gerrand <adg@golang.org>
Fri, 20 Feb 2015 05:46:48 +0000 (16:46 +1100)
committerAndrew Gerrand <adg@golang.org>
Fri, 20 Feb 2015 07:35:57 +0000 (07:35 +0000)
Fixes #9928

Change-Id: Iab37051078755a132f211ad48e756422f7c55a39
Reviewed-on: https://go-review.googlesource.com/5416
Reviewed-by: Minux Ma <minux@golang.org>
src/path/filepath/example_unix_test.go

index f3fe076c3c73297b3e06fdf857be3739b39e191f..27d85d15c6c5b6e9a3f41dc7d022029dd618a727 100644 (file)
@@ -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"
+}