[libgee/0.8] Return true from HashSet.Iterator.foreach() if we fall off the end



commit 9714f844ce81af8f7a8aa78871ec3659231baef9
Author: Simon McVittie <simon mcvittie collabora co uk>
Date:   Wed Mar 27 15:49:03 2013 +0000

    Return true from HashSet.Iterator.foreach() if we fall off the end
    
    This is documented to happen, and was implemented correctly in the other
    collections, but not in HashSet.

 gee/hashset.vala          |    2 +-
 tests/testcollection.vala |   14 +++++++++++---
 2 files changed, 12 insertions(+), 4 deletions(-)
---
diff --git a/gee/hashset.vala b/gee/hashset.vala
index e8c9f26..d6f10c4 100644
--- a/gee/hashset.vala
+++ b/gee/hashset.vala
@@ -307,7 +307,7 @@ public class Gee.HashSet<G> : AbstractSet<G> {
                                        _next = _set._nodes[_index];
                                }
                        }
-                       return false;
+                       return true;
                }
        }
 }
diff --git a/tests/testcollection.vala b/tests/testcollection.vala
index 2c0050a..c1774ce 100644
--- a/tests/testcollection.vala
+++ b/tests/testcollection.vala
@@ -770,17 +770,25 @@ public abstract class CollectionTests : Gee.TestCase {
                assert (test_collection.add ("three"));
                
                int count = 0;
+               bool res;
                
-               test_collection.foreach ((x) => {count++; return true;});
+               res = test_collection.foreach ((x) => {count++; return true;});
                assert (count == 3);
+               assert (res == true);
                
-               test_collection.iterator ().foreach ((x) => {count++; return true;});
+               res = test_collection.iterator ().foreach ((x) => {count++; return true;});
                assert (count == 6);
+               assert (res == true);
                
                Iterator<string> iter = test_collection.iterator ();
                assert (iter.next ());
-               iter.foreach ((x) => {count++; return true;});
+               res = iter.foreach ((x) => {count++; return true;});
                assert (count == 9);
+               assert (res == true);
+
+               res = test_collection.foreach ((x) => {count++; return false;});
+               assert (count == 10);
+               assert (res == false);
        }
 
        public void test_map () {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]