Skip to content

Commit

Permalink
Add more assertions for parsing of big numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
plokhotnyuk committed Feb 11, 2025
1 parent 7ee179e commit 5b039c5
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions zio-json/shared/src/test/scala/zio/json/DecoderSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,20 @@ object DecoderSpec extends ZIOSpecDefault {
assertTrue("\"-Infinity\"".fromJson[BigDecimal].isLeft) &&
assertTrue("\"NaN\"".fromJson[BigDecimal].isLeft)
},
test("BigDecimal from JSON AST") {
assert("13.38885989999999992505763657391071319580078125".fromJson[Json])(
isRight(equalTo(Json.Num(BigDecimal("13.38885989999999992505763657391071319580078125"))))
)
},
test("BigDecimal too large") {
// this big integer consumes more than 256 bits
assert(
"170141183460469231731687303715884105728489465165484668486513574864654818964653168465316546851"
.fromJson[BigDecimal]
)(
isLeft(equalTo("(expected a BigDecimal with 256-bit mantissa)"))
)
},
test("BigInteger") {
assert("170141183460469231731687303715884105728".fromJson[BigInteger])(
isRight(equalTo(new BigInteger("170141183460469231731687303715884105728")))
Expand Down

0 comments on commit 5b039c5

Please sign in to comment.