-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcli_test.go
40 lines (36 loc) · 1.25 KB
/
cli_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
package main
import (
"regexp"
"testing"
)
func TestDefaultIgnore(t *testing.T) {
t.Parallel()
tests := []struct {
filename string
matchExpected bool
}{
{filename: "/etc/test", matchExpected: false},
{filename: "etc/test", matchExpected: false},
{filename: "test", matchExpected: false},
{filename: "test.txt", matchExpected: false},
{filename: "foo/test.txt", matchExpected: false},
{filename: "foo.bar/test.txt", matchExpected: false},
{filename: `foo\test.txt`, matchExpected: false},
{filename: `c:\\foo.bar\test.txt`, matchExpected: false},
{filename: "/var/lib/.teet", matchExpected: true},
{filename: "mla/.test", matchExpected: true},
{filename: ".test", matchExpected: true},
{filename: `c:\\bsa\.sath`, matchExpected: true},
{filename: `aoeu\.tsaoe`, matchExpected: true},
}
re := regexp.MustCompile(defaultIgnore)
for _, test := range tests {
t.Run("file "+test.filename, func(t *testing.T) {
if re.MatchString(test.filename) && !test.matchExpected {
t.Errorf("regexp `%s` match string '%s' but should not", defaultIgnore, test.filename)
} else if !re.MatchString(test.filename) && test.matchExpected {
t.Errorf("regexp `%s` did not match string '%s' but should", defaultIgnore, test.filename)
}
})
}
}