summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorSom Snytt <som.snytt@gmail.com>2015-05-27 12:07:10 -0700
committerSom Snytt <som.snytt@gmail.com>2015-05-27 12:07:10 -0700
commit5b02bb4f8993f8e09ff1223fbdd4acf78eabd964 (patch)
treed336bf1633a7e63dcdc8b3370da05c1422ef6ddc /test
parent15ca0b31afecfa24686c7a650f550ba5fcac1f03 (diff)
downloadscala-5b02bb4f8993f8e09ff1223fbdd4acf78eabd964.tar.gz
scala-5b02bb4f8993f8e09ff1223fbdd4acf78eabd964.tar.bz2
scala-5b02bb4f8993f8e09ff1223fbdd4acf78eabd964.zip
SI-9332 Iterator.span exhausts leading iterator
Since the leading and trailing iterators returned by span share the underlying iterator, the leading iterator must flag when it is exhausted (when the span predicate fails) since the trailing iterator will advance the underlying iterator. It would also be possible to leave the failing element in the leading lookahead buffer, where it would forever fail the predicate, but that entails evaluating the predicate twice, on both enqueue and dequeue.
Diffstat (limited to 'test')
-rw-r--r--test/junit/scala/collection/IteratorTest.scala10
1 files changed, 10 insertions, 0 deletions
diff --git a/test/junit/scala/collection/IteratorTest.scala b/test/junit/scala/collection/IteratorTest.scala
index d5389afd0c..1c1e50aed9 100644
--- a/test/junit/scala/collection/IteratorTest.scala
+++ b/test/junit/scala/collection/IteratorTest.scala
@@ -154,4 +154,14 @@ class IteratorTest {
results += (Stream from 1).toIterator.drop(10).toStream.drop(10).toIterator.next()
assertSameElements(List(1,1,21), results)
}
+ // SI-9332
+ @Test def spanExhaustsLeadingIterator(): Unit = {
+ def it = Iterator.iterate(0)(_ + 1).take(6)
+ val (x, y) = it.span(_ != 1)
+ val z = x.toList
+ assertEquals(1, z.size)
+ assertFalse(x.hasNext)
+ assertEquals(1, y.next)
+ assertFalse(x.hasNext) // was true, after advancing underlying iterator
+ }
}