Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions streams-tests/shared/src/test/scala/zio/stream/ZStreamSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ object ZStreamSpec extends ZIOBaseSpec {
def inParallel(action: => Unit)(implicit ec: ExecutionContext): Unit =
ec.execute(() => action)

def spec =
override def spec: Spec[TestEnvironment with Scope, Any] =
suite("ZStreamSpec")(
suite("Combinators")(
suite("absolve")(
Expand Down Expand Up @@ -5621,11 +5621,32 @@ object ZStreamSpec extends ZIOBaseSpec {
_ <- ZStream.fromIterableZIO(ZIO.succeed(1 to 5000000)).runDrain
} yield assertCompletes
},
test("fromIterator") {
check(Gen.small(Gen.chunkOfN(_)(Gen.int)), Gen.small(Gen.const(_), 1)) { (chunk, maxChunkSize) =>
assertZIO(ZStream.fromIterator(chunk.iterator, maxChunkSize).runCollect)(equalTo(chunk))
suite("fromIterator")(
test("with values") {
check(Gen.small(Gen.chunkOfN(_)(Gen.int)), Gen.small(Gen.const(_), min = 1)) { (chunk, maxChunkSize) =>
assertZIO(ZStream.fromIterator(chunk.iterator, maxChunkSize).runCollect)(equalTo(chunk))
}
},
test("handles exceptions from making the iterator") {
check(Gen.small(Gen.const(_), min = 1)) { maxChunkSize =>
val exception = new RuntimeException("Iterator error")
def failingIterator: Iterator[Int] = throw exception

assertZIO(ZStream.fromIterator(failingIterator, maxChunkSize).runCollect.exit)(fails(equalTo(exception)))
}
},
test("handles exceptions from iterator") {
check(Gen.small(Gen.const(_), min = 1)) { maxChunkSize =>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do either of these tests need Gen?

Copy link
Member Author

@guizmaii guizmaii Jul 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic is different when maxChunkSize == 1 and maxChunkSize > 1 so it needs to test these 2 cases, which justifies the usage of Gen.

It's copied from the initial test testing fromIterator

val exception = new RuntimeException("Iterator error")
val failingIterator =
new Iterator[Int] {
def hasNext: Boolean = true
def next(): Int = throw exception
}
assertZIO(ZStream.fromIterator(failingIterator, maxChunkSize).runCollect.exit)(fails(equalTo(exception)))
}
}
},
),
test("fromIteratorSucceed") {
check(Gen.small(Gen.chunkOfN(_)(Gen.int)), Gen.small(Gen.const(_), 1)) { (chunk, maxChunkSize) =>
assertZIO(ZStream.fromIteratorSucceed(chunk.iterator, maxChunkSize).runCollect)(equalTo(chunk))
Expand Down
Loading