forked from bitfield/script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script_windows_test.go
93 lines (86 loc) · 1.94 KB
/
script_windows_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package script_test
import (
"testing"
"github.com/bitfield/script"
)
func TestDirnameReturnsExpectedResultsOnPlatformsWithBackslashPathSeparator(t *testing.T) {
t.Parallel()
testCases := []struct {
path string
want string
}{
{`C:\`, "C:\\\n"},
{`C:\a\b`, "C:\\a\n"},
{`C:a\b`, "C:a\n"},
{`\\host\share`, "\\\\host\\share\n"},
{`\\host\share\a\b`, "\\\\host\\share\\a\n"},
{`C:\Program Files\PHP\a`, "C:\\Program Files\\PHP\n"},
}
for _, tc := range testCases {
got, err := script.Echo(tc.path).Dirname().String()
if err != nil {
t.Error(err)
}
if tc.want != got {
t.Errorf("%q: want %q, got %q", tc.path, tc.want, got)
}
}
}
func ExampleFindFiles() {
script.FindFiles("testdata/multiple_files_with_subdirectory").Stdout()
// Output:
// testdata\multiple_files_with_subdirectory\1.txt
// testdata\multiple_files_with_subdirectory\2.txt
// testdata\multiple_files_with_subdirectory\3.tar.zip
// testdata\multiple_files_with_subdirectory\dir\.hidden
// testdata\multiple_files_with_subdirectory\dir\1.txt
// testdata\multiple_files_with_subdirectory\dir\2.txt
}
func ExampleListFiles() {
script.ListFiles("testdata/multiple_files_with_subdirectory").Stdout()
// Output:
// testdata\multiple_files_with_subdirectory\1.txt
// testdata\multiple_files_with_subdirectory\2.txt
// testdata\multiple_files_with_subdirectory\3.tar.zip
// testdata\multiple_files_with_subdirectory\dir
}
func ExamplePipe_Basename() {
input := []string{
"",
"/",
"/root",
"/tmp/example.php",
"/var/tmp/",
"./src/filters",
"C:\\Program Files",
}
script.Slice(input).Basename().Stdout()
// Output:
// .
// \
// root
// example.php
// tmp
// filters
// Program Files
}
func ExamplePipe_Dirname() {
input := []string{
"",
"/",
"/root",
"/tmp/example.php",
"/var/tmp/",
"./src/filters",
"C:/Program Files",
}
script.Slice(input).Dirname().Stdout()
// Output:
// .
// \
// \
// \tmp
// \var
// ./src
// C:\
}