Skip to content

Commit

Permalink
last tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Pawel Czajka committed Dec 17, 2024
1 parent 133a299 commit 6c25c7d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ object ToBigDecimalConversion extends ToNumericConversion[JBigDecimal] {

override def convertEither(value: Any): Either[Throwable, JBigDecimal] =
value match {
case v: JBigDecimal => Right(v)
case v: JBigDecimal => Right(v.setScale(Math.max(v.scale(), NumberUtilsConsts.DEFAULT_BIG_DECIMAL_SCALE)))
case v: JBigInteger => Right(new JBigDecimal(v).setScale(NumberUtilsConsts.DEFAULT_BIG_DECIMAL_SCALE))
case v: Number => Try(NumberUtils.convertNumberToTargetClass(v, resultTypeClass)).toEither
case v: String =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,11 +364,26 @@ class SpelExpressionSpec extends AnyFunSuite with Matchers with ValidatedValuesD
BigDecimal(result.asInstanceOf[java.math.BigDecimal]) shouldBe BigDecimal(0.5) +- BigDecimal(0.001)
}

test("should set scale at least 18 when creating big double") {
test("should set scale at least default when creating big decimal from int") {
val result = evaluate[Any]("""(1).toBigDecimal""".stripMargin)
result.asInstanceOf[java.math.BigDecimal].scale() shouldBe NumberUtilsConsts.DEFAULT_BIG_DECIMAL_SCALE
}

test("should set scale at least default when creating big decimal from big int") {
val result = evaluate[Any]("""#a.toBigDecimal""".stripMargin, Context("asd", Map("a" -> JBigInteger.ONE)))
result.asInstanceOf[java.math.BigDecimal].scale() shouldBe NumberUtilsConsts.DEFAULT_BIG_DECIMAL_SCALE
}

test("should set scale at least default when creating big decimal from string with low scale") {
val result = evaluate[Any]("""("1.23").toBigDecimal""".stripMargin)
result.asInstanceOf[java.math.BigDecimal].scale() shouldBe NumberUtilsConsts.DEFAULT_BIG_DECIMAL_SCALE
}

test("should set high scale when creating big decimal from string with high scale") {
val result = evaluate[Any]("""("1.345345345345345345345345345345").toBigDecimal""".stripMargin)
result.asInstanceOf[java.math.BigDecimal].scale() shouldBe 30
}

test("indexer access on unknown - array like case") {
parse[Any](
"#containerWithUnknownArray.value[0]"
Expand Down

0 comments on commit 6c25c7d

Please sign in to comment.