1
0
mirror of https://github.com/golang/go synced 2024-11-23 20:20:01 -07:00

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>
This commit is contained in:
Mark Harrison 2017-05-08 22:48:08 -07:00 committed by Brad Fitzpatrick
parent 5548f7d5cf
commit 84a51432a8

View 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
//
}