...
Source file
src/path/filepath/example_unix_test.go
1
2
3
4
5
6
7 package filepath_test
8
9 import (
10 "fmt"
11 "path/filepath"
12 )
13
14 func ExampleSplitList() {
15 fmt.Println("On Unix:", filepath.SplitList("/a/b/c:/usr/bin"))
16
17
18 }
19
20 func ExampleRel() {
21 paths := []string{
22 "/a/b/c",
23 "/b/c",
24 "./b/c",
25 }
26 base := "/a"
27
28 fmt.Println("On Unix:")
29 for _, p := range paths {
30 rel, err := filepath.Rel(base, p)
31 fmt.Printf("%q: %q %v\n", p, rel, err)
32 }
33
34
35
36
37
38
39 }
40
41 func ExampleSplit() {
42 paths := []string{
43 "/home/arnie/amelia.jpg",
44 "/mnt/photos/",
45 "rabbit.jpg",
46 "/usr/local//go",
47 }
48 fmt.Println("On Unix:")
49 for _, p := range paths {
50 dir, file := filepath.Split(p)
51 fmt.Printf("input: %q\n\tdir: %q\n\tfile: %q\n", p, dir, file)
52 }
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67 }
68
69 func ExampleJoin() {
70 fmt.Println("On Unix:")
71 fmt.Println(filepath.Join("a", "b", "c"))
72 fmt.Println(filepath.Join("a", "b/c"))
73 fmt.Println(filepath.Join("a/b", "c"))
74 fmt.Println(filepath.Join("a/b", "/c"))
75
76 fmt.Println(filepath.Join("a/b", "../../../xyz"))
77
78
79
80
81
82
83
84
85 }
86
87 func ExampleMatch() {
88 fmt.Println("On Unix:")
89 fmt.Println(filepath.Match("/home/catch/*", "/home/catch/foo"))
90 fmt.Println(filepath.Match("/home/catch/*", "/home/catch/foo/bar"))
91 fmt.Println(filepath.Match("/home/?opher", "/home/gopher"))
92 fmt.Println(filepath.Match("/home/\\*", "/home/*"))
93
94
95
96
97
98
99
100 }
101
102 func ExampleBase() {
103 fmt.Println("On Unix:")
104 fmt.Println(filepath.Base("/foo/bar/baz.js"))
105 fmt.Println(filepath.Base("/foo/bar/baz"))
106 fmt.Println(filepath.Base("/foo/bar/baz/"))
107 fmt.Println(filepath.Base("dev.txt"))
108 fmt.Println(filepath.Base("../todo.txt"))
109 fmt.Println(filepath.Base(".."))
110 fmt.Println(filepath.Base("."))
111 fmt.Println(filepath.Base("/"))
112 fmt.Println(filepath.Base(""))
113
114
115
116
117
118
119
120
121
122
123
124
125 }
126
127 func ExampleDir() {
128 fmt.Println("On Unix:")
129 fmt.Println(filepath.Dir("/foo/bar/baz.js"))
130 fmt.Println(filepath.Dir("/foo/bar/baz"))
131 fmt.Println(filepath.Dir("/foo/bar/baz/"))
132 fmt.Println(filepath.Dir("/dirty//path///"))
133 fmt.Println(filepath.Dir("dev.txt"))
134 fmt.Println(filepath.Dir("../todo.txt"))
135 fmt.Println(filepath.Dir(".."))
136 fmt.Println(filepath.Dir("."))
137 fmt.Println(filepath.Dir("/"))
138 fmt.Println(filepath.Dir(""))
139
140
141
142
143
144
145
146
147
148
149
150
151
152 }
153
154 func ExampleIsAbs() {
155 fmt.Println("On Unix:")
156 fmt.Println(filepath.IsAbs("/home/gopher"))
157 fmt.Println(filepath.IsAbs(".bashrc"))
158 fmt.Println(filepath.IsAbs(".."))
159 fmt.Println(filepath.IsAbs("."))
160 fmt.Println(filepath.IsAbs("/"))
161 fmt.Println(filepath.IsAbs(""))
162
163
164
165
166
167
168
169
170
171 }
172
View as plain text