| 95 | } |
| 96 | |
| 97 | func TestExcludes(t *testing.T) { |
| 98 | testFs := newTestFS() |
| 99 | |
| 100 | stignore := ` |
| 101 | !iex2 |
| 102 | !ign1/ex |
| 103 | ign1 |
| 104 | i*2 |
| 105 | !ign2 |
| 106 | ` |
| 107 | pats := New(testFs, WithCache(true)) |
| 108 | err := pats.Parse(bytes.NewBufferString(stignore), ".stignore") |
| 109 | if err != nil { |
| 110 | t.Fatal(err) |
| 111 | } |
| 112 | |
| 113 | tests := []struct { |
| 114 | f string |
| 115 | r bool |
| 116 | }{ |
| 117 | {"ign1", true}, |
| 118 | {"ign2", true}, |
| 119 | {"ibla2", true}, |
| 120 | {"iex2", false}, |
| 121 | {filepath.Join("ign1", "ign"), true}, |
| 122 | {filepath.Join("ign1", "ex"), false}, |
| 123 | {filepath.Join("ign1", "iex2"), false}, |
| 124 | {filepath.Join("iex2", "ign"), false}, |
| 125 | {filepath.Join("foo", "bar", "ign1"), true}, |
| 126 | {filepath.Join("foo", "bar", "ign2"), true}, |
| 127 | {filepath.Join("foo", "bar", "iex2"), false}, |
| 128 | } |
| 129 | |
| 130 | for _, tc := range tests { |
| 131 | if r := pats.Match(tc.f); r.IsIgnored() != tc.r { |
| 132 | t.Errorf("Incorrect match for %s: %v != %v", tc.f, r, tc.r) |
| 133 | } |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | func TestFlagOrder(t *testing.T) { |
| 138 | testFs := newTestFS() |