Skip to content

Commit

Permalink
Fix Bool pattern matching to be exhaustive (#461)
Browse files Browse the repository at this point in the history
Fixes #456
  • Loading branch information
lolgab authored Mar 12, 2023
1 parent 0724f89 commit 7e469da
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ujson/src/ujson/Value.scala
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ sealed abstract class Bool extends Value{
}
object Bool{
def apply(value: Boolean): Bool = if (value) True else False
def unapply(bool: Bool): Option[Boolean] = Some(bool.value)
def unapply(bool: Bool): Some[Boolean] = Some(bool.value)
}
case object False extends Bool{
def value = false
Expand Down
5 changes: 5 additions & 0 deletions ujson/test/src/ujson/BoolTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,10 @@ object BoolTests extends TestSuite {
}
}
}
test("ujson.Bool pattern matching should be exhaustive") {
ujson.Bool(true) match {
case ujson.Bool(value) =>
}
}
}
}
2 changes: 1 addition & 1 deletion upack/src/upack/Msg.scala
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ sealed abstract class Bool extends Msg{
}
object Bool{
def apply(value: Boolean): Bool = if (value) True else False
def unapply(bool: Bool): Option[Boolean] = Some(bool.value)
def unapply(bool: Bool): Some[Boolean] = Some(bool.value)
}

object Msg extends MsgVisitor[Msg, Msg]{
Expand Down
32 changes: 32 additions & 0 deletions upack/test/src/upack/BoolTests.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package upack

import utest._

object BoolTests extends TestSuite {
def tests = Tests{
test("upack.Bool apply") {
upack.Bool(true) ==> upack.True
upack.Bool(false) ==> upack.False
}

test("upack.Bool.value") {
upack.Bool(true).value ==> true
upack.Bool(false).value ==> false
}
test("upack.Bool unapply") {
for(bool <- Seq(true, false)){
val jsb = upack.Bool(bool)
assertMatch(jsb) {
case upack.Bool(value)
if value == bool
&& jsb.value == value =>
}
}
}
test("upack.Bool pattern matching should be exhaustive") {
upack.Bool(true) match {
case upack.Bool(value) =>
}
}
}
}

0 comments on commit 7e469da

Please sign in to comment.