Commit 84a51432 authored by Mark Harrison's avatar Mark Harrison Committed by Brad Fitzpatrick

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/43010Reviewed-by: default avatarSteve Francia <spf@golang.org>
Run-TryBot: Jaana Burcu Dogan <jbd@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 5548f7d5
...@@ -11,7 +11,12 @@ import ( ...@@ -11,7 +11,12 @@ import (
func ExampleBase() { func ExampleBase() {
fmt.Println(path.Base("/a/b")) fmt.Println(path.Base("/a/b"))
// Output: b fmt.Println(path.Base("/"))
fmt.Println(path.Base(""))
// Output:
// b
// /
// .
} }
func ExampleClean() { func ExampleClean() {
...@@ -22,6 +27,7 @@ func ExampleClean() { ...@@ -22,6 +27,7 @@ func ExampleClean() {
"a/c/b/..", "a/c/b/..",
"/../a/c", "/../a/c",
"/../a/b/../././/c", "/../a/b/../././/c",
"",
} }
for _, p := range paths { for _, p := range paths {
...@@ -35,16 +41,29 @@ func ExampleClean() { ...@@ -35,16 +41,29 @@ func ExampleClean() {
// Clean("a/c/b/..") = "a/c" // Clean("a/c/b/..") = "a/c"
// Clean("/../a/c") = "/a/c" // Clean("/../a/c") = "/a/c"
// Clean("/../a/b/../././/c") = "/a/c" // Clean("/../a/b/../././/c") = "/a/c"
// Clean("") = "."
} }
func ExampleDir() { func ExampleDir() {
fmt.Println(path.Dir("/a/b/c")) 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() { func ExampleExt() {
fmt.Println(path.Ext("/a/b/c/bar.css")) fmt.Println(path.Ext("/a/b/c/bar.css"))
// Output: .css fmt.Println(path.Ext("/"))
fmt.Println(path.Ext(""))
// Output:
// .css
//
//
} }
func ExampleIsAbs() { func ExampleIsAbs() {
...@@ -56,15 +75,24 @@ func ExampleJoin() { ...@@ -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("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: // Output:
// a/b/c // a/b/c
// a/b/c // a/b/c
// a/b/c // a/b/c
// a/b/c //
// a
// a
} }
func ExampleSplit() { func ExampleSplit() {
fmt.Println(path.Split("static/myfile.css")) 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
//
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment