aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format/gitignore
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-06-19 10:26:03 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2017-06-19 10:26:03 +0200
commit3ae5d4de35e76f2f573b550d93bb2aed8137f1cb (patch)
treeab3c103c09dd6eaf07c99de04b643869eca1a7ce /plumbing/format/gitignore
parent93633b5767b0d571bedc724364209d30f96a7b17 (diff)
downloadgo-git-3ae5d4de35e76f2f573b550d93bb2aed8137f1cb.tar.gz
plumbing: gitignore, upgrade to go-billy.v3 and test with gocheck
Diffstat (limited to 'plumbing/format/gitignore')
-rw-r--r--plumbing/format/gitignore/dir.go13
-rw-r--r--plumbing/format/gitignore/dir_test.go62
-rw-r--r--plumbing/format/gitignore/matcher_test.go15
-rw-r--r--plumbing/format/gitignore/pattern_test.go327
4 files changed, 199 insertions, 218 deletions
diff --git a/plumbing/format/gitignore/dir.go b/plumbing/format/gitignore/dir.go
index 16e4617..c3bfc53 100644
--- a/plumbing/format/gitignore/dir.go
+++ b/plumbing/format/gitignore/dir.go
@@ -2,9 +2,10 @@ package gitignore
import (
"io/ioutil"
+ "os"
"strings"
- "gopkg.in/src-d/go-billy.v2"
+ "gopkg.in/src-d/go-billy.v3"
)
const (
@@ -17,8 +18,10 @@ const (
// ReadPatterns reads gitignore patterns recursively traversing through the directory
// structure. The result is in the ascending order of priority (last higher).
func ReadPatterns(fs billy.Filesystem, path []string) (ps []Pattern, err error) {
- if f, err := fs.Open(fs.Join(append(path, gitignoreFile)...)); err == nil {
+ f, err := fs.Open(fs.Join(append(path, gitignoreFile)...))
+ if err == nil {
defer f.Close()
+
if data, err := ioutil.ReadAll(f); err == nil {
for _, s := range strings.Split(string(data), eol) {
if !strings.HasPrefix(s, commentPrefix) && len(strings.TrimSpace(s)) > 0 {
@@ -26,13 +29,16 @@ func ReadPatterns(fs billy.Filesystem, path []string) (ps []Pattern, err error)
}
}
}
+ } else if !os.IsNotExist(err) {
+ return nil, err
}
- var fis []billy.FileInfo
+ var fis []os.FileInfo
fis, err = fs.ReadDir(fs.Join(path...))
if err != nil {
return
}
+
for _, fi := range fis {
if fi.IsDir() && fi.Name() != gitDir {
var subps []Pattern
@@ -40,6 +46,7 @@ func ReadPatterns(fs billy.Filesystem, path []string) (ps []Pattern, err error)
if err != nil {
return
}
+
if len(subps) > 0 {
ps = append(ps, subps...)
}
diff --git a/plumbing/format/gitignore/dir_test.go b/plumbing/format/gitignore/dir_test.go
index 61f3fc0..d28a714 100644
--- a/plumbing/format/gitignore/dir_test.go
+++ b/plumbing/format/gitignore/dir_test.go
@@ -2,40 +2,50 @@ package gitignore
import (
"os"
- "testing"
- "gopkg.in/src-d/go-billy.v2"
- "gopkg.in/src-d/go-billy.v2/memfs"
+ "gopkg.in/src-d/go-billy.v3"
+ "gopkg.in/src-d/go-billy.v3/memfs"
+
+ . "gopkg.in/check.v1"
)
-func setupTestFS(subdirError bool) billy.Filesystem {
+type MatcherSuite struct {
+ FS billy.Filesystem
+}
+
+var _ = Suite(&MatcherSuite{})
+
+func (s *MatcherSuite) SetUpTest(c *C) {
fs := memfs.New()
- f, _ := fs.Create(".gitignore")
- f.Write([]byte("vendor/g*/\n"))
- f.Close()
- fs.MkdirAll("vendor", os.ModePerm)
- f, _ = fs.Create("vendor/.gitignore")
- f.Write([]byte("!github.com/\n"))
- f.Close()
+ f, err := fs.Create(".gitignore")
+ c.Assert(err, IsNil)
+ _, err = f.Write([]byte("vendor/g*/\n"))
+ c.Assert(err, IsNil)
+ err = f.Close()
+ c.Assert(err, IsNil)
+
+ err = fs.MkdirAll("vendor", os.ModePerm)
+ c.Assert(err, IsNil)
+ f, err = fs.Create("vendor/.gitignore")
+ c.Assert(err, IsNil)
+ _, err = f.Write([]byte("!github.com/\n"))
+ c.Assert(err, IsNil)
+ err = f.Close()
+ c.Assert(err, IsNil)
+
fs.MkdirAll("another", os.ModePerm)
fs.MkdirAll("vendor/github.com", os.ModePerm)
fs.MkdirAll("vendor/gopkg.in", os.ModePerm)
- return fs
+
+ s.FS = fs
}
-func TestDir_ReadPatterns(t *testing.T) {
- ps, err := ReadPatterns(setupTestFS(false), nil)
- if err != nil {
- t.Errorf("no error expected, found %v", err)
- }
- if len(ps) != 2 {
- t.Errorf("expected 2 patterns, found %v", len(ps))
- }
+func (s *MatcherSuite) TestDir_ReadPatterns(c *C) {
+ ps, err := ReadPatterns(s.FS, nil)
+ c.Assert(err, IsNil)
+ c.Assert(ps, HasLen, 2)
+
m := NewMatcher(ps)
- if !m.Match([]string{"vendor", "gopkg.in"}, true) {
- t.Error("expected a match")
- }
- if m.Match([]string{"vendor", "github.com"}, true) {
- t.Error("expected no match")
- }
+ c.Assert(m.Match([]string{"vendor", "gopkg.in"}, true), Equals, true)
+ c.Assert(m.Match([]string{"vendor", "github.com"}, true), Equals, false)
}
diff --git a/plumbing/format/gitignore/matcher_test.go b/plumbing/format/gitignore/matcher_test.go
index 268e1c0..7311042 100644
--- a/plumbing/format/gitignore/matcher_test.go
+++ b/plumbing/format/gitignore/matcher_test.go
@@ -1,17 +1,16 @@
package gitignore
-import "testing"
+import (
+ . "gopkg.in/check.v1"
+)
-func TestMatcher_Match(t *testing.T) {
+func (s *MatcherSuite) TestMatcher_Match(c *C) {
ps := []Pattern{
ParsePattern("**/middle/v[uo]l?ano", nil),
ParsePattern("!volcano", nil),
}
+
m := NewMatcher(ps)
- if !m.Match([]string{"head", "middle", "vulkano"}, false) {
- t.Errorf("expected a match, found mismatch")
- }
- if m.Match([]string{"head", "middle", "volcano"}, false) {
- t.Errorf("expected a mismatch, found a match")
- }
+ c.Assert(m.Match([]string{"head", "middle", "vulkano"}, false), Equals, true)
+ c.Assert(m.Match([]string{"head", "middle", "volcano"}, false), Equals, false)
}
diff --git a/plumbing/format/gitignore/pattern_test.go b/plumbing/format/gitignore/pattern_test.go
index 3abb012..f94cef3 100644
--- a/plumbing/format/gitignore/pattern_test.go
+++ b/plumbing/format/gitignore/pattern_test.go
@@ -1,318 +1,283 @@
package gitignore
-import "testing"
+import (
+ "testing"
-func TestPatternSimpleMatch_inclusion(t *testing.T) {
+ . "gopkg.in/check.v1"
+)
+
+func Test(t *testing.T) { TestingT(t) }
+
+type PatternSuite struct{}
+
+var _ = Suite(&PatternSuite{})
+
+func (s *PatternSuite) TestSimpleMatch_inclusion(c *C) {
p := ParsePattern("!vul?ano", nil)
- if res := p.Match([]string{"value", "vulkano", "tail"}, false); res != Include {
- t.Errorf("expected Exclude, found %v", res)
- }
+ r := p.Match([]string{"value", "vulkano", "tail"}, false)
+ c.Assert(r, Equals, Include)
}
-func TestPatternMatch_domainLonger_mismatch(t *testing.T) {
+func (s *PatternSuite) TestMatch_domainLonger_mismatch(c *C) {
p := ParsePattern("value", []string{"head", "middle", "tail"})
- if res := p.Match([]string{"head", "middle"}, false); res != NoMatch {
- t.Errorf("expected NoMatch, found %v", res)
- }
+ r := p.Match([]string{"head", "middle"}, false)
+ c.Assert(r, Equals, NoMatch)
}
-func TestPatternMatch_domainSameLength_mismatch(t *testing.T) {
+func (s *PatternSuite) TestMatch_domainSameLength_mismatch(c *C) {
p := ParsePattern("value", []string{"head", "middle", "tail"})
- if res := p.Match([]string{"head", "middle", "tail"}, false); res != NoMatch {
- t.Errorf("expected NoMatch, found %v", res)
- }
+ r := p.Match([]string{"head", "middle", "tail"}, false)
+ c.Assert(r, Equals, NoMatch)
}
-func TestPatternMatch_domainMismatch_mismatch(t *testing.T) {
+func (s *PatternSuite) TestMatch_domainMismatch_mismatch(c *C) {
p := ParsePattern("value", []string{"head", "middle", "tail"})
- if res := p.Match([]string{"head", "middle", "_tail_", "value"}, false); res != NoMatch {
- t.Errorf("expected NoMatch, found %v", res)
- }
+ r := p.Match([]string{"head", "middle", "_tail_", "value"}, false)
+ c.Assert(r, Equals, NoMatch)
}
-func TestPatternSimpleMatch_withDomain(t *testing.T) {
+func (s *PatternSuite) TestSimpleMatch_withDomain(c *C) {
p := ParsePattern("middle/", []string{"value", "volcano"})
- if res := p.Match([]string{"value", "volcano", "middle", "tail"}, false); res != Exclude {
- t.Errorf("expected Exclude, found %v", res)
- }
+ r := p.Match([]string{"value", "volcano", "middle", "tail"}, false)
+ c.Assert(r, Equals, Exclude)
}
-func TestPatternSimpleMatch_onlyMatchInDomain_mismatch(t *testing.T) {
+func (s *PatternSuite) TestSimpleMatch_onlyMatchInDomain_mismatch(c *C) {
p := ParsePattern("volcano/", []string{"value", "volcano"})
- if res := p.Match([]string{"value", "volcano", "tail"}, true); res != NoMatch {
- t.Errorf("expected NoMatch, found %v", res)
- }
+ r := p.Match([]string{"value", "volcano", "tail"}, true)
+ c.Assert(r, Equals, NoMatch)
}
-func TestPatternSimpleMatch_atStart(t *testing.T) {
+func (s *PatternSuite) TestSimpleMatch_atStart(c *C) {
p := ParsePattern("value", nil)
- if res := p.Match([]string{"value", "tail"}, false); res != Exclude {
- t.Errorf("expected Exclude, found %v", res)
- }
+ r := p.Match([]string{"value", "tail"}, false)
+ c.Assert(r, Equals, Exclude)
}
-func TestPatternSimpleMatch_inTheMiddle(t *testing.T) {
+func (s *PatternSuite) TestSimpleMatch_inTheMiddle(c *C) {
p := ParsePattern("value", nil)
- if res := p.Match([]string{"head", "value", "tail"}, false); res != Exclude {
- t.Errorf("expected Exclude, found %v", res)
- }
+ r := p.Match([]string{"head", "value", "tail"}, false)
+ c.Assert(r, Equals, Exclude)
}
-func TestPatternSimpleMatch_atEnd(t *testing.T) {
+func (s *PatternSuite) TestSimpleMatch_atEnd(c *C) {
p := ParsePattern("value", nil)
- if res := p.Match([]string{"head", "value"}, false); res != Exclude {
- t.Errorf("expected Exclude, found %v", res)
- }
+ r := p.Match([]string{"head", "value"}, false)
+ c.Assert(r, Equals, Exclude)
}
-func TestPatternSimpleMatch_atStart_dirWanted(t *testing.T) {
+func (s *PatternSuite) TestSimpleMatch_atStart_dirWanted(c *C) {
p := ParsePattern("value/", nil)
- if res := p.Match([]string{"value", "tail"}, false); res != Exclude {
- t.Errorf("expected Exclude, found %v", res)
- }
+ r := p.Match([]string{"value", "tail"}, false)
+ c.Assert(r, Equals, Exclude)
}
-func TestPatternSimpleMatch_inTheMiddle_dirWanted(t *testing.T) {
+func (s *PatternSuite) TestSimpleMatch_inTheMiddle_dirWanted(c *C) {
p := ParsePattern("value/", nil)
- if res := p.Match([]string{"head", "value", "tail"}, false); res != Exclude {
- t.Errorf("expected Exclude, found %v", res)
- }
+ r := p.Match([]string{"head", "value", "tail"}, false)
+ c.Assert(r, Equals, Exclude)
}
-func TestPatternSimpleMatch_atEnd_dirWanted(t *testing.T) {
+func (s *PatternSuite) TestSimpleMatch_atEnd_dirWanted(c *C) {
p := ParsePattern("value/", nil)
- if res := p.Match([]string{"head", "value"}, true); res != Exclude {
- t.Errorf("expected Exclude, found %v", res)
- }
+ r := p.Match([]string{"head", "value"}, true)
+ c.Assert(r, Equals, Exclude)
}
-func TestPatternSimpleMatch_atEnd_dirWanted_notADir_mismatch(t *testing.T) {
+func (s *PatternSuite) TestSimpleMatch_atEnd_dirWanted_notADir_mismatch(c *C) {
p := ParsePattern("value/", nil)
- if res := p.Match([]string{"head", "value"}, false); res != NoMatch {
- t.Errorf("expected NoMatch, found %v", res)
- }
+ r := p.Match([]string{"head", "value"}, false)
+ c.Assert(r, Equals, NoMatch)
}
-func TestPatternSimpleMatch_mismatch(t *testing.T) {
+func (s *PatternSuite) TestSimpleMatch_mismatch(c *C) {
p := ParsePattern("value", nil)
- if res := p.Match([]string{"head", "val", "tail"}, false); res != NoMatch {
- t.Errorf("expected NoMatch, found %v", res)
- }
+ r := p.Match([]string{"head", "val", "tail"}, false)
+ c.Assert(r, Equals, NoMatch)
}
-func TestPatternSimpleMatch_valueLonger_mismatch(t *testing.T) {
+func (s *PatternSuite) TestSimpleMatch_valueLonger_mismatch(c *C) {
p := ParsePattern("val", nil)
- if res := p.Match([]string{"head", "value", "tail"}, false); res != NoMatch {
- t.Errorf("expected NoMatch, found %v", res)
- }
+ r := p.Match([]string{"head", "value", "tail"}, false)
+ c.Assert(r, Equals, NoMatch)
}
-func TestPatternSimpleMatch_withAsterisk(t *testing.T) {
+func (s *PatternSuite) TestSimpleMatch_withAsterisk(c *C) {
p := ParsePattern("v*o", nil)
- if res := p.Match([]string{"value", "vulkano", "tail"}, false); res != Exclude {
- t.Errorf("expected Exclude, found %v", res)
- }
+ r := p.Match([]string{"value", "vulkano", "tail"}, false)
+ c.Assert(r, Equals, Exclude)
}
-func TestPatternSimpleMatch_withQuestionMark(t *testing.T) {
+func (s *PatternSuite) TestSimpleMatch_withQuestionMark(c *C) {
p := ParsePattern("vul?ano", nil)
- if res := p.Match([]string{"value", "vulkano", "tail"}, false); res != Exclude {
- t.Errorf("expected Exclude, found %v", res)
- }
+ r := p.Match([]string{"value", "vulkano", "tail"}, false)
+ c.Assert(r, Equals, Exclude)
}
-func TestPatternSimpleMatch_magicChars(t *testing.T) {
+func (s *PatternSuite) TestSimpleMatch_magicChars(c *C) {
p := ParsePattern("v[ou]l[kc]ano", nil)
- if res := p.Match([]string{"value", "volcano"}, false); res != Exclude {
- t.Errorf("expected Exclude, found %v", res)
- }
+ r := p.Match([]string{"value", "volcano"}, false)
+ c.Assert(r, Equals, Exclude)
}
-func TestPatternSimpleMatch_wrongPattern_mismatch(t *testing.T) {
+func (s *PatternSuite) TestSimpleMatch_wrongPattern_mismatch(c *C) {
p := ParsePattern("v[ou]l[", nil)
- if res := p.Match([]string{"value", "vol["}, false); res != NoMatch {
- t.Errorf("expected NoMatch, found %v", res)
- }
+ r := p.Match([]string{"value", "vol["}, false)
+ c.Assert(r, Equals, NoMatch)
}
-func TestPatternGlobMatch_fromRootWithSlash(t *testing.T) {
+func (s *PatternSuite) TestGlobMatch_fromRootWithSlash(c *C) {
p := ParsePattern("/value/vul?ano", nil)
- if res := p.Match([]string{"value", "vulkano", "tail"}, false); res != Exclude {
- t.Errorf("expected Exclude, found %v", res)
- }
+ r := p.Match([]string{"value", "vulkano", "tail"}, false)
+ c.Assert(r, Equals, Exclude)
}
-func TestPatternGlobMatch_withDomain(t *testing.T) {
+func (s *PatternSuite) TestGlobMatch_withDomain(c *C) {
p := ParsePattern("middle/tail/", []string{"value", "volcano"})
- if res := p.Match([]string{"value", "volcano", "middle", "tail"}, true); res != Exclude {
- t.Errorf("expected Exclude, found %v", res)
- }
+ r := p.Match([]string{"value", "volcano", "middle", "tail"}, true)
+ c.Assert(r, Equals, Exclude)
}
-func TestPatternGlobMatch_onlyMatchInDomain_mismatch(t *testing.T) {
+func (s *PatternSuite) TestGlobMatch_onlyMatchInDomain_mismatch(c *C) {
p := ParsePattern("volcano/tail", []string{"value", "volcano"})
- if res := p.Match([]string{"value", "volcano", "tail"}, false); res != NoMatch {
- t.Errorf("expected NoMatch, found %v", res)
- }
+ r := p.Match([]string{"value", "volcano", "tail"}, false)
+ c.Assert(r, Equals, NoMatch)
}
-func TestPatternGlobMatch_fromRootWithoutSlash(t *testing.T) {
+func (s *PatternSuite) TestGlobMatch_fromRootWithoutSlash(c *C) {
p := ParsePattern("value/vul?ano", nil)
- if res := p.Match([]string{"value", "vulkano", "tail"}, false); res != Exclude {
- t.Errorf("expected Exclude, found %v", res)
- }
+ r := p.Match([]string{"value", "vulkano", "tail"}, false)
+ c.Assert(r, Equals, Exclude)
}
-func TestPatternGlobMatch_fromRoot_mismatch(t *testing.T) {
+func (s *PatternSuite) TestGlobMatch_fromRoot_mismatch(c *C) {
p := ParsePattern("value/vulkano", nil)
- if res := p.Match([]string{"value", "volcano"}, false); res != NoMatch {
- t.Errorf("expected NoMatch, found %v", res)
- }
+ r := p.Match([]string{"value", "volcano"}, false)
+ c.Assert(r, Equals, NoMatch)
}
-func TestPatternGlobMatch_fromRoot_tooShort_mismatch(t *testing.T) {
+func (s *PatternSuite) TestGlobMatch_fromRoot_tooShort_mismatch(c *C) {
p := ParsePattern("value/vul?ano", nil)
- if res := p.Match([]string{"value"}, false); res != NoMatch {
- t.Errorf("expected NoMatch, found %v", res)
- }
+ r := p.Match([]string{"value"}, false)
+ c.Assert(r, Equals, NoMatch)
}
-func TestPatternGlobMatch_fromRoot_notAtRoot_mismatch(t *testing.T) {
+func (s *PatternSuite) TestGlobMatch_fromRoot_notAtRoot_mismatch(c *C) {
p := ParsePattern("/value/volcano", nil)
- if res := p.Match([]string{"value", "value", "volcano"}, false); res != NoMatch {
- t.Errorf("expected NoMatch, found %v", res)
- }
+ r := p.Match([]string{"value", "value", "volcano"}, false)
+ c.Assert(r, Equals, NoMatch)
}
-func TestPatternGlobMatch_leadingAsterisks_atStart(t *testing.T) {
+func (s *PatternSuite) TestGlobMatch_leadingAsterisks_atStart(c *C) {
p := ParsePattern("**/*lue/vol?ano", nil)
- if res := p.Match([]string{"value", "volcano", "tail"}, false); res != Exclude {
- t.Errorf("expected Exclude, found %v", res)
- }
+ r := p.Match([]string{"value", "volcano", "tail"}, false)
+ c.Assert(r, Equals, Exclude)
}
-func TestPatternGlobMatch_leadingAsterisks_notAtStart(t *testing.T) {
+func (s *PatternSuite) TestGlobMatch_leadingAsterisks_notAtStart(c *C) {
p := ParsePattern("**/*lue/vol?ano", nil)
- if res := p.Match([]string{"head", "value", "volcano", "tail"}, false); res != Exclude {
- t.Errorf("expected Exclude, found %v", res)
- }
+ r := p.Match([]string{"head", "value", "volcano", "tail"}, false)
+ c.Assert(r, Equals, Exclude)
}
-func TestPatternGlobMatch_leadingAsterisks_mismatch(t *testing.T) {
+func (s *PatternSuite) TestGlobMatch_leadingAsterisks_mismatch(c *C) {
p := ParsePattern("**/*lue/vol?ano", nil)
- if res := p.Match([]string{"head", "value", "Volcano", "tail"}, false); res != NoMatch {
- t.Errorf("expected NoMatch, found %v", res)
- }
+ r := p.Match([]string{"head", "value", "Volcano", "tail"}, false)
+ c.Assert(r, Equals, NoMatch)
}
-func TestPatternGlobMatch_leadingAsterisks_isDir(t *testing.T) {
+func (s *PatternSuite) TestGlobMatch_leadingAsterisks_isDir(c *C) {
p := ParsePattern("**/*lue/vol?ano/", nil)
- if res := p.Match([]string{"head", "value", "volcano", "tail"}, false); res != Exclude {
- t.Errorf("expected Exclude, found %v", res)
- }
+ r := p.Match([]string{"head", "value", "volcano", "tail"}, false)
+ c.Assert(r, Equals, Exclude)
}
-func TestPatternGlobMatch_leadingAsterisks_isDirAtEnd(t *testing.T) {
+func (s *PatternSuite) TestGlobMatch_leadingAsterisks_isDirAtEnd(c *C) {
p := ParsePattern("**/*lue/vol?ano/", nil)
- if res := p.Match([]string{"head", "value", "volcano"}, true); res != Exclude {
- t.Errorf("expected Exclude, found %v", res)
- }
+ r := p.Match([]string{"head", "value", "volcano"}, true)
+ c.Assert(r, Equals, Exclude)
}
-func TestPatternGlobMatch_leadingAsterisks_isDir_mismatch(t *testing.T) {
+func (s *PatternSuite) TestGlobMatch_leadingAsterisks_isDir_mismatch(c *C) {
p := ParsePattern("**/*lue/vol?ano/", nil)
- if res := p.Match([]string{"head", "value", "Colcano"}, true); res != NoMatch {
- t.Errorf("expected NoMatch, found %v", res)
- }
+ r := p.Match([]string{"head", "value", "Colcano"}, true)
+ c.Assert(r, Equals, NoMatch)
}
-func TestPatternGlobMatch_leadingAsterisks_isDirNoDirAtEnd_mismatch(t *testing.T) {
+func (s *PatternSuite) TestGlobMatch_leadingAsterisks_isDirNoDirAtEnd_mismatch(c *C) {
p := ParsePattern("**/*lue/vol?ano/", nil)
- if res := p.Match([]string{"head", "value", "volcano"}, false); res != NoMatch {
- t.Errorf("expected NoMatch, found %v", res)
- }
+ r := p.Match([]string{"head", "value", "volcano"}, false)
+ c.Assert(r, Equals, NoMatch)
}
-func TestPatternGlobMatch_tailingAsterisks(t *testing.T) {
+func (s *PatternSuite) TestGlobMatch_tailingAsterisks(c *C) {
p := ParsePattern("/*lue/vol?ano/**", nil)
- if res := p.Match([]string{"value", "volcano", "tail", "moretail"}, false); res != Exclude {
- t.Errorf("expected Exclude, found %v", res)
- }
+ r := p.Match([]string{"value", "volcano", "tail", "moretail"}, false)
+ c.Assert(r, Equals, Exclude)
}
-func TestPatternGlobMatch_tailingAsterisks_exactMatch(t *testing.T) {
+func (s *PatternSuite) TestGlobMatch_tailingAsterisks_exactMatch(c *C) {
p := ParsePattern("/*lue/vol?ano/**", nil)
- if res := p.Match([]string{"value", "volcano"}, false); res != Exclude {
- t.Errorf("expected Exclude, found %v", res)
- }
+ r := p.Match([]string{"value", "volcano"}, false)
+ c.Assert(r, Equals, Exclude)
}
-func TestPatternGlobMatch_middleAsterisks_emptyMatch(t *testing.T) {
+func (s *PatternSuite) TestGlobMatch_middleAsterisks_emptyMatch(c *C) {
p := ParsePattern("/*lue/**/vol?ano", nil)
- if res := p.Match([]string{"value", "volcano"}, false); res != Exclude {
- t.Errorf("expected Exclude, found %v", res)
- }
+ r := p.Match([]string{"value", "volcano"}, false)
+ c.Assert(r, Equals, Exclude)
}
-func TestPatternGlobMatch_middleAsterisks_oneMatch(t *testing.T) {
+func (s *PatternSuite) TestGlobMatch_middleAsterisks_oneMatch(c *C) {
p := ParsePattern("/*lue/**/vol?ano", nil)
- if res := p.Match([]string{"value", "middle", "volcano"}, false); res != Exclude {
- t.Errorf("expected Exclude, found %v", res)
- }
+ r := p.Match([]string{"value", "middle", "volcano"}, false)
+ c.Assert(r, Equals, Exclude)
}
-func TestPatternGlobMatch_middleAsterisks_multiMatch(t *testing.T) {
+func (s *PatternSuite) TestGlobMatch_middleAsterisks_multiMatch(c *C) {
p := ParsePattern("/*lue/**/vol?ano", nil)
- if res := p.Match([]string{"value", "middle1", "middle2", "volcano"}, false); res != Exclude {
- t.Errorf("expected Exclude, found %v", res)
- }
+ r := p.Match([]string{"value", "middle1", "middle2", "volcano"}, false)
+ c.Assert(r, Equals, Exclude)
}
-func TestPatternGlobMatch_middleAsterisks_isDir_trailing(t *testing.T) {
+func (s *PatternSuite) TestGlobMatch_middleAsterisks_isDir_trailing(c *C) {
p := ParsePattern("/*lue/**/vol?ano/", nil)
- if res := p.Match([]string{"value", "middle1", "middle2", "volcano"}, true); res != Exclude {
- t.Errorf("expected Exclude, found %v", res)
- }
+ r := p.Match([]string{"value", "middle1", "middle2", "volcano"}, true)
+ c.Assert(r, Equals, Exclude)
}
-func TestPatternGlobMatch_middleAsterisks_isDir_trailing_mismatch(t *testing.T) {
+func (s *PatternSuite) TestGlobMatch_middleAsterisks_isDir_trailing_mismatch(c *C) {
p := ParsePattern("/*lue/**/vol?ano/", nil)
- if res := p.Match([]string{"value", "middle1", "middle2", "volcano"}, false); res != NoMatch {
- t.Errorf("expected NoMatch, found %v", res)
- }
+ r := p.Match([]string{"value", "middle1", "middle2", "volcano"}, false)
+ c.Assert(r, Equals, NoMatch)
}
-func TestPatternGlobMatch_middleAsterisks_isDir(t *testing.T) {
+func (s *PatternSuite) TestGlobMatch_middleAsterisks_isDir(c *C) {
p := ParsePattern("/*lue/**/vol?ano/", nil)
- if res := p.Match([]string{"value", "middle1", "middle2", "volcano", "tail"}, false); res != Exclude {
- t.Errorf("expected Exclude, found %v", res)
- }
+ r := p.Match([]string{"value", "middle1", "middle2", "volcano", "tail"}, false)
+ c.Assert(r, Equals, Exclude)
}
-func TestPatternGlobMatch_wrongDoubleAsterisk_mismatch(t *testing.T) {
+func (s *PatternSuite) TestGlobMatch_wrongDoubleAsterisk_mismatch(c *C) {
p := ParsePattern("/*lue/**foo/vol?ano", nil)
- if res := p.Match([]string{"value", "foo", "volcano", "tail"}, false); res != NoMatch {
- t.Errorf("expected NoMatch, found %v", res)
- }
+ r := p.Match([]string{"value", "foo", "volcano", "tail"}, false)
+ c.Assert(r, Equals, NoMatch)
}
-func TestPatternGlobMatch_magicChars(t *testing.T) {
+func (s *PatternSuite) TestGlobMatch_magicChars(c *C) {
p := ParsePattern("**/head/v[ou]l[kc]ano", nil)
- if res := p.Match([]string{"value", "head", "volcano"}, false); res != Exclude {
- t.Errorf("expected Exclude, found %v", res)
- }
+ r := p.Match([]string{"value", "head", "volcano"}, false)
+ c.Assert(r, Equals, Exclude)
}
-func TestPatternGlobMatch_wrongPattern_noTraversal_mismatch(t *testing.T) {
+func (s *PatternSuite) TestGlobMatch_wrongPattern_noTraversal_mismatch(c *C) {
p := ParsePattern("**/head/v[ou]l[", nil)
- if res := p.Match([]string{"value", "head", "vol["}, false); res != NoMatch {
- t.Errorf("expected NoMatch, found %v", res)
- }
+ r := p.Match([]string{"value", "head", "vol["}, false)
+ c.Assert(r, Equals, NoMatch)
}
-func TestPatternGlobMatch_wrongPattern_onTraversal_mismatch(t *testing.T) {
+func (s *PatternSuite) TestGlobMatch_wrongPattern_onTraversal_mismatch(c *C) {
p := ParsePattern("/value/**/v[ou]l[", nil)
- if res := p.Match([]string{"value", "head", "vol["}, false); res != NoMatch {
- t.Errorf("expected NoMatch, found %v", res)
- }
+ r := p.Match([]string{"value", "head", "vol["}, false)
+ c.Assert(r, Equals, NoMatch)
}