]> Cypherpunks repositories - gostls13.git/commitdiff
path, path/filepath: add Join example with joined rooted path
authorRuss Cox <rsc@golang.org>
Tue, 15 Mar 2016 00:23:22 +0000 (20:23 -0400)
committerRuss Cox <rsc@golang.org>
Sun, 3 Apr 2016 16:55:51 +0000 (16:55 +0000)
This makes clear that Go's path.Join and filepath.Join are different
from the Python os.path.join (and perhaps others).

Requested in private mail.

Change-Id: Ie5dfad8a57f9baa5cca31246af1fd4dd5b1a64ee
Reviewed-on: https://go-review.googlesource.com/20711
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/path/example_test.go
src/path/filepath/example_unix_test.go

index fa8c28d2e1718a706b93960b4ce867864423eb06..e8d684f7718338433f91b6aa6be6d216dfc9f300 100644 (file)
@@ -54,7 +54,14 @@ func ExampleIsAbs() {
 
 func ExampleJoin() {
        fmt.Println(path.Join("a", "b", "c"))
-       // Output: a/b/c
+       fmt.Println(path.Join("a", "b/c"))
+       fmt.Println(path.Join("a/b", "c"))
+       fmt.Println(path.Join("a/b", "/c"))
+       // Output:
+       // a/b/c
+       // a/b/c
+       // a/b/c
+       // a/b/c
 }
 
 func ExampleSplit() {
index 893be1b198817708b7b5bb884bcf5c671ac7a748..cd8233ceb6a60e2d3f0d55199d0dcb60d7912176 100644 (file)
@@ -65,3 +65,17 @@ func ExampleSplit() {
        //      dir: "/usr/local//"
        //      file: "go"
 }
+
+func ExampleJoin() {
+       fmt.Println("On Unix:")
+       fmt.Println(filepath.Join("a", "b", "c"))
+       fmt.Println(filepath.Join("a", "b/c"))
+       fmt.Println(filepath.Join("a/b", "c"))
+       fmt.Println(filepath.Join("a/b", "/c"))
+       // Output:
+       // On Unix:
+       // a/b/c
+       // a/b/c
+       // a/b/c
+       // a/b/c
+}