Skip to content
This repository has been archived by the owner on Sep 7, 2024. It is now read-only.

Commit

Permalink
[Improved] Better coverage for new json implementation
Browse files Browse the repository at this point in the history
Signed-off-by: amannocci <[email protected]>
  • Loading branch information
amannocci committed Jul 8, 2019
1 parent 8257264 commit 6775a70
Showing 1 changed file with 43 additions and 6 deletions.
49 changes: 43 additions & 6 deletions core/src/test/scala/io/techcode/streamy/util/json/JsonSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,35 @@ class JsonSpec extends WordSpecLike with Matchers {
}
}

"Json number" should {
"stringify float correctly" in {
JsFloat(1.0F).toString should equal("1.0")
}

"map json number correctly" in {
JsFloat(10F).map[JsNumber](_ => JsNull) should equal(JsNull)
JsNull.map[Float](_ => JsNull) should equal(JsUndefined)
}

"flatMap json number correctly" in {
JsFloat(10F).flatMap[JsNumber](_ => JsNull) should equal(JsNull)
JsNull.flatMap[Float](_ => JsNull) should equal(JsUndefined)
}

"get json number correctly" in {
JsFloat(10F).get[JsNumber] should equal(JsFloat(10F))
}

"getOrElse json number correctly" in {
JsFloat(10F).getOrElse[JsNumber](JsFloat(0F)) should equal(JsFloat(10F))
JsNull.getOrElse[JsNumber](JsFloat(0F)) should equal(JsFloat(0F))
}

"be identified as number" in {
JsFloat(0F).isNumber should equal(true)
}
}

"Json float" should {
"stringify float correctly" in {
JsFloat(1.0F).toString should equal("1.0")
Expand All @@ -535,11 +564,6 @@ class JsonSpec extends WordSpecLike with Matchers {
JsNull.map[Float](_ => JsNull) should equal(JsUndefined)
}

"map json double correctly" in {
JsDouble(10D).map[Double](_ => JsNull) should equal(JsNull)
JsNull.map[Double](_ => JsNull) should equal(JsUndefined)
}

"return float conversion for big decimal" in {
JsBigDecimal(BigDecimal(6.0F)).toFloat should equal(6.0F)
}
Expand Down Expand Up @@ -582,6 +606,11 @@ class JsonSpec extends WordSpecLike with Matchers {
JsDouble(1.0D).toString should equal("1.0")
}

"map json double correctly" in {
JsDouble(10D).map[Double](_ => JsNull) should equal(JsNull)
JsNull.map[Double](_ => JsNull) should equal(JsUndefined)
}

"return correct size for double" in {
JsDouble(2.0D).sizeHint should equal(3)
}
Expand Down Expand Up @@ -773,6 +802,14 @@ class JsonSpec extends WordSpecLike with Matchers {
}

"Json boolean" should {
"get boolean correctly" in {
JsTrue.get[Boolean] should equal(true)
JsFalse.get[Boolean] should equal(false)
assertThrows[ClassCastException] {
JsNull.get[Boolean]
}
}

"return correct size for boolean" in {
JsTrue.sizeHint should equal(4)
JsFalse.sizeHint should equal(5)
Expand Down Expand Up @@ -988,7 +1025,7 @@ class JsonSpec extends WordSpecLike with Matchers {

"getOrElse json correctly" in {
JsLong(1330950829160L).getOrElse[Json](JsNull) should equal(JsLong(1330950829160L))
JsNull.getOrElse[Json](JsNull) should equal(JsNull)
JsUndefined.getOrElse[Json](JsNull) should equal(JsNull)
}

"getOrElse json array correctly" in {
Expand Down

0 comments on commit 6775a70

Please sign in to comment.