aboutsummaryrefslogtreecommitdiffstats
path: root/core/reference_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'core/reference_test.go')
-rw-r--r--core/reference_test.go61
1 files changed, 60 insertions, 1 deletions
diff --git a/core/reference_test.go b/core/reference_test.go
index 5d88f0e..3739a15 100644
--- a/core/reference_test.go
+++ b/core/reference_test.go
@@ -1,6 +1,10 @@
package core
-import . "gopkg.in/check.v1"
+import (
+ "io"
+
+ . "gopkg.in/check.v1"
+)
type ReferenceSuite struct{}
@@ -62,3 +66,58 @@ func (s *ReferenceSuite) TestIsTag(c *C) {
r := NewHashReference(ReferenceName("refs/tags/v3.1."), ZeroHash)
c.Assert(r.IsTag(), Equals, true)
}
+
+func (s *ReferenceSuite) TestReferenceSliceIterNext(c *C) {
+ slice := []*Reference{
+ NewReferenceFromStrings("foo", "foo"),
+ NewReferenceFromStrings("bar", "bar"),
+ }
+
+ i := NewReferenceSliceIter(slice)
+ foo, err := i.Next()
+ c.Assert(err, IsNil)
+ c.Assert(foo == slice[0], Equals, true)
+
+ bar, err := i.Next()
+ c.Assert(err, IsNil)
+ c.Assert(bar == slice[1], Equals, true)
+
+ empty, err := i.Next()
+ c.Assert(err, Equals, io.EOF)
+ c.Assert(empty, IsNil)
+}
+
+func (s *ReferenceSuite) TestReferenceSliceIterForEach(c *C) {
+ slice := []*Reference{
+ NewReferenceFromStrings("foo", "foo"),
+ NewReferenceFromStrings("bar", "bar"),
+ }
+
+ i := NewReferenceSliceIter(slice)
+ var count int
+ i.ForEach(func(r *Reference) error {
+ c.Assert(r == slice[count], Equals, true)
+ count++
+ return nil
+ })
+
+ c.Assert(count, Equals, 2)
+}
+
+func (s *ReferenceSuite) TestReferenceSliceIterForEachStop(c *C) {
+ slice := []*Reference{
+ NewReferenceFromStrings("foo", "foo"),
+ NewReferenceFromStrings("bar", "bar"),
+ }
+
+ i := NewReferenceSliceIter(slice)
+
+ var count int
+ i.ForEach(func(r *Reference) error {
+ c.Assert(r == slice[count], Equals, true)
+ count++
+ return ErrStop
+ })
+
+ c.Assert(count, Equals, 1)
+}