| 1 |
package gitattributes |
| 2 |
|
| 3 |
import ( |
| 4 |
"testing" |
| 5 |
|
| 6 |
. "gopkg.in/check.v1" |
| 7 |
) |
| 8 |
|
| 9 |
func Test(t *testing.T) { TestingT(t) } |
| 10 |
|
| 11 |
type PatternSuite struct{} |
| 12 |
|
| 13 |
var _ = Suite(&PatternSuite{}) |
| 14 |
|
| 15 |
func (s *PatternSuite) TestMatch_domainLonger_mismatch(c *C) { |
| 16 |
p := ParsePattern("value", []string{"head", "middle", "tail"}) |
| 17 |
r := p.Match([]string{"head", "middle"}) |
| 18 |
c.Assert(r, Equals, false) |
| 19 |
} |
| 20 |
|
| 21 |
func (s *PatternSuite) TestMatch_domainSameLength_mismatch(c *C) { |
| 22 |
p := ParsePattern("value", []string{"head", "middle", "tail"}) |
| 23 |
r := p.Match([]string{"head", "middle", "tail"}) |
| 24 |
c.Assert(r, Equals, false) |
| 25 |
} |
| 26 |
|
| 27 |
func (s *PatternSuite) TestMatch_domainMismatch_mismatch(c *C) { |
| 28 |
p := ParsePattern("value", []string{"head", "middle", "tail"}) |
| 29 |
r := p.Match([]string{"head", "middle", "_tail_", "value"}) |
| 30 |
c.Assert(r, Equals, false) |
| 31 |
} |
| 32 |
|
| 33 |
func (s *PatternSuite) TestSimpleMatch_match(c *C) { |
| 34 |
p := ParsePattern("vul?ano", nil) |
| 35 |
r := p.Match([]string{"value", "vulkano"}) |
| 36 |
c.Assert(r, Equals, true) |
| 37 |
} |
| 38 |
|
| 39 |
func (s *PatternSuite) TestSimpleMatch_withDomain(c *C) { |
| 40 |
p := ParsePattern("middle/tail", []string{"value", "volcano"}) |
| 41 |
r := p.Match([]string{"value", "volcano", "middle", "tail"}) |
| 42 |
c.Assert(r, Equals, true) |
| 43 |
} |
| 44 |
|
| 45 |
func (s *PatternSuite) TestSimpleMatch_onlyMatchInDomain_mismatch(c *C) { |
| 46 |
p := ParsePattern("value/volcano", []string{"value", "volcano"}) |
| 47 |
r := p.Match([]string{"value", "volcano", "tail"}) |
| 48 |
c.Assert(r, Equals, false) |
| 49 |
} |
| 50 |
|
| 51 |
func (s *PatternSuite) TestSimpleMatch_atStart(c *C) { |
| 52 |
p := ParsePattern("value", nil) |
| 53 |
r := p.Match([]string{"value", "tail"}) |
| 54 |
c.Assert(r, Equals, false) |
| 55 |
} |
| 56 |
|
| 57 |
func (s *PatternSuite) TestSimpleMatch_inTheMiddle(c *C) { |
| 58 |
p := ParsePattern("value", nil) |
| 59 |
r := p.Match([]string{"head", "value", "tail"}) |
| 60 |
c.Assert(r, Equals, false) |
| 61 |
} |
| 62 |
|
| 63 |
func (s *PatternSuite) TestSimpleMatch_atEnd(c *C) { |
| 64 |
p := ParsePattern("value", nil) |
| 65 |
r := p.Match([]string{"head", "value"}) |
| 66 |
c.Assert(r, Equals, true) |
| 67 |
} |
| 68 |
|
| 69 |
func (s *PatternSuite) TestSimpleMatch_mismatch(c *C) { |
| 70 |
p := ParsePattern("value", nil) |
| 71 |
r := p.Match([]string{"head", "val", "tail"}) |
| 72 |
c.Assert(r, Equals, false) |
| 73 |
} |
| 74 |
|
| 75 |
func (s *PatternSuite) TestSimpleMatch_valueLonger_mismatch(c *C) { |
| 76 |
p := ParsePattern("tai", nil) |
| 77 |
r := p.Match([]string{"head", "value", "tail"}) |
| 78 |
c.Assert(r, Equals, false) |
| 79 |
} |
| 80 |
|
| 81 |
func (s *PatternSuite) TestSimpleMatch_withAsterisk(c *C) { |
| 82 |
p := ParsePattern("t*l", nil) |
| 83 |
r := p.Match([]string{"value", "vulkano", "tail"}) |
| 84 |
c.Assert(r, Equals, true) |
| 85 |
} |
| 86 |
|
| 87 |
func (s *PatternSuite) TestSimpleMatch_withQuestionMark(c *C) { |
| 88 |
p := ParsePattern("ta?l", nil) |
| 89 |
r := p.Match([]string{"value", "vulkano", "tail"}) |
| 90 |
c.Assert(r, Equals, true) |
| 91 |
} |
| 92 |
|
| 93 |
func (s *PatternSuite) TestSimpleMatch_magicChars(c *C) { |
| 94 |
p := ParsePattern("v[ou]l[kc]ano", nil) |
| 95 |
r := p.Match([]string{"value", "volcano"}) |
| 96 |
c.Assert(r, Equals, true) |
| 97 |
} |
| 98 |
|
| 99 |
func (s *PatternSuite) TestSimpleMatch_wrongPattern_mismatch(c *C) { |
| 100 |
p := ParsePattern("v[ou]l[", nil) |
| 101 |
r := p.Match([]string{"value", "vol["}) |
| 102 |
c.Assert(r, Equals, false) |
| 103 |
} |
| 104 |
|
| 105 |
func (s *PatternSuite) TestGlobMatch_fromRootWithSlash(c *C) { |
| 106 |
p := ParsePattern("/value/vul?ano/tail", nil) |
| 107 |
r := p.Match([]string{"value", "vulkano", "tail"}) |
| 108 |
c.Assert(r, Equals, true) |
| 109 |
} |
| 110 |
|
| 111 |
func (s *PatternSuite) TestGlobMatch_withDomain(c *C) { |
| 112 |
p := ParsePattern("middle/tail", []string{"value", "volcano"}) |
| 113 |
r := p.Match([]string{"value", "volcano", "middle", "tail"}) |
| 114 |
c.Assert(r, Equals, true) |
| 115 |
} |
| 116 |
|
| 117 |
func (s *PatternSuite) TestGlobMatch_onlyMatchInDomain_mismatch(c *C) { |
| 118 |
p := ParsePattern("volcano/tail", []string{"value", "volcano"}) |
| 119 |
r := p.Match([]string{"value", "volcano", "tail"}) |
| 120 |
c.Assert(r, Equals, false) |
| 121 |
} |
| 122 |
|
| 123 |
func (s *PatternSuite) TestGlobMatch_fromRootWithoutSlash(c *C) { |
| 124 |
p := ParsePattern("value/vul?ano/tail", nil) |
| 125 |
r := p.Match([]string{"value", "vulkano", "tail"}) |
| 126 |
c.Assert(r, Equals, true) |
| 127 |
} |
| 128 |
|
| 129 |
func (s *PatternSuite) TestGlobMatch_fromRoot_mismatch(c *C) { |
| 130 |
p := ParsePattern("value/vulkano", nil) |
| 131 |
r := p.Match([]string{"value", "volcano"}) |
| 132 |
c.Assert(r, Equals, false) |
| 133 |
} |
| 134 |
|
| 135 |
func (s *PatternSuite) TestGlobMatch_fromRoot_tooShort_mismatch(c *C) { |
| 136 |
p := ParsePattern("value/vul?ano", nil) |
| 137 |
r := p.Match([]string{"value"}) |
| 138 |
c.Assert(r, Equals, false) |
| 139 |
} |
| 140 |
|
| 141 |
func (s *PatternSuite) TestGlobMatch_fromRoot_notAtRoot_mismatch(c *C) { |
| 142 |
p := ParsePattern("/value/volcano", nil) |
| 143 |
r := p.Match([]string{"value", "value", "volcano"}) |
| 144 |
c.Assert(r, Equals, false) |
| 145 |
} |
| 146 |
|
| 147 |
func (s *PatternSuite) TestGlobMatch_leadingAsterisks_atStart(c *C) { |
| 148 |
p := ParsePattern("**/*lue/vol?ano/ta?l", nil) |
| 149 |
r := p.Match([]string{"value", "volcano", "tail"}) |
| 150 |
c.Assert(r, Equals, true) |
| 151 |
} |
| 152 |
|
| 153 |
func (s *PatternSuite) TestGlobMatch_leadingAsterisks_notAtStart(c *C) { |
| 154 |
p := ParsePattern("**/*lue/vol?ano/tail", nil) |
| 155 |
r := p.Match([]string{"head", "value", "volcano", "tail"}) |
| 156 |
c.Assert(r, Equals, true) |
| 157 |
} |
| 158 |
|
| 159 |
func (s *PatternSuite) TestGlobMatch_leadingAsterisks_mismatch(c *C) { |
| 160 |
p := ParsePattern("**/*lue/vol?ano/tail", nil) |
| 161 |
r := p.Match([]string{"head", "value", "Volcano", "tail"}) |
| 162 |
c.Assert(r, Equals, false) |
| 163 |
} |
| 164 |
|
| 165 |
func (s *PatternSuite) TestGlobMatch_tailingAsterisks(c *C) { |
| 166 |
p := ParsePattern("/*lue/vol?ano/**", nil) |
| 167 |
r := p.Match([]string{"value", "volcano", "tail", "moretail"}) |
| 168 |
c.Assert(r, Equals, true) |
| 169 |
} |
| 170 |
|
| 171 |
func (s *PatternSuite) TestGlobMatch_tailingAsterisks_single(c *C) { |
| 172 |
p := ParsePattern("/*lue/**", nil) |
| 173 |
r := p.Match([]string{"value", "volcano"}) |
| 174 |
c.Assert(r, Equals, true) |
| 175 |
} |
| 176 |
|
| 177 |
func (s *PatternSuite) TestGlobMatch_tailingAsterisk_single(c *C) { |
| 178 |
p := ParsePattern("/*lue/*", nil) |
| 179 |
r := p.Match([]string{"value", "volcano", "tail"}) |
| 180 |
c.Assert(r, Equals, false) |
| 181 |
} |
| 182 |
|
| 183 |
func (s *PatternSuite) TestGlobMatch_tailingAsterisks_exactMatch(c *C) { |
| 184 |
p := ParsePattern("/*lue/vol?ano/**", nil) |
| 185 |
r := p.Match([]string{"value", "volcano"}) |
| 186 |
c.Assert(r, Equals, false) |
| 187 |
} |
| 188 |
|
| 189 |
func (s *PatternSuite) TestGlobMatch_middleAsterisks_emptyMatch(c *C) { |
| 190 |
p := ParsePattern("/*lue/**/vol?ano", nil) |
| 191 |
r := p.Match([]string{"value", "volcano"}) |
| 192 |
c.Assert(r, Equals, true) |
| 193 |
} |
| 194 |
|
| 195 |
func (s *PatternSuite) TestGlobMatch_middleAsterisks_oneMatch(c *C) { |
| 196 |
p := ParsePattern("/*lue/**/vol?ano", nil) |
| 197 |
r := p.Match([]string{"value", "middle", "volcano"}) |
| 198 |
c.Assert(r, Equals, true) |
| 199 |
} |
| 200 |
|
| 201 |
func (s *PatternSuite) TestGlobMatch_middleAsterisks_multiMatch(c *C) { |
| 202 |
p := ParsePattern("/*lue/**/vol?ano", nil) |
| 203 |
r := p.Match([]string{"value", "middle1", "middle2", "volcano"}) |
| 204 |
c.Assert(r, Equals, true) |
| 205 |
} |
| 206 |
|
| 207 |
func (s *PatternSuite) TestGlobMatch_wrongDoubleAsterisk_mismatch(c *C) { |
| 208 |
p := ParsePattern("/*lue/**foo/vol?ano/tail", nil) |
| 209 |
r := p.Match([]string{"value", "foo", "volcano", "tail"}) |
| 210 |
c.Assert(r, Equals, false) |
| 211 |
} |
| 212 |
|
| 213 |
func (s *PatternSuite) TestGlobMatch_magicChars(c *C) { |
| 214 |
p := ParsePattern("**/head/v[ou]l[kc]ano", nil) |
| 215 |
r := p.Match([]string{"value", "head", "volcano"}) |
| 216 |
c.Assert(r, Equals, true) |
| 217 |
} |
| 218 |
|
| 219 |
func (s *PatternSuite) TestGlobMatch_wrongPattern_noTraversal_mismatch(c *C) { |
| 220 |
p := ParsePattern("**/head/v[ou]l[", nil) |
| 221 |
r := p.Match([]string{"value", "head", "vol["}) |
| 222 |
c.Assert(r, Equals, false) |
| 223 |
} |
| 224 |
|
| 225 |
func (s *PatternSuite) TestGlobMatch_wrongPattern_onTraversal_mismatch(c *C) { |
| 226 |
p := ParsePattern("/value/**/v[ou]l[", nil) |
| 227 |
r := p.Match([]string{"value", "head", "vol["}) |
| 228 |
c.Assert(r, Equals, false) |
| 229 |
} |
| 230 |
|
| 231 |
func (s *PatternSuite) TestGlobMatch_issue_923(c *C) { |
| 232 |
p := ParsePattern("**/android/**/GeneratedPluginRegistrant.java", nil) |
| 233 |
r := p.Match([]string{"packages", "flutter_tools", "lib", "src", "android", "gradle.dart"}) |
| 234 |
c.Assert(r, Equals, false) |
| 235 |
} |