From 84a51432a80686267e131f5d516559b3d82122b8 Mon Sep 17 00:00:00 2001 From: Mark Harrison Date: Mon, 8 May 2017 22:48:08 -0700 Subject: [PATCH] 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 Run-TryBot: Jaana Burcu Dogan TryBot-Result: Gobot Gobot --- src/path/example_test.go | 40 ++++++++++++++++++++++++++++++++++------ 1 file 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 + // } -- 2.48.1