summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2016-02-10 12:56:14 +1000
committerJason Zaugg <jzaugg@gmail.com>2016-02-10 12:56:14 +1000
commitfca51b24115ad17a26a144b394a18471ea356155 (patch)
tree28517374ed747afa892f4bcae09e92d5d4dd20f9 /test
parentb0beb720e70cc8700a593766ad6c384e8826bf52 (diff)
parent8f8f81b72ef07140952aeb76120bd032e35cc918 (diff)
downloadscala-fca51b24115ad17a26a144b394a18471ea356155.tar.gz
scala-fca51b24115ad17a26a144b394a18471ea356155.tar.bz2
scala-fca51b24115ad17a26a144b394a18471ea356155.zip
Merge branch '2.11.x' into topic/merge-2.11.x-to-2.12.x-20160210
Conflicts: src/library/scala/collection/Iterator.scala | `-- trivial conflicts only. Parens were added to the next() calls in 2.12.x, while in the meantime `{Concat,Join}Iterator` were optimized in 2.11.x
Diffstat (limited to 'test')
-rw-r--r--test/junit/scala/collection/IteratorTest.scala28
1 files changed, 28 insertions, 0 deletions
diff --git a/test/junit/scala/collection/IteratorTest.scala b/test/junit/scala/collection/IteratorTest.scala
index b0639ef365..4df29e36c0 100644
--- a/test/junit/scala/collection/IteratorTest.scala
+++ b/test/junit/scala/collection/IteratorTest.scala
@@ -186,4 +186,32 @@ class IteratorTest {
assertEquals(1, y.next)
assertFalse(x.hasNext) // was true, after advancing underlying iterator
}
+ // SI-9623
+ @Test def noExcessiveHasNextInJoinIterator: Unit = {
+ var counter = 0
+ val exp = List(1,2,3,1,2,3)
+ def it: Iterator[Int] = new Iterator[Int] {
+ val parent = List(1,2,3).iterator
+ def next(): Int = parent.next
+ def hasNext: Boolean = { counter += 1; parent.hasNext }
+ }
+ // Iterate separately
+ val res = new mutable.ArrayBuffer[Int]
+ it.foreach(res += _)
+ it.foreach(res += _)
+ assertSameElements(exp, res)
+ assertEquals(8, counter)
+ // JoinIterator
+ counter = 0
+ res.clear
+ (it ++ it).foreach(res += _)
+ assertSameElements(exp, res)
+ assertEquals(8, counter) // was 17
+ // ConcatIterator
+ counter = 0
+ res.clear
+ (Iterator.empty ++ it ++ it).foreach(res += _)
+ assertSameElements(exp, res)
+ assertEquals(8, counter) // was 14
+ }
}