forked from cortesi/devd
/
watch_test.go
56 lines (49 loc) · 1.09 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
package devd
import (
"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)
err := false
if len(result) != len(tt.expected) {
err = true
} else {
for j := range result {
if result[j] != tt.expected[j] {
err = true
break
}
}
}
if err {
t.Errorf("Test %d (pattern %s), expected \"%s\" got \"%s\"", i, tt.pattern, tt.expected, result)
}
}
}