diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs new file mode 100644 index 00000000..9a1ba689 --- /dev/null +++ b/.git-blame-ignore-revs @@ -0,0 +1,2 @@ +# Scala Steward: Reformat with scalafmt 3.8.5 +974cc9929319d574e3495a61af47f636aa824db6 diff --git a/.scalafmt.conf b/.scalafmt.conf index 719c6e47..37bc0f87 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -1,4 +1,4 @@ -version = 3.8.3 +version = 3.8.5 runner.dialect = scala213 diff --git a/json/json-core/src/test/scala/io/sphere/json/JodaJavaLocalDateCompatSpec.scala b/json/json-core/src/test/scala/io/sphere/json/JodaJavaLocalDateCompatSpec.scala index f8295527..1b49c7a0 100644 --- a/json/json-core/src/test/scala/io/sphere/json/JodaJavaLocalDateCompatSpec.scala +++ b/json/json-core/src/test/scala/io/sphere/json/JodaJavaLocalDateCompatSpec.scala @@ -26,26 +26,20 @@ class JodaJavaLocalDateCompatSpec extends AnyWordSpec with Matchers { } "parsing a LocalDate" should { - "accept two digit years" in { + "accept two digit years" in test(jsonDateStringWith(year = "50")) - } - "accept year zero" in { + "accept year zero" in test(JString("0-10-31")) - } - "accept no day set" in { + "accept no day set" in test(JString("2024-09")) - } - "accept up to nine digit years" in { + "accept up to nine digit years" in (1 to 9).foreach { l => val year = List.fill(l)("1").mkString("") test(jsonDateStringWith(year = year)) } - } - "accept a year with leading zero" in { + "accept a year with leading zero" in test(jsonDateStringWith(year = "02020")) - } - "accept a year with leading plus sign" in { + "accept a year with leading plus sign" in test(jsonDateStringWith(year = "+02020")) - } } } diff --git a/mongo/mongo-core/src/test/scala/io/sphere/mongo/format/DefaultMongoFormatsTest.scala b/mongo/mongo-core/src/test/scala/io/sphere/mongo/format/DefaultMongoFormatsTest.scala index 15d3673b..3d2ab62e 100644 --- a/mongo/mongo-core/src/test/scala/io/sphere/mongo/format/DefaultMongoFormatsTest.scala +++ b/mongo/mongo-core/src/test/scala/io/sphere/mongo/format/DefaultMongoFormatsTest.scala @@ -125,12 +125,11 @@ class DefaultMongoFormatsTest check(map, format) } - "support Java Locale" in { + "support Java Locale" in Locale.getAvailableLocales.filter(_.toLanguageTag != LangTag.UNDEFINED).foreach { l: Locale => localeFormat.fromMongoValue(localeFormat.toMongoValue(l)).toLanguageTag must be( l.toLanguageTag) } - } "support UUID" in { val format = uuidFormat diff --git a/mongo/mongo-derivation/src/test/scala/io/sphere/mongo/generic/SumTypesDerivingSpec.scala b/mongo/mongo-derivation/src/test/scala/io/sphere/mongo/generic/SumTypesDerivingSpec.scala index 3a4bb47d..4356b0b4 100644 --- a/mongo/mongo-derivation/src/test/scala/io/sphere/mongo/generic/SumTypesDerivingSpec.scala +++ b/mongo/mongo-derivation/src/test/scala/io/sphere/mongo/generic/SumTypesDerivingSpec.scala @@ -47,9 +47,8 @@ class SumTypesDerivingSpec extends AnyWordSpec with Matchers { "deriveMongoFormat[Color6]" mustNot compile } - "use intermediate level" in { + "use intermediate level" in Color7.format - } "do not use sealed trait info when using a case class directly" in { check(Color8.format, Color8.Custom("2356"), dbObj("type" -> "Custom", "rgb" -> "2356")) diff --git a/project/Fmpp.scala b/project/Fmpp.scala index 31b41844..0f32b272 100644 --- a/project/Fmpp.scala +++ b/project/Fmpp.scala @@ -11,7 +11,7 @@ import java.io.File object Fmpp { private lazy val fmpp = TaskKey[Seq[File]]("fmpp") private lazy val fmppOptions = SettingKey[Seq[String]]("fmppOptions") - private lazy val FmppConfig = config("fmpp") hide + private lazy val FmppConfig = config("fmpp").hide lazy val settings = fmppConfigSettings(Compile) ++ Seq( libraryDependencies += "net.sourceforge.fmpp" % "fmpp" % "0.9.16" % FmppConfig.name, diff --git a/util/src/test/scala/HighPrecisionMoneySpec.scala b/util/src/test/scala/HighPrecisionMoneySpec.scala index e8a539b2..d6dd183d 100644 --- a/util/src/test/scala/HighPrecisionMoneySpec.scala +++ b/util/src/test/scala/HighPrecisionMoneySpec.scala @@ -47,9 +47,8 @@ class HighPrecisionMoneySpec extends AnyFunSpec with Matchers with ScalaCheckDri } it("should throw error on overflow in the unary '-' operator.") { - a[MoneyOverflowException] must be thrownBy { + a[MoneyOverflowException] must be thrownBy -(BigDecimal(Long.MinValue) / 1000).EUR_PRECISE(3) - } } it("should support the binary '+' operator.") { @@ -67,9 +66,8 @@ class HighPrecisionMoneySpec extends AnyFunSpec with Matchers with ScalaCheckDri } it("should throw error on overflow in the binary '+' operator.") { - a[MoneyOverflowException] must be thrownBy { + a[MoneyOverflowException] must be thrownBy (BigDecimal(Long.MaxValue) / 1000).EUR_PRECISE(3) + 1 - } } it("should support the binary '-' operator.") { @@ -87,9 +85,8 @@ class HighPrecisionMoneySpec extends AnyFunSpec with Matchers with ScalaCheckDri } it("should throw error on overflow in the binary '-' operator.") { - a[MoneyOverflowException] must be thrownBy { + a[MoneyOverflowException] must be thrownBy (BigDecimal(Long.MinValue) / 1000).EUR_PRECISE(3) - 1 - } } it("should support the binary '*' operator.") { @@ -107,9 +104,8 @@ class HighPrecisionMoneySpec extends AnyFunSpec with Matchers with ScalaCheckDri } it("should throw error on overflow in the binary '*' operator.") { - a[MoneyOverflowException] must be thrownBy { + a[MoneyOverflowException] must be thrownBy (BigDecimal(Long.MaxValue / 1000) / 2 + 1).EUR_PRECISE(3) * 2 - } } it("should support the binary '%' operator.") { @@ -127,9 +123,8 @@ class HighPrecisionMoneySpec extends AnyFunSpec with Matchers with ScalaCheckDri } it("should throw error on overflow in the binary '%' operator.") { - noException must be thrownBy { + noException must be thrownBy BigDecimal(Long.MaxValue / 1000).EUR_PRECISE(3) % 0.5 - } } it("should support the binary '/%' operator.") { @@ -139,9 +134,8 @@ class HighPrecisionMoneySpec extends AnyFunSpec with Matchers with ScalaCheckDri } it("should throw error on overflow in the binary '/%' operator.") { - a[MoneyOverflowException] must be thrownBy { + a[MoneyOverflowException] must be thrownBy BigDecimal(Long.MaxValue / 1000).EUR_PRECISE(3) /% 0.5 - } } it("should support the remainder operator.") { @@ -151,9 +145,8 @@ class HighPrecisionMoneySpec extends AnyFunSpec with Matchers with ScalaCheckDri } it("should not overflow when getting the remainder of a division ('%').") { - noException must be thrownBy { + noException must be thrownBy BigDecimal(Long.MaxValue / 1000).EUR_PRECISE(3).remainder(0.5) - } } it("should partition the value properly.") { diff --git a/util/src/test/scala/MoneySpec.scala b/util/src/test/scala/MoneySpec.scala index 718d6e19..2cc7ffa8 100644 --- a/util/src/test/scala/MoneySpec.scala +++ b/util/src/test/scala/MoneySpec.scala @@ -16,140 +16,132 @@ class MoneySpec extends AnyFunSpec with Matchers with ScalaCheckDrivenPropertyCh describe("Money") { it("should have value semantics.") { - (1.23 EUR) must equal(1.23 EUR) + (1.23.EUR) must equal(1.23.EUR) } it( "should default to HALF_EVEN rounding mode when using monetary notation and use provided rounding mode when performing operations.") { implicit val mode = BigDecimal.RoundingMode.HALF_EVEN - (1.001 EUR) must equal(1.00 EUR) - (1.005 EUR) must equal(1.00 EUR) - (1.015 EUR) must equal(1.02 EUR) - ((1.00 EUR) + 0.001) must equal(1.00 EUR) - ((1.00 EUR) + 0.005) must equal(1.00 EUR) - ((1.00 EUR) + 0.015) must equal(1.02 EUR) - ((1.00 EUR) - 0.005) must equal(1.00 EUR) - ((1.00 EUR) - 0.015) must equal(0.98 EUR) - ((1.00 EUR) + 0.0115) must equal(1.01 EUR) + (1.001.EUR) must equal(1.00.EUR) + (1.005.EUR) must equal(1.00.EUR) + (1.015.EUR) must equal(1.02.EUR) + ((1.00.EUR) + 0.001) must equal(1.00.EUR) + ((1.00.EUR) + 0.005) must equal(1.00.EUR) + ((1.00.EUR) + 0.015) must equal(1.02.EUR) + ((1.00.EUR) - 0.005) must equal(1.00.EUR) + ((1.00.EUR) - 0.015) must equal(0.98.EUR) + ((1.00.EUR) + 0.0115) must equal(1.01.EUR) } it( "should not accept an amount with an invalid scale for the used currency when using the constructor directly.") { - an[IllegalArgumentException] must be thrownBy { + an[IllegalArgumentException] must be thrownBy Money(1.0001, java.util.Currency.getInstance("EUR")) - } } it("should not be prone to common rounding errors known from floating point numbers.") { - var m = 0.00 EUR + var m = 0.00.EUR for (i <- 1 to 10) m = m + 0.10 - m must equal(1.00 EUR) + m must equal(1.00.EUR) } it("should support the unary '-' operator.") { - -EUR(1.00) must equal(-1.00 EUR) + -EUR(1.00) must equal(-1.00.EUR) } it("should throw error on overflow in the unary '-' operator.") { - a[MoneyOverflowException] must be thrownBy { + a[MoneyOverflowException] must be thrownBy -euroCents(Long.MinValue) - } } it("should support the binary '+' operator.") { - (1.42 EUR) + (1.58 EUR) must equal(3.00 EUR) + (1.42.EUR) + (1.58.EUR) must equal(3.00.EUR) } it("should support the binary '+' operator on different currencies.") { - an[IllegalArgumentException] must be thrownBy { - (1.42 EUR) + (1.58 USD) - } + an[IllegalArgumentException] must be thrownBy + (1.42.EUR) + (1.58.USD) } it("should throw error on overflow in the binary '+' operator.") { - a[MoneyOverflowException] must be thrownBy { + a[MoneyOverflowException] must be thrownBy euroCents(Long.MaxValue) + 1 - } } it("should support the binary '-' operator.") { - (1.33 EUR) - (0.33 EUR) must equal(1.00 EUR) + (1.33.EUR) - (0.33.EUR) must equal(1.00.EUR) } it("should throw error on overflow in the binary '-' operator.") { - a[MoneyOverflowException] must be thrownBy { + a[MoneyOverflowException] must be thrownBy euroCents(Long.MinValue) - 1 - } } it("should support the binary '*' operator, requiring a rounding mode.") { implicit val mode = BigDecimal.RoundingMode.HALF_EVEN - (1.33 EUR) * (1.33 EUR) must equal(1.77 EUR) + (1.33.EUR) * (1.33.EUR) must equal(1.77.EUR) } it("should throw error on overflow in the binary '*' operator.") { - a[MoneyOverflowException] must be thrownBy { + a[MoneyOverflowException] must be thrownBy euroCents(Long.MaxValue / 2 + 1) * 2 - } } it("should support the binary '/%' (divideAndRemainder) operator.") { implicit val mode = BigDecimal.RoundingMode.HALF_EVEN - (1.33 EUR) /% 0.3 must equal(4.00 EUR, 0.13 EUR) - (1.33 EUR) /% 0.003 must equal(443.00 EUR, 0.00 EUR) + (1.33.EUR) /% 0.3 must equal(4.00.EUR, 0.13.EUR) + (1.33.EUR) /% 0.003 must equal(443.00.EUR, 0.00.EUR) } it("should throw error on overflow in the binary '/%' (divideAndRemainder) operator.") { - a[MoneyOverflowException] must be thrownBy { + a[MoneyOverflowException] must be thrownBy euroCents(Long.MaxValue) /% 0.5 - } } it("should support getting the remainder of a division ('%').") { implicit val mode = BigDecimal.RoundingMode.HALF_EVEN - (1.25 EUR).remainder(1.1) must equal(0.15 EUR) - (1.25 EUR) % 1.1 must equal(0.15 EUR) + 1.25.EUR.remainder(1.1) must equal(0.15.EUR) + (1.25.EUR) % 1.1 must equal(0.15.EUR) } it("should not overflow when getting the remainder of a division ('%').") { - noException must be thrownBy { + noException must be thrownBy euroCents(Long.MaxValue).remainder(0.5) - } } it("should support partitioning an amount without losing or gaining money.") { - (0.05 EUR).partition(3, 7) must equal(Seq(0.02 EUR, 0.03 EUR)) - (10 EUR).partition(1, 2) must equal(Seq(3.34 EUR, 6.66 EUR)) - (10 EUR).partition(3, 1, 3) must equal(Seq(4.29 EUR, 1.43 EUR, 4.28 EUR)) + 0.05.EUR.partition(3, 7) must equal(Seq(0.02.EUR, 0.03.EUR)) + 10.EUR.partition(1, 2) must equal(Seq(3.34.EUR, 6.66.EUR)) + 10.EUR.partition(3, 1, 3) must equal(Seq(4.29.EUR, 1.43.EUR, 4.28.EUR)) } it("should allow comparing money with the same currency.") { - ((1.10 EUR) > (1.00 EUR)) must be(true) - ((1.00 EUR) >= (1.00 EUR)) must be(true) - ((1.00 EUR) < (1.10 EUR)) must be(true) - ((1.00 EUR) <= (1.00 EUR)) must be(true) + ((1.10.EUR) > (1.00.EUR)) must be(true) + ((1.00.EUR) >= (1.00.EUR)) must be(true) + ((1.00.EUR) < (1.10.EUR)) must be(true) + ((1.00.EUR) <= (1.00.EUR)) must be(true) } it("should support currencies with a scale of 0 (i.e. Japanese Yen)") { - (1 JPY) must equal(1 JPY) + (1.JPY) must equal(1.JPY) } it("should be able to update the centAmount") { - (1.10 EUR).withCentAmount(170) must be(1.70 EUR) - (1.10 EUR).withCentAmount(1711) must be(17.11 EUR) - (1 JPY).withCentAmount(34) must be(34 JPY) + 1.10.EUR.withCentAmount(170) must be(1.70.EUR) + 1.10.EUR.withCentAmount(1711) must be(17.11.EUR) + 1.JPY.withCentAmount(34) must be(34.JPY) } it("should provide convenient toString") { - (1 JPY).toString must be("1 JPY") - (1.00 EUR).toString must be("1.00 EUR") - (0.10 EUR).toString must be("0.10 EUR") - (0.01 EUR).toString must be("0.01 EUR") - (0.00 EUR).toString must be("0.00 EUR") - (94.5 EUR).toString must be("94.50 EUR") + 1.JPY.toString must be("1 JPY") + 1.00.EUR.toString must be("1.00 EUR") + 0.10.EUR.toString must be("0.10 EUR") + 0.01.EUR.toString must be("0.01 EUR") + 0.00.EUR.toString must be("0.00 EUR") + 94.5.EUR.toString must be("94.50 EUR") } it("should not fail on toString") {