Skip to content

Commit 84a5143

Browse files
Mark Harrisonbradfitz
Mark Harrison
authored andcommitted
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 <[email protected]> Run-TryBot: Jaana Burcu Dogan <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 5548f7d commit 84a5143

File tree

1 file changed

+34
-6
lines changed

1 file changed

+34
-6
lines changed

src/path/example_test.go

+34-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ import (
1111

1212
func ExampleBase() {
1313
fmt.Println(path.Base("/a/b"))
14-
// Output: b
14+
fmt.Println(path.Base("/"))
15+
fmt.Println(path.Base(""))
16+
// Output:
17+
// b
18+
// /
19+
// .
1520
}
1621

1722
func ExampleClean() {
@@ -22,6 +27,7 @@ func ExampleClean() {
2227
"a/c/b/..",
2328
"/../a/c",
2429
"/../a/b/../././/c",
30+
"",
2531
}
2632

2733
for _, p := range paths {
@@ -35,16 +41,29 @@ func ExampleClean() {
3541
// Clean("a/c/b/..") = "a/c"
3642
// Clean("/../a/c") = "/a/c"
3743
// Clean("/../a/b/../././/c") = "/a/c"
44+
// Clean("") = "."
3845
}
3946

4047
func ExampleDir() {
4148
fmt.Println(path.Dir("/a/b/c"))
42-
// Output: /a/b
49+
fmt.Println(path.Dir("a/b/c"))
50+
fmt.Println(path.Dir("/"))
51+
fmt.Println(path.Dir(""))
52+
// Output:
53+
// /a/b
54+
// a/b
55+
// /
56+
// .
4357
}
4458

4559
func ExampleExt() {
4660
fmt.Println(path.Ext("/a/b/c/bar.css"))
47-
// Output: .css
61+
fmt.Println(path.Ext("/"))
62+
fmt.Println(path.Ext(""))
63+
// Output:
64+
// .css
65+
//
66+
//
4867
}
4968

5069
func ExampleIsAbs() {
@@ -56,15 +75,24 @@ func ExampleJoin() {
5675
fmt.Println(path.Join("a", "b", "c"))
5776
fmt.Println(path.Join("a", "b/c"))
5877
fmt.Println(path.Join("a/b", "c"))
59-
fmt.Println(path.Join("a/b", "/c"))
78+
fmt.Println(path.Join("", ""))
79+
fmt.Println(path.Join("a", ""))
80+
fmt.Println(path.Join("", "a"))
6081
// Output:
6182
// a/b/c
6283
// a/b/c
6384
// a/b/c
64-
// a/b/c
85+
//
86+
// a
87+
// a
6588
}
6689

6790
func ExampleSplit() {
6891
fmt.Println(path.Split("static/myfile.css"))
69-
// Output: static/ myfile.css
92+
fmt.Println(path.Split("myfile.css"))
93+
fmt.Println(path.Split(""))
94+
// Output:
95+
// static/ myfile.css
96+
// myfile.css
97+
//
7098
}

0 commit comments

Comments
 (0)