From 1bdefd451a7804a1ecfbd0673a03dcfdbe7a62c9 Mon Sep 17 00:00:00 2001 From: Uwe Reimann Date: Fri, 2 Jun 2023 17:17:31 +0200 Subject: [PATCH] Add tests for mergePreferred --- .../src/test/scala/fs2/StreamMergeSuite.scala | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/core/shared/src/test/scala/fs2/StreamMergeSuite.scala b/core/shared/src/test/scala/fs2/StreamMergeSuite.scala index 6ff3b03a1b..7aac2102ed 100644 --- a/core/shared/src/test/scala/fs2/StreamMergeSuite.scala +++ b/core/shared/src/test/scala/fs2/StreamMergeSuite.scala @@ -242,4 +242,37 @@ class StreamMergeSuite extends Fs2Suite { } } } + + test("mergePreferred prefers") { + forAllF { (leftStream: Stream[Pure, Int], rightStream: Stream[Pure, Int]) => + val leftTagged = leftStream.covary[IO] + val rightTagged = rightStream.covary[IO].delayBy(10.milli) + leftTagged + .mergePreferred(rightTagged) + .assertEmitsSameAs(leftStream ++ rightStream) + } + } + + test("mergePreferred fully consumes this") { + forAllF { stream: Stream[Pure, Int] => + stream.covary[IO].mergePreferred(Stream.empty.covary[IO]).assertEmitsSameAs(stream) + } + } + + test("mergePreferred fully consumes that") { + forAllF { stream: Stream[Pure, Int] => + Stream.empty.covary[IO].mergePreferred(stream.covary[IO]).assertEmitsSameAs(stream) + } + } + + test("mergePreferred fully consumes both") { + forAllF { (leftStream: Stream[Pure, Int], rightStream: Stream[Pure, Int]) => + val leftTagged = leftStream.covary[IO] + val rightTagged = rightStream.covary[IO] + leftTagged + .mergePreferred(rightTagged) + .assertEmitsUnorderedSameAs(leftStream ++ rightStream) + } + } + }