diff options
| author | Mark Harrison <marhar@google.com> | 2017-05-08 22:48:08 -0700 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@golang.org> | 2017-05-16 15:44:29 +0000 |
| commit | 84a51432a80686267e131f5d516559b3d82122b8 (patch) | |
| tree | f65e04d2dc3647c8888ee4441e15f57f8a7e6091 /src/path/example_test.go | |
| parent | 5548f7d5cfadf1319a99b2a17e72ff91fcdd09fc (diff) | |
| download | go-84a51432a80686267e131f5d516559b3d82122b8.tar.xz | |
path: add examples
This change adds several examples, with emphasis on special or edge
cases such as a directory parameter consisting of an empty string.
Change-Id: Ib4ac3d0f6d503493eeed0c4fda7c12acf782e9e2
Reviewed-on: https://go-review.googlesource.com/43010
Reviewed-by: Steve Francia <spf@golang.org>
Run-TryBot: Jaana Burcu Dogan <jbd@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/path/example_test.go')
| -rw-r--r-- | src/path/example_test.go | 40 |
1 files changed, 34 insertions, 6 deletions
diff --git a/src/path/example_test.go b/src/path/example_test.go index e8d684f771..07f9de3271 100644 --- a/src/path/example_test.go +++ b/src/path/example_test.go @@ -11,7 +11,12 @@ import ( func ExampleBase() { fmt.Println(path.Base("/a/b")) - // Output: b + fmt.Println(path.Base("/")) + fmt.Println(path.Base("")) + // Output: + // b + // / + // . } func ExampleClean() { @@ -22,6 +27,7 @@ func ExampleClean() { "a/c/b/..", "/../a/c", "/../a/b/../././/c", + "", } for _, p := range paths { @@ -35,16 +41,29 @@ func ExampleClean() { // Clean("a/c/b/..") = "a/c" // Clean("/../a/c") = "/a/c" // Clean("/../a/b/../././/c") = "/a/c" + // Clean("") = "." } func ExampleDir() { fmt.Println(path.Dir("/a/b/c")) - // Output: /a/b + fmt.Println(path.Dir("a/b/c")) + fmt.Println(path.Dir("/")) + fmt.Println(path.Dir("")) + // Output: + // /a/b + // a/b + // / + // . } func ExampleExt() { fmt.Println(path.Ext("/a/b/c/bar.css")) - // Output: .css + fmt.Println(path.Ext("/")) + fmt.Println(path.Ext("")) + // Output: + // .css + // + // } func ExampleIsAbs() { @@ -56,15 +75,24 @@ func ExampleJoin() { fmt.Println(path.Join("a", "b", "c")) fmt.Println(path.Join("a", "b/c")) fmt.Println(path.Join("a/b", "c")) - fmt.Println(path.Join("a/b", "/c")) + fmt.Println(path.Join("", "")) + fmt.Println(path.Join("a", "")) + fmt.Println(path.Join("", "a")) // Output: // a/b/c // a/b/c // a/b/c - // a/b/c + // + // a + // a } func ExampleSplit() { fmt.Println(path.Split("static/myfile.css")) - // Output: static/ myfile.css + fmt.Println(path.Split("myfile.css")) + fmt.Println(path.Split("")) + // Output: + // static/ myfile.css + // myfile.css + // } |
