]> Cypherpunks repositories - gostls13.git/commitdiff
path/filepath: add examples for Base, Dir and IsAbs
authorHasan Ozgan <hasan@ozgan.net>
Fri, 8 Feb 2019 00:50:51 +0000 (00:50 +0000)
committerRob Pike <r@golang.org>
Mon, 25 Mar 2019 02:57:06 +0000 (02:57 +0000)
Change-Id: I7a438409748f0f9d6517a7ea1cdee6512ce3ca8a
Reviewed-on: https://go-review.googlesource.com/c/go/+/161678
Run-TryBot: Rob Pike <r@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
src/path/filepath/example_unix_test.go

index 20ec8927b4692b304672b19162ba85306b7ec21e..23f21380d01cb2fcf60e849f7fc425666541c87d 100644 (file)
@@ -94,3 +94,74 @@ func ExampleMatch() {
        // true <nil>
        // true <nil>
 }
+
+func ExampleBase() {
+       fmt.Println("On Unix:")
+       fmt.Println(filepath.Base("/foo/bar/baz.js"))
+       fmt.Println(filepath.Base("/foo/bar/baz"))
+       fmt.Println(filepath.Base("/foo/bar/baz/"))
+       fmt.Println(filepath.Base("dev.txt"))
+       fmt.Println(filepath.Base("../todo.txt"))
+       fmt.Println(filepath.Base(".."))
+       fmt.Println(filepath.Base("."))
+       fmt.Println(filepath.Base("/"))
+       fmt.Println(filepath.Base(""))
+
+       // Output:
+       // On Unix:
+       // baz.js
+       // baz
+       // baz
+       // dev.txt
+       // todo.txt
+       // ..
+       // .
+       // /
+       // .
+}
+
+func ExampleDir() {
+       fmt.Println("On Unix:")
+       fmt.Println(filepath.Dir("/foo/bar/baz.js"))
+       fmt.Println(filepath.Dir("/foo/bar/baz"))
+       fmt.Println(filepath.Dir("/foo/bar/baz/"))
+       fmt.Println(filepath.Dir("/dirty//path///"))
+       fmt.Println(filepath.Dir("dev.txt"))
+       fmt.Println(filepath.Dir("../todo.txt"))
+       fmt.Println(filepath.Dir(".."))
+       fmt.Println(filepath.Dir("."))
+       fmt.Println(filepath.Dir("/"))
+       fmt.Println(filepath.Dir(""))
+
+       // Output:
+       // On Unix:
+       // /foo/bar
+       // /foo/bar
+       // /foo/bar/baz
+       // /dirty/path
+       // .
+       // ..
+       // .
+       // .
+       // /
+       // .
+}
+
+func ExampleIsAbs() {
+       fmt.Println("On Unix:")
+       fmt.Println(filepath.IsAbs("/home/gopher"))
+       fmt.Println(filepath.IsAbs(".bashrc"))
+       fmt.Println(filepath.IsAbs(".."))
+       fmt.Println(filepath.IsAbs("."))
+       fmt.Println(filepath.IsAbs("/"))
+       fmt.Println(filepath.IsAbs(""))
+
+       // Output:
+       // On Unix:
+       // true
+       // false
+       // false
+       // false
+       // true
+       // false
+}