aboutsummaryrefslogtreecommitdiff
path: root/src/path
diff options
context:
space:
mode:
authorHasan Ozgan <hasan@ozgan.net>2019-02-08 00:50:51 +0000
committerRob Pike <r@golang.org>2019-03-25 02:57:06 +0000
commit56e1614c47cca7dc76b435f485fe86fe088d5127 (patch)
treee7f9c0db5e1687a28ab2bc6cda1ed9ff412dc181 /src/path
parent869620bbeaef7698ef6210c896f913257fe2e43b (diff)
downloadgo-56e1614c47cca7dc76b435f485fe86fe088d5127.tar.gz
go-56e1614c47cca7dc76b435f485fe86fe088d5127.zip
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: Rob Pike <r@golang.org>
Diffstat (limited to 'src/path')
-rw-r--r--src/path/filepath/example_unix_test.go71
1 files changed, 71 insertions, 0 deletions
diff --git a/src/path/filepath/example_unix_test.go b/src/path/filepath/example_unix_test.go
index 20ec8927b4..23f21380d0 100644
--- a/src/path/filepath/example_unix_test.go
+++ b/src/path/filepath/example_unix_test.go
@@ -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
+}