forked from cortesi/devd
/
watch_test.go
59 lines (52 loc) · 1.24 KB
/
watch_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
package devd
import (
"reflect"
"testing"
"github.com/cortesi/devd/termlog"
)
var filterFilesTests = []struct {
pattern string
files []string
expected []string
}{
{
"*",
[]string{"main.cpp", "main.go", "main.h", "foo.go", "bar.py"},
[]string{},
},
{
"*.go",
[]string{"main.cpp", "main.go", "main.h", "foo.go", "bar.py"},
[]string{"main.cpp", "main.h", "bar.py"},
},
// Invalid patterns won't match anything. This would trigger a warning at
// runtime.
{
"[[",
[]string{"main.cpp", "main.go", "main.h", "foo.go", "bar.py"},
[]string{"main.cpp", "main.go", "main.h", "foo.go", "bar.py"},
},
}
func TestFilterFiles(t *testing.T) {
logger := termlog.NewLog()
logger.Quiet()
for i, tt := range filterFilesTests {
result := filterFiles("", tt.files, []string{tt.pattern}, logger)
if !reflect.DeepEqual(result, tt.expected) {
t.Errorf(
"Test %d (pattern %s), expected \"%v\" got \"%v\"",
i, tt.pattern, tt.expected, result,
)
}
}
}
func TestBatch(t *testing.T) {
input := make(chan string, 2)
input <- "nonexistent"
input <- "./testdata/index.html"
output := batch(0, input)
ret := <-output
if !reflect.DeepEqual(ret, []string{"./testdata/index.html"}) {
t.Error("Unexpected return from batch.")
}
}