Commit 56e1614c authored by Hasan Ozgan's avatar Hasan Ozgan Committed by Rob Pike

path/filepath: add examples for Base, Dir and IsAbs

Change-Id: I7a438409748f0f9d6517a7ea1cdee6512ce3ca8a
Reviewed-on: https://go-review.googlesource.com/c/go/+/161678
Run-TryBot: Rob Pike <r@golang.org>
Reviewed-by: default avatarRob Pike <r@golang.org>
parent 869620bb
......@@ -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
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment