summaryrefslogtreecommitdiff
path: root/test/junit/scala/collection/IteratorTest.scala
diff options
context:
space:
mode:
authorRui Gonçalves <ruippeixotog@gmail.com>2015-04-04 15:03:06 +0100
committerRui Gonçalves <ruippeixotog@gmail.com>2015-04-04 15:03:06 +0100
commit065388637eb07d90a32f22a2a00de93bbb934b34 (patch)
tree4efdcdfe62f3c8e3624ad9a518bf87e0f2bde752 /test/junit/scala/collection/IteratorTest.scala
parentebf0976c363c67e6a46c66d70b39704f1ce5e74a (diff)
downloadscala-065388637eb07d90a32f22a2a00de93bbb934b34.tar.gz
scala-065388637eb07d90a32f22a2a00de93bbb934b34.tar.bz2
scala-065388637eb07d90a32f22a2a00de93bbb934b34.zip
SI-8627 Two-argument indexOf does not work for Iterator
Adds two new methods to `Iterator`, overloading `indexOf` and `indexWhere` with a two-arg version whose second argument indicates the index where to start the search. These methods were already present in instances of `GenSeqLike` but not on iterators, leading to strange behavior when two arguments were passed to `indexOf`.
Diffstat (limited to 'test/junit/scala/collection/IteratorTest.scala')
-rw-r--r--test/junit/scala/collection/IteratorTest.scala22
1 files changed, 22 insertions, 0 deletions
diff --git a/test/junit/scala/collection/IteratorTest.scala b/test/junit/scala/collection/IteratorTest.scala
index d5389afd0c..b3cd6707c1 100644
--- a/test/junit/scala/collection/IteratorTest.scala
+++ b/test/junit/scala/collection/IteratorTest.scala
@@ -135,6 +135,20 @@ class IteratorTest {
assertEquals(3, List(1, 2, 3, 4, 5).iterator.indexWhere { x: Int => x >= 4 })
assertEquals(-1, List(1, 2, 3, 4, 5).iterator.indexWhere { x: Int => x >= 16 })
}
+ @Test def indexOfFrom(): Unit = {
+ assertEquals(1, List(1, 2, 3, 4, 5).iterator.indexOf(2, 0))
+ assertEquals(1, List(1, 2, 3, 4, 5).iterator.indexOf(2, 1))
+ assertEquals(-1, List(1, 2, 3, 4, 5).iterator.indexOf(2, 2))
+ assertEquals(4, List(1, 2, 3, 2, 1).iterator.indexOf(1, 1))
+ assertEquals(1, List(1, 2, 3, 2, 1).iterator.indexOf(2, 1))
+ }
+ @Test def indexWhereFrom(): Unit = {
+ assertEquals(1, List(1, 2, 3, 4, 5).iterator.indexWhere(_ == 2, 0))
+ assertEquals(1, List(1, 2, 3, 4, 5).iterator.indexWhere(_ == 2, 1))
+ assertEquals(-1, List(1, 2, 3, 4, 5).iterator.indexWhere(_ == 2, 2))
+ assertEquals(4, List(1, 2, 3, 2, 1).iterator.indexWhere(_ < 2, 1))
+ assertEquals(1, List(1, 2, 3, 2, 1).iterator.indexWhere(_ <= 2, 1))
+ }
// iterator-iterate-lazy.scala
// was java.lang.UnsupportedOperationException: tail of empty list
@Test def iterateIsSufficientlyLazy(): Unit = {
@@ -154,4 +168,12 @@ class IteratorTest {
results += (Stream from 1).toIterator.drop(10).toStream.drop(10).toIterator.next()
assertSameElements(List(1,1,21), results)
}
+ // SI-8552
+ @Test def indexOfShouldWorkForTwoParams(): Unit = {
+ assertEquals(1, List(1, 2, 3).iterator.indexOf(2, 0))
+ assertEquals(-1, List(5 -> 0).iterator.indexOf(5, 0))
+ assertEquals(0, List(5 -> 0).iterator.indexOf((5, 0)))
+ assertEquals(-1, List(5 -> 0, 9 -> 2, 0 -> 3).iterator.indexOf(9, 2))
+ assertEquals(1, List(5 -> 0, 9 -> 2, 0 -> 3).iterator.indexOf(9 -> 2))
+ }
}