-
Notifications
You must be signed in to change notification settings - Fork 29
/
gow_test.go
85 lines (69 loc) · 1.78 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
package main
import (
"fmt"
"path/filepath"
"testing"
"github.com/mitranim/gg/gtest"
)
func TestFlagExtensions(t *testing.T) {
defer gtest.Catch(t)
opt := OptDefault()
gtest.Equal(opt.Extensions, FlagExtensions{`go`, `mod`})
{
var tar FlagExtensions
gtest.NoError(tar.Parse(`one,two,three`))
gtest.Equal(tar, FlagExtensions{`one`, `two`, `three`})
}
{
var tar FlagExtensions
gtest.NoError(tar.Parse(`one`))
gtest.NoError(tar.Parse(`two`))
gtest.NoError(tar.Parse(`three`))
gtest.Equal(tar, FlagExtensions{`one`, `two`, `three`})
}
}
type TestFsEvent string
func (self TestFsEvent) Path() string { return string(self) }
func TestOpt_ShouldRestart(t *testing.T) {
defer gtest.Catch(t)
test := func(path, ignore string, exp bool) {
var opt Opt
opt.Init([]string{`-i`, ignore, `cmd`})
gtest.Eq(
opt.ShouldRestart(TestFsEvent(filepath.Join(cwd, path))),
exp,
fmt.Sprintf(`path: %q; ignore: %q`, path, ignore),
)
}
test(`file.go`, ``, true)
test(`to/file.go`, ``, true)
test(`to/file`, ``, false)
test(`to/file.txt`, ``, false)
test(`to/file.go.txt`, ``, false)
test(`to/file.go`, `to`, false)
test(`to/file.go`, `yo,to`, false)
test(`to/file.go`, `yo,./to/`, false)
test(`to/file.go`, `file`, true)
test(`to/file.go`, ``, true)
test(`.hidden/file.go`, ``, true)
test(`.hidden/ignore/file.go`, `.hidden/ignore`, false)
test(`.hidden/no/file.go`, `.hidden/ignore`, true)
}
func BenchmarkOpt_ShouldRestart(b *testing.B) {
event := FsEvent(TestFsEvent(filepath.Join(cwd, `ignore3/file.ext3`)))
var opt Opt
opt.Init([]string{
`-e=ext1`,
`-e=ext2`,
`-e=ext3`,
`-i=./ignore1`,
`-i=ignore2`,
`-i=ignore3`,
`cmd`,
})
gtest.False(opt.ShouldRestart(event))
b.ResetTimer()
for ind := 0; ind < b.N; ind++ {
opt.ShouldRestart(event)
}
}