...
Source file
src/path/example_test.go
Documentation: path
1
2
3
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
17
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
38
39
40
41
42
43
44
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("/a/"))
51 fmt.Println(path.Dir("a/"))
52 fmt.Println(path.Dir("/"))
53 fmt.Println(path.Dir(""))
54
55
56
57
58
59
60
61 }
62
63 func ExampleExt() {
64 fmt.Println(path.Ext("/a/b/c/bar.css"))
65 fmt.Println(path.Ext("/"))
66 fmt.Println(path.Ext(""))
67
68
69
70
71 }
72
73 func ExampleIsAbs() {
74 fmt.Println(path.IsAbs("/dev/null"))
75
76 }
77
78 func ExampleJoin() {
79 fmt.Println(path.Join("a", "b", "c"))
80 fmt.Println(path.Join("a", "b/c"))
81 fmt.Println(path.Join("a/b", "c"))
82
83 fmt.Println(path.Join("a/b", "../../../xyz"))
84
85 fmt.Println(path.Join("", ""))
86 fmt.Println(path.Join("a", ""))
87 fmt.Println(path.Join("", "a"))
88
89
90
91
92
93
94
95
96
97 }
98
99 func ExampleMatch() {
100 fmt.Println(path.Match("abc", "abc"))
101 fmt.Println(path.Match("a*", "abc"))
102 fmt.Println(path.Match("a*/b", "a/c/b"))
103
104
105
106
107 }
108
109 func ExampleSplit() {
110 split := func(s string) {
111 dir, file := path.Split(s)
112 fmt.Printf("path.Split(%q) = dir: %q, file: %q\n", s, dir, file)
113 }
114 split("static/myfile.css")
115 split("myfile.css")
116 split("")
117
118
119
120
121 }
122
View as plain text