fork of https://github.com/sourcegraph/zoekt
0

Configure Feed

Select the types of activity you want to include in your feed.

1package ignore 2 3import ( 4 "bytes" 5 "reflect" 6 "strings" 7 "testing" 8 9 "github.com/gobwas/glob" 10) 11 12func TestParseIgnoreFile(t *testing.T) { 13 tests := []struct { 14 ignoreFile []byte 15 wantIgnoreList []glob.Glob 16 }{ 17 { 18 ignoreFile: []byte("# ignore this \n \n foo\n bar/"), 19 wantIgnoreList: []glob.Glob{ 20 glob.MustCompile("foo**", '/'), 21 glob.MustCompile("bar/**", '/')}, 22 }, 23 { 24 ignoreFile: []byte("/foo/bar \n /qux \n *.go\nfoo.go"), 25 wantIgnoreList: []glob.Glob{ 26 glob.MustCompile("foo/bar**", '/'), 27 glob.MustCompile("qux**", '/'), 28 glob.MustCompile("*.go", '/'), 29 glob.MustCompile("foo.go", '/')}, 30 }, 31 } 32 33 for _, tt := range tests { 34 m, err := ParseIgnoreFile(bytes.NewReader(tt.ignoreFile)) 35 if err != nil { 36 t.Error(err) 37 } 38 if !reflect.DeepEqual(m.ignoreList, tt.wantIgnoreList) { 39 t.Errorf("got %v, expected %v", m.ignoreList, tt.wantIgnoreList) 40 } 41 } 42} 43 44func TestIgnoreMatcher(t *testing.T) { 45 ignoreFile := ` 46dir1/ 47*.go 48**/data.* 49` 50 ig, err := ParseIgnoreFile(strings.NewReader(ignoreFile)) 51 if err != nil { 52 t.Errorf("error in ignoreFile") 53 } 54 tests := []struct { 55 path string 56 wantMatch bool 57 }{ 58 { 59 path: "dir1/readme.md", 60 wantMatch: true, 61 }, 62 { 63 path: "dir1/dir2/readme.md", 64 wantMatch: true, 65 }, 66 67 { 68 path: "foo.go", 69 wantMatch: true, 70 }, 71 { 72 path: "dir2/foo.go", 73 wantMatch: false, 74 }, 75 { 76 path: "dir3/data.xyz", 77 wantMatch: true, 78 }, 79 } 80 for _, tt := range tests { 81 t.Run(tt.path, func(t *testing.T) { 82 if got := ig.Match(tt.path); got != tt.wantMatch { 83 t.Errorf("got %t, expected %t", got, tt.wantMatch) 84 } 85 }) 86 } 87}