Skip to content

Commit

Permalink
Make test case match exhaustive
Browse files Browse the repository at this point in the history
  • Loading branch information
raquo committed Nov 16, 2024
1 parent 012b34d commit 8661acb
Showing 1 changed file with 115 additions and 108 deletions.
223 changes: 115 additions & 108 deletions src/test/scala-3/com/raquo/airstream/split/SplitMatchOneSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class SplitMatchOneSpec extends UnitSpec {
case object Tar extends Foo

final case class Res(result: Any)

it("split match signal") {
val effects = mutable.Buffer[Effect[String]]()

Expand Down Expand Up @@ -65,7 +65,7 @@ class SplitMatchOneSpec extends UnitSpec {
Res("Tar")
}
.toSignal

signal.foreach { result =>
effects += Effect("result", result.toString)
}(owner)
Expand Down Expand Up @@ -163,6 +163,7 @@ class SplitMatchOneSpec extends UnitSpec {

val owner = new TestableOwner

// #TODO[Test] How to confirm exhaustiveness warning without having it printed to the test output?
// This should warn "match may not be exhaustive" with mising cases, and some idea can also flag it
val signal = myVar.signal
.splitMatchOne
Expand Down Expand Up @@ -199,7 +200,7 @@ class SplitMatchOneSpec extends UnitSpec {
Res("Tar")
}
.toSignal

signal.foreach { result =>
effects += Effect("result", result.toString)
}(owner)
Expand Down Expand Up @@ -251,7 +252,7 @@ class SplitMatchOneSpec extends UnitSpec {
)

effects.clear()

}

it("split match stream") {
Expand Down Expand Up @@ -297,7 +298,7 @@ class SplitMatchOneSpec extends UnitSpec {
Res("Tar")
}
.toStream

stream.foreach { result =>
effects += Effect("result", result.toString)
}(owner)
Expand Down Expand Up @@ -388,8 +389,9 @@ class SplitMatchOneSpec extends UnitSpec {

val owner = new TestableOwner

// #TODO[Test] How to confirm exhaustiveness warning without having it printed to the test output?
// This should warn "match may not be exhaustive" with mising cases, and some idea can also flag it
// Compiler only flag the first warning in some case, so it's best to comment out first warning test for this to flag the warning
// #Note Compiler only flag the first warning in some case, so it's best to comment out first warning test for this to flag the warning
val stream = myEventBus.events
.splitMatchOne
.handleCase {
Expand All @@ -415,7 +417,7 @@ class SplitMatchOneSpec extends UnitSpec {
Res("Baz")
}
.toStream

stream.foreach { result =>
effects += Effect("result", result.toString)
}(owner)
Expand Down Expand Up @@ -473,111 +475,116 @@ class SplitMatchOneSpec extends UnitSpec {

it("100 cases can be compiled") {
val myVar = Var[Foo](Bar(Some("initial")))
def cond(str: String): Boolean = true // Only purpose is to avoid 100x "unreachable case" warnings
val signal = myVar.signal
.splitMatchOne
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) if cond(str) => str } { (str, strSignal) => () }
.handleCase { case Bar(Some(str)) => str } { (str, strSignal) => () }
.handleCase { case Bar(None) => "Bar(None)" } { (str, strSignal) => () }
.handleCase { case Baz.Baz1 => "Baz1" } { (str, strSignal) => () }
.handleCase { case Baz.Baz2 => "Baz2" } { (str, strSignal) => () }
.handleCase { case Tar => "Tar" } { (str, strSignal) => () }
.toSignal

succeed
succeed
}

}

0 comments on commit 8661acb

Please sign in to comment.