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



commit dd1449c61fb5ea1e25ada35ec13504c199440513
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 ddb9308..090724a 100644
--- a/tests/testcollection.vala
+++ b/tests/testcollection.vala
@@ -667,17 +667,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]