-
Notifications
You must be signed in to change notification settings - Fork 29
/
gow_test.go
161 lines (128 loc) · 4.21 KB
/
gow_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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package main
import (
"fmt"
"path/filepath"
"testing"
"github.com/mitranim/gg/gtest"
)
var testIgnoredPath = filepath.Join(cwd, `ignore3/file.ext3`)
var testIgnoredEvent = FsEvent(TestFsEvent(testIgnoredPath))
var testOpt = func() (tar Opt) {
tar.Init([]string{
`-e=ext1`,
`-e=ext2`,
`-e=ext3`,
`-i=./ignore1`,
`-i=ignore2`,
`-i=ignore3`,
`some_command`,
})
return
}()
var testMain = Main{Opt: testOpt}
type TestFsEvent string
func (self TestFsEvent) Path() string { return string(self) }
func TestFlagExtensions(t *testing.T) {
defer gtest.Catch(t)
opt := OptDefault()
gtest.Equal(opt.Extensions, FlagExtensions{`go`, `mod`})
{
var tar FlagExtensions
gtest.NoErr(tar.Parse(`one,two,three`))
gtest.Equal(tar, FlagExtensions{`one`, `two`, `three`})
}
{
var tar FlagExtensions
gtest.NoErr(tar.Parse(`one`))
gtest.NoErr(tar.Parse(`two`))
gtest.NoErr(tar.Parse(`three`))
gtest.Equal(tar, FlagExtensions{`one`, `two`, `three`})
}
}
func testIgnore[Ignore interface {
~[]string
Norm()
Ignore(string) bool
}](path string, ignore Ignore, exp bool) {
// Even though we invoke this on a value type, this works because the method
// mutates the underlying array, not the slice header itself.
ignore.Norm()
path = filepath.Join(cwd, path)
msg := fmt.Sprintf(`ignore: %q; path: %q`, ignore, path)
if exp {
gtest.True(ignore.Ignore(path), msg)
} else {
gtest.False(ignore.Ignore(path), msg)
}
}
func TestFlagIgnoreDirs_Ignore(t *testing.T) {
defer gtest.Catch(t)
type Ignore = FlagIgnoreDirs
{
testIgnore(`one.go`, Ignore{}, false)
testIgnore(`one.go`, Ignore{`.`}, true)
testIgnore(`one.go`, Ignore{`*`}, false)
testIgnore(`one.go`, Ignore{`.`, `two`}, true)
testIgnore(`one.go`, Ignore{`*`, `two`}, false)
testIgnore(`one.go`, Ignore{`./*`}, false)
testIgnore(`one.go`, Ignore{`two`}, false)
testIgnore(`one.go`, Ignore{`one.go`}, false)
}
{
testIgnore(`one/two.go`, Ignore{}, false)
testIgnore(`one/two.go`, Ignore{`one/two.go`}, false)
testIgnore(`one/two.go`, Ignore{`.`}, true)
testIgnore(`one/two.go`, Ignore{`./.`}, true)
testIgnore(`one/two.go`, Ignore{`././.`}, true)
testIgnore(`one/two.go`, Ignore{`*`}, false)
testIgnore(`one/two.go`, Ignore{`./*`}, false)
testIgnore(`one/two.go`, Ignore{`*/*`}, false)
testIgnore(`one/two.go`, Ignore{`./*/*`}, false)
testIgnore(`one/two.go`, Ignore{`one`}, true)
testIgnore(`one/two.go`, Ignore{`./one`}, true)
testIgnore(`one/two.go`, Ignore{`one/.`}, true)
testIgnore(`one/two.go`, Ignore{`./one/.`}, true)
testIgnore(`one/two.go`, Ignore{`one/*`}, false)
testIgnore(`one/two.go`, Ignore{`./one/*`}, false)
testIgnore(`one/two.go`, Ignore{`one/two`}, false)
testIgnore(`one/two.go`, Ignore{`./one/two`}, false)
testIgnore(`one/two.go`, Ignore{`one/two/.`}, false)
testIgnore(`one/two.go`, Ignore{`./one/two/.`}, false)
testIgnore(`one/two.go`, Ignore{`one/two/*`}, false)
testIgnore(`one/two.go`, Ignore{`./one/two/*`}, false)
testIgnore(`one/two.go`, Ignore{`two`}, false)
testIgnore(`one/two.go`, Ignore{`one`, `three`}, true)
testIgnore(`one/two.go`, Ignore{`three`, `one`}, true)
}
{
testIgnore(`.one/two.go`, Ignore{}, false)
testIgnore(`.one/two.go`, Ignore{`.one`}, true)
testIgnore(`.one/two.go`, Ignore{`./.one`}, true)
testIgnore(`.one/two.go`, Ignore{`.one/.`}, true)
testIgnore(`.one/two.go`, Ignore{`.one/*`}, false)
testIgnore(`.one/two.go`, Ignore{`three`}, false)
}
{
testIgnore(`.one/two/three.go`, Ignore{`.one`}, true)
testIgnore(`.one/two/three.go`, Ignore{`.one/.`}, true)
testIgnore(`.one/two/three.go`, Ignore{`.one/*`}, false)
testIgnore(`.one/two/three.go`, Ignore{`.one/two`}, true)
testIgnore(`.one/two/three.go`, Ignore{`.one/two/.`}, true)
testIgnore(`.one/two/three.go`, Ignore{`.one/two/*`}, false)
testIgnore(`.one/two/three.go`, Ignore{`.one/three`}, false)
}
}
func BenchmarkOpt_AllowPath(b *testing.B) {
gtest.False(testOpt.AllowPath(testIgnoredPath))
b.ResetTimer()
for ind := 0; ind < b.N; ind++ {
testOpt.AllowPath(testIgnoredPath)
}
}
func BenchmarkMain_ShouldRestart(b *testing.B) {
gtest.False(testMain.ShouldRestart(testIgnoredEvent))
b.ResetTimer()
for ind := 0; ind < b.N; ind++ {
testMain.ShouldRestart(testIgnoredEvent)
}
}