path, path/filepath: add Join example with joined rooted path

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>
This commit is contained in:
Russ Cox 2016-03-14 20:23:22 -04:00
Родитель 29a6149e67
Коммит 1f7e55e418
2 изменённых файлов: 22 добавлений и 1 удалений

Просмотреть файл

@ -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() {

Просмотреть файл

@ -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
}