1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package pathspec
19
20 import (
21 "bytes"
22 "strings"
23 "testing"
24 )
25
26 func TestGitIgnore(t *testing.T) {
27 toInclude := []string{"!.#test", "~foo", "foo/foo.txt", "bar/foobar.txt", "foo/bar.txt", "/bar/foo"}
28 toIgnore := []string{".#test", "foo/#test#", "foo/bar/.foo.txt.swp", "foo/foobar/foobar.txt", "foo.txt", "test/foo.test", "test/foo/bar.test", "foo/bar", "foo/1/2/bar", "foo/foobar/abcd.txt", "foo/shibumi/test.txt"}
29 content := []string{".#*", "\\#*#", ".*.sw[a-z]", "**/foobar/foobar.txt", "/foo.txt", "test/", "foo/**/bar", "/b[^a]r/foo", "abcd.txt", "shibumi/"}
30
31 for _, f := range toInclude {
32 match, err := GitIgnore(content, f)
33 if err != nil {
34 t.Fatalf("Received an unexpected error: %s", err)
35 }
36 if match {
37 t.Errorf("GitIgnore('%s', %s) returned '%v', want 'false'", content, f, match)
38 }
39 }
40
41 for _, f := range toIgnore {
42 match, err := GitIgnore(content, f)
43 if err != nil {
44 t.Fatalf("Received an unexpected error: %s", err)
45 }
46 if !match {
47 t.Errorf("GitIgnore('%s', %s) returned '%v', want 'true'", content, f, match)
48 }
49 }
50 }
51
52 func TestReadGitIgnore(t *testing.T) {
53 toInclude := []string{"!.#test", "~foo", "foo/foo.txt", "bar/foobar.txt", "foo/bar.txt", "/bar/foo"}
54 toIgnore := []string{".#test", "foo/#test#", "foo/bar/.foo.txt.swp", "foo/foobar/foobar.txt", "foo.txt", "test/foo.test", "test/foo/bar.test", "foo/bar", "foo/1/2/bar"}
55 content := []byte(".#*\n\\#*#\n.*.sw[a-z]\n**/foobar/foobar.txt\n/foo.txt\ntest/\nfoo/**/bar\n/b[^a]r/foo")
56
57 for _, f := range toInclude {
58 match, err := ReadGitIgnore(bytes.NewReader(content), f)
59 if err != nil {
60 t.Fatalf("Received an unexpected error: %s", err)
61 }
62 if match {
63 t.Errorf("GitIgnore('%s', %s) returned '%v', want 'false'", strings.Replace(string(content), "\n", ", ", -1), f, match)
64 }
65 }
66
67 for _, f := range toIgnore {
68 match, err := ReadGitIgnore(bytes.NewReader(content), f)
69 if err != nil {
70 t.Fatalf("Received an unexpected error: %s", err)
71 }
72 if !match {
73 t.Errorf("GitIgnore('%s', %s) returned '%v', want 'true'", strings.Replace(string(content), "\n", ", ", -1), f, match)
74 }
75 }
76 }
77
View as plain text