-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1844aa4
commit b0bb1bc
Showing
2 changed files
with
98 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
core/src/test/scala/ox/channels/SourceOpsMapConcatTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package ox.channels | ||
|
||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.should.Matchers | ||
import ox.* | ||
|
||
class SourceOpsMapConcatTest extends AnyFlatSpec with Matchers { | ||
|
||
behavior of "Source.mapConcat" | ||
|
||
it should "unfold iterables" in supervised { | ||
val c = Source.fromValues(List("a", "b", "c"), List("d", "e"), List("f")) | ||
val s = c.mapConcat(identity) | ||
s.toList shouldBe List("a", "b", "c", "d", "e", "f") | ||
} | ||
|
||
it should "transform elements" in supervised { | ||
val c = Source.fromValues("ab", "cd") | ||
val s = c.mapConcat { str => str.toList } | ||
|
||
s.toList shouldBe List('a', 'b', 'c', 'd') | ||
} | ||
|
||
it should "handle empty lists" in supervised { | ||
val c = Source.fromValues(List.empty, List("a"), List.empty, List("b", "c")) | ||
val s = c.mapConcat(identity) | ||
|
||
s.toList shouldBe List("a", "b", "c") | ||
} | ||
|
||
it should "propagate errors in the mapping function" in supervised { | ||
// given | ||
given StageCapacity = StageCapacity(0) // so that the error isn't created too early | ||
val c = Source.fromValues(List("a"), List("b", "c"), List("error here")) | ||
|
||
// when | ||
val s = c.mapConcat { element => | ||
if (element != List("error here")) | ||
element | ||
else throw new RuntimeException("boom") | ||
} | ||
|
||
// then | ||
s.receive() shouldBe "a" | ||
s.receive() shouldBe "b" | ||
s.receive() shouldBe "c" | ||
s.receiveSafe() should matchPattern { | ||
case ChannelClosed.Error(reason) if reason.getMessage == "boom" => | ||
} | ||
} | ||
} |