github.com/activestate/go@v0.0.0-20170614201249-0b81c023a722/src/path/example_test.go (about) 1 // Copyright 2012 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package path_test 6 7 import ( 8 "fmt" 9 "path" 10 ) 11 12 func ExampleBase() { 13 fmt.Println(path.Base("/a/b")) 14 fmt.Println(path.Base("/")) 15 fmt.Println(path.Base("")) 16 // Output: 17 // b 18 // / 19 // . 20 } 21 22 func ExampleClean() { 23 paths := []string{ 24 "a/c", 25 "a//c", 26 "a/c/.", 27 "a/c/b/..", 28 "/../a/c", 29 "/../a/b/../././/c", 30 "", 31 } 32 33 for _, p := range paths { 34 fmt.Printf("Clean(%q) = %q\n", p, path.Clean(p)) 35 } 36 37 // Output: 38 // Clean("a/c") = "a/c" 39 // Clean("a//c") = "a/c" 40 // Clean("a/c/.") = "a/c" 41 // Clean("a/c/b/..") = "a/c" 42 // Clean("/../a/c") = "/a/c" 43 // Clean("/../a/b/../././/c") = "/a/c" 44 // Clean("") = "." 45 } 46 47 func ExampleDir() { 48 fmt.Println(path.Dir("/a/b/c")) 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 // . 57 } 58 59 func ExampleExt() { 60 fmt.Println(path.Ext("/a/b/c/bar.css")) 61 fmt.Println(path.Ext("/")) 62 fmt.Println(path.Ext("")) 63 // Output: 64 // .css 65 // 66 // 67 } 68 69 func ExampleIsAbs() { 70 fmt.Println(path.IsAbs("/dev/null")) 71 // Output: true 72 } 73 74 func ExampleJoin() { 75 fmt.Println(path.Join("a", "b", "c")) 76 fmt.Println(path.Join("a", "b/c")) 77 fmt.Println(path.Join("a/b", "c")) 78 fmt.Println(path.Join("", "")) 79 fmt.Println(path.Join("a", "")) 80 fmt.Println(path.Join("", "a")) 81 // Output: 82 // a/b/c 83 // a/b/c 84 // a/b/c 85 // 86 // a 87 // a 88 } 89 90 func ExampleSplit() { 91 fmt.Println(path.Split("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 // 98 }