aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format/index/index_test.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2018-02-28 19:18:36 +0100
committerGitHub <noreply@github.com>2018-02-28 19:18:36 +0100
commit4397264e391b45a8eac147cc7373189d55c640cc (patch)
tree6198853fc7ca31ac16a0cbfa683828568452a6dd /plumbing/format/index/index_test.go
parentdefd0b861ca79845c8f06f7c826c769012404bbd (diff)
parent6d23b50e27312f3ba3e839153c2c0db5237c827d (diff)
downloadgo-git-4397264e391b45a8eac147cc7373189d55c640cc.tar.gz
Merge pull request #739 from mcuadros/add
new methods Worktree.[AddGlob|RemoveBlob] and recursive Worktree.[Add|Remove]
Diffstat (limited to 'plumbing/format/index/index_test.go')
-rw-r--r--plumbing/format/index/index_test.go37
1 files changed, 37 insertions, 0 deletions
diff --git a/plumbing/format/index/index_test.go b/plumbing/format/index/index_test.go
index cad5f9c..ecf3c0d 100644
--- a/plumbing/format/index/index_test.go
+++ b/plumbing/format/index/index_test.go
@@ -1,9 +1,22 @@
package index
import (
+ "path/filepath"
+
. "gopkg.in/check.v1"
)
+func (s *IndexSuite) TestIndexAdd(c *C) {
+ idx := &Index{}
+ e := idx.Add("foo")
+ e.Size = 42
+
+ e, err := idx.Entry("foo")
+ c.Assert(err, IsNil)
+ c.Assert(e.Name, Equals, "foo")
+ c.Assert(e.Size, Equals, uint32(42))
+}
+
func (s *IndexSuite) TestIndexEntry(c *C) {
idx := &Index{
Entries: []*Entry{
@@ -37,3 +50,27 @@ func (s *IndexSuite) TestIndexRemove(c *C) {
c.Assert(e, IsNil)
c.Assert(err, Equals, ErrEntryNotFound)
}
+
+func (s *IndexSuite) TestIndexGlob(c *C) {
+ idx := &Index{
+ Entries: []*Entry{
+ {Name: "foo/bar/bar", Size: 42},
+ {Name: "foo/baz/qux", Size: 42},
+ {Name: "fux", Size: 82},
+ },
+ }
+
+ m, err := idx.Glob(filepath.Join("foo", "b*"))
+ c.Assert(err, IsNil)
+ c.Assert(m, HasLen, 2)
+ c.Assert(m[0].Name, Equals, "foo/bar/bar")
+ c.Assert(m[1].Name, Equals, "foo/baz/qux")
+
+ m, err = idx.Glob("f*")
+ c.Assert(err, IsNil)
+ c.Assert(m, HasLen, 3)
+
+ m, err = idx.Glob("f*/baz/q*")
+ c.Assert(err, IsNil)
+ c.Assert(m, HasLen, 1)
+}