github.com/panjjo/go@v0.0.0-20161104043856-d62b31386338/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 // Output: b 15 } 16 17 func ExampleClean() { 18 paths := []string{ 19 "a/c", 20 "a//c", 21 "a/c/.", 22 "a/c/b/..", 23 "/../a/c", 24 "/../a/b/../././/c", 25 } 26 27 for _, p := range paths { 28 fmt.Printf("Clean(%q) = %q\n", p, path.Clean(p)) 29 } 30 31 // Output: 32 // Clean("a/c") = "a/c" 33 // Clean("a//c") = "a/c" 34 // Clean("a/c/.") = "a/c" 35 // Clean("a/c/b/..") = "a/c" 36 // Clean("/../a/c") = "/a/c" 37 // Clean("/../a/b/../././/c") = "/a/c" 38 } 39 40 func ExampleDir() { 41 fmt.Println(path.Dir("/a/b/c")) 42 // Output: /a/b 43 } 44 45 func ExampleExt() { 46 fmt.Println(path.Ext("/a/b/c/bar.css")) 47 // Output: .css 48 } 49 50 func ExampleIsAbs() { 51 fmt.Println(path.IsAbs("/dev/null")) 52 // Output: true 53 } 54 55 func ExampleJoin() { 56 fmt.Println(path.Join("a", "b", "c")) 57 fmt.Println(path.Join("a", "b/c")) 58 fmt.Println(path.Join("a/b", "c")) 59 fmt.Println(path.Join("a/b", "/c")) 60 // Output: 61 // a/b/c 62 // a/b/c 63 // a/b/c 64 // a/b/c 65 } 66 67 func ExampleSplit() { 68 fmt.Println(path.Split("static/myfile.css")) 69 // Output: static/ myfile.css 70 }