Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update scalafmt-core to 3.8.5 #644

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Scala Steward: Reformat with scalafmt 3.8.5
974cc9929319d574e3495a61af47f636aa824db6
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = 3.8.3
version = 3.8.5

runner.dialect = scala213

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
2 changes: 1 addition & 1 deletion project/Fmpp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
21 changes: 7 additions & 14 deletions util/src/test/scala/HighPrecisionMoneySpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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.") {
Expand All @@ -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.") {
Expand All @@ -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.") {
Expand All @@ -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.") {
Expand All @@ -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.") {
Expand All @@ -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.") {
Expand All @@ -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.") {
Expand Down
100 changes: 46 additions & 54 deletions util/src/test/scala/MoneySpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
Loading