aboutsummaryrefslogtreecommitdiffstats
path: root/core/reference_test.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2016-08-15 23:09:33 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2016-08-15 23:09:33 +0200
commit6b9a59be60de5b66aee14e9160ace80734008eca (patch)
treec302776360b0fd4f774f67f177870fda478b4258 /core/reference_test.go
parented2e3b299e03e4bfd4c37bf5232e9fde05c0600d (diff)
downloadgo-git-6b9a59be60de5b66aee14e9160ace80734008eca.tar.gz
core: *Iter.ForEach method
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)
+}