]> Cypherpunks repositories - gostls13.git/commitdiff
path: add examples
authorMark Harrison <marhar@google.com>
Tue, 9 May 2017 05:48:08 +0000 (22:48 -0700)
committerBrad Fitzpatrick <bradfitz@golang.org>
Tue, 16 May 2017 15:44:29 +0000 (15:44 +0000)
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>

src/path/example_test.go

index e8d684f7718338433f91b6aa6be6d216dfc9f300..07f9de3271c3c9de23a753271e6fe6642ef52e3b 100644 (file)
@@ -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
+       //
 }