You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2016/08/03 22:49:33 UTC

groovy git commit: GROOVY-5936: provide an iterator backed implementation for Iterator DGM dropRight rather than convert to a list (additional test)

Repository: groovy
Updated Branches:
  refs/heads/master 4a3dce9f1 -> 85cf8bc5f


GROOVY-5936: provide an iterator backed implementation for Iterator DGM dropRight rather than convert to a list (additional test)


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/85cf8bc5
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/85cf8bc5
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/85cf8bc5

Branch: refs/heads/master
Commit: 85cf8bc5f5d73209ec10b123a89a867592bd0cf4
Parents: 4a3dce9
Author: paulk <pa...@asert.com.au>
Authored: Thu Aug 4 08:49:21 2016 +1000
Committer: paulk <pa...@asert.com.au>
Committed: Thu Aug 4 08:49:21 2016 +1000

----------------------------------------------------------------------
 src/test/groovy/GroovyMethodsTest.groovy | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/85cf8bc5/src/test/groovy/GroovyMethodsTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/GroovyMethodsTest.groovy b/src/test/groovy/GroovyMethodsTest.groovy
index 267f4d1..7c0a39f 100644
--- a/src/test/groovy/GroovyMethodsTest.groovy
+++ b/src/test/groovy/GroovyMethodsTest.groovy
@@ -1285,6 +1285,9 @@ class GroovyMethodsTest extends GroovyTestCase {
         assert items.dropRight( 4 ).collect { it } == [ 1 ]
         a = 1
         assert items.dropRight( 5 ).collect { it } == []
+
+        // if we ever traverse the whole exploding list we'll get a RuntimeException
+        assert new ExplodingList('letters'.toList(), 4).iterator().dropRight(1).drop(1).take(1).toList() == ['e']
     }
 
     void testIterableDrop() {
@@ -1823,4 +1826,28 @@ class Things implements Iterable<String> {
     }
 }
 
+class ExplodingList extends ArrayList {
+    final int num
+
+    ExplodingList(List orig, int num) {
+        super(orig)
+        this.num = num
+    }
+
+    def get(int index) {
+        if (index == num) {
+            throw new RuntimeException("Explode!")
+        }
+        super.get(index)
+    }
+
+    Iterator iterator() {
+        int cursor = 0
+        new Iterator() {
+            boolean hasNext() { cursor < ExplodingList.this.size() }
+            def next() { ExplodingList.this.get(cursor++) }
+        }
+    }
+}
+
 enum Suit { HEARTS, CLUBS, SPADES, DIAMONDS }