Made sliding/grouped throw an exception when read past the end.
Closes #3017. git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@20777 5e8d7ff9-d8ef-0310-90f0-a4852d11357a
This commit is contained in:
parent
acea463802
commit
800326e386
|
@ -937,6 +937,8 @@ trait Iterator[+A] { self =>
|
|||
if (!filled)
|
||||
fill()
|
||||
|
||||
if (!filled)
|
||||
throw new NoSuchElementException("next on empty iterator")
|
||||
filled = false
|
||||
buffer.toList
|
||||
}
|
||||
|
|
|
@ -33,5 +33,18 @@ object Test
|
|||
assertThat(1, (1 to 8).toList) { it.sliding(8, 8) withPartial false }
|
||||
assertThat(2, List(9, 10, -1, -1, -1)) { it.sliding(5, 8) withPadding -1 }
|
||||
assertThat(1, (1 to 5).toList) { it.sliding(5, 8) withPartial false }
|
||||
|
||||
// make sure it throws past th end
|
||||
val thrown = try {
|
||||
val it = List(1,2,3).sliding(2)
|
||||
it.next
|
||||
it.next
|
||||
it.next
|
||||
false
|
||||
}
|
||||
catch {
|
||||
case _: NoSuchElementException => true
|
||||
}
|
||||
assert(thrown)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue