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