From 87ef2bd56fac8d34c6fa621ec7e0d9d8d993fe6b Mon Sep 17 00:00:00 2001 From: 47erbot Date: Mon, 24 Jan 2022 05:13:40 +0000 Subject: [PATCH 1/5] Update scalafmt-core to 3.3.3 --- .scalafmt.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.scalafmt.conf b/.scalafmt.conf index 029d9cf..d0ed599 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -1,4 +1,4 @@ -version = 3.3.2 +version = 3.3.3 style = defaultWithAlign maxColumn = 100 runner.dialect = scala213 From 19c5ecfd71feb116fff05246051b7ac7c1da81d3 Mon Sep 17 00:00:00 2001 From: James Santucci Date: Thu, 27 Jan 2022 16:08:43 -0500 Subject: [PATCH 2/5] enhance clues with predicate info --- .../datetime/jdk8/GenJdk8Properties.scala | 49 +++++++++++++------ 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/modules/scalacheck-toolbox-datetime/src/test/scala/com/fortysevendeg/scalacheck/datetime/jdk8/GenJdk8Properties.scala b/modules/scalacheck-toolbox-datetime/src/test/scala/com/fortysevendeg/scalacheck/datetime/jdk8/GenJdk8Properties.scala index 54614c0..92f858e 100644 --- a/modules/scalacheck-toolbox-datetime/src/test/scala/com/fortysevendeg/scalacheck/datetime/jdk8/GenJdk8Properties.scala +++ b/modules/scalacheck-toolbox-datetime/src/test/scala/com/fortysevendeg/scalacheck/datetime/jdk8/GenJdk8Properties.scala @@ -30,6 +30,11 @@ import scala.util.Try object GenJdk8Properties extends Properties("Java 8 Generators") { + case class LabeledPredicate[T](label: String, fn: T => Boolean) + + def predicateClue[T](predicate: LabeledPredicate[T]): String = + s"Predicate label: ${predicate.label}" + // Guards against generating values well outside of expected ranges, as users may run into JDK bugs implicit val yearRange: YearRange = YearRange.between(0, 10000) @@ -63,7 +68,9 @@ object GenJdk8Properties extends Properties("Java 8 Generators") { forAll((_: Instant) => passed) } - val granularitiesAndPredicates: List[(Granularity[ZonedDateTime], ZonedDateTime => Boolean)] = { + val granularitiesAndPredicates: List[ + (Granularity[ZonedDateTime], LabeledPredicate[ZonedDateTime]) + ] = { import java.time.temporal.ChronoField._ @@ -99,24 +106,31 @@ object GenJdk8Properties extends Properties("Java 8 Generators") { timezoneSwitch(dt) || (zeroHours(dt) && dt.get(DAY_OF_YEAR) == 1) List( - (granularity.seconds, zeroNanos), - (granularity.minutes, zeroSeconds), - (granularity.hours, zeroMinutes), - (granularity.days, zeroHours), - (granularity.years, firstDay) + (granularity.seconds, LabeledPredicate[ZonedDateTime]("zero nanos", zeroNanos)), + (granularity.minutes, LabeledPredicate[ZonedDateTime]("zero seconds", zeroSeconds)), + (granularity.hours, LabeledPredicate[ZonedDateTime]("zero minutes", zeroMinutes)), + (granularity.days, LabeledPredicate[ZonedDateTime]("zero hours", zeroHours)), + (granularity.years, LabeledPredicate[ZonedDateTime]("first day", firstDay)) ) } val granularitiesAndPredicatesWithDefault: List[ - (Granularity[ZonedDateTime], ZonedDateTime => Boolean) + (Granularity[ZonedDateTime], LabeledPredicate[ZonedDateTime]) ] = - (Granularity.identity[ZonedDateTime], (_: ZonedDateTime) => true) :: granularitiesAndPredicates + ( + Granularity.identity[ZonedDateTime], + LabeledPredicate[ZonedDateTime]("identity", (_: ZonedDateTime) => true) + ) :: granularitiesAndPredicates property("genZonedDateTime with a granularity generates appropriate ZonedDateTimes") = forAll(Gen.oneOf(granularitiesAndPredicates)) { case (granularity, predicate) => implicit val generatedGranularity: Granularity[ZonedDateTime] = granularity - forAll(genZonedDateTime)(dt => predicate(dt) :| s"${granularity.description}: $dt") + forAll(genZonedDateTime)(dt => + predicate.fn( + dt + ) :| s"Granularity: ${granularity.description}; ${predicateClue(predicate)}; $dt" + ) } property("arbitrary generation with a granularity generates appropriate ZonedDateTimes") = @@ -125,7 +139,9 @@ object GenJdk8Properties extends Properties("Java 8 Generators") { implicit val generatedGranularity: Granularity[ZonedDateTime] = granularity - forAll((dt: ZonedDateTime) => predicate(dt) :| s"${granularity.description}: $dt") + forAll((dt: ZonedDateTime) => + predicate.fn(dt) :| s"${granularity.description}; ${predicateClue(predicate)}; $dt" + ) } property("arbitrary generation with a granularity generates appropriate LocalDateTimes") = @@ -135,7 +151,8 @@ object GenJdk8Properties extends Properties("Java 8 Generators") { implicit val generatedGranularity: Granularity[ZonedDateTime] = granularity forAll { (dt: LocalDateTime) => - predicate(dt.atZone(ZoneOffset.UTC)) :| s"${granularity.description}: $dt" + predicate + .fn(dt.atZone(ZoneOffset.UTC)) :| s"${granularity.description}; ${predicateClue(predicate)}; $dt" } } @@ -146,7 +163,9 @@ object GenJdk8Properties extends Properties("Java 8 Generators") { implicit val generatedGranularity: Granularity[ZonedDateTime] = granularity forAll { (dt: LocalDate) => - predicate(dt.atStartOfDay(ZoneOffset.UTC)) :| s"${granularity.description}: $dt" + predicate.fn( + dt.atStartOfDay(ZoneOffset.UTC) + ) :| s"${granularity.description}; ${predicateClue(predicate)}; $dt" } } @@ -157,7 +176,9 @@ object GenJdk8Properties extends Properties("Java 8 Generators") { implicit val generatedGranularity: Granularity[ZonedDateTime] = granularity forAll { (instant: Instant) => - predicate(instant.atZone(ZoneOffset.UTC)) :| s"${granularity.description}: $instant" + predicate.fn( + instant.atZone(ZoneOffset.UTC) + ) :| s"${granularity.description}; ${predicateClue(predicate)}; $instant" } } @@ -211,7 +232,7 @@ object GenJdk8Properties extends Properties("Java 8 Generators") { .isBefore(generated) || granularity.normalize(lowerBound).isEqual(generated)) && (upperBound.isAfter(generated) || upperBound.isEqual(generated)) - val granularityCheck = predicate(generated) + val granularityCheck = predicate.fn(generated) val prop = rangeCheck && granularityCheck From 2fc79722fb27b453b63bb07b408b1e18b754bb5b Mon Sep 17 00:00:00 2001 From: James Santucci Date: Thu, 27 Jan 2022 16:22:15 -0500 Subject: [PATCH 3/5] add a failed test to prevent auto-merge --- .../scalacheck/datetime/jdk8/GenJdk8Properties.scala | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/scalacheck-toolbox-datetime/src/test/scala/com/fortysevendeg/scalacheck/datetime/jdk8/GenJdk8Properties.scala b/modules/scalacheck-toolbox-datetime/src/test/scala/com/fortysevendeg/scalacheck/datetime/jdk8/GenJdk8Properties.scala index 92f858e..3e761ac 100644 --- a/modules/scalacheck-toolbox-datetime/src/test/scala/com/fortysevendeg/scalacheck/datetime/jdk8/GenJdk8Properties.scala +++ b/modules/scalacheck-toolbox-datetime/src/test/scala/com/fortysevendeg/scalacheck/datetime/jdk8/GenJdk8Properties.scala @@ -240,4 +240,6 @@ object GenJdk8Properties extends Properties("Java 8 Generators") { } } } + + property("fail to prevent automerge") = forAll((_: Int) => falsified) } From fca272ccb04e0a81bc60561188a1a5509dad6258 Mon Sep 17 00:00:00 2001 From: James Santucci Date: Thu, 27 Jan 2022 16:31:44 -0500 Subject: [PATCH 4/5] Revert "add a failed test to prevent auto-merge" This reverts commit 2fc79722fb27b453b63bb07b408b1e18b754bb5b. --- .../scalacheck/datetime/jdk8/GenJdk8Properties.scala | 2 -- 1 file changed, 2 deletions(-) diff --git a/modules/scalacheck-toolbox-datetime/src/test/scala/com/fortysevendeg/scalacheck/datetime/jdk8/GenJdk8Properties.scala b/modules/scalacheck-toolbox-datetime/src/test/scala/com/fortysevendeg/scalacheck/datetime/jdk8/GenJdk8Properties.scala index 3e761ac..92f858e 100644 --- a/modules/scalacheck-toolbox-datetime/src/test/scala/com/fortysevendeg/scalacheck/datetime/jdk8/GenJdk8Properties.scala +++ b/modules/scalacheck-toolbox-datetime/src/test/scala/com/fortysevendeg/scalacheck/datetime/jdk8/GenJdk8Properties.scala @@ -240,6 +240,4 @@ object GenJdk8Properties extends Properties("Java 8 Generators") { } } } - - property("fail to prevent automerge") = forAll((_: Int) => falsified) } From 920d9aa53b68b20a2ac2d9a2e507cff4391206a3 Mon Sep 17 00:00:00 2001 From: James Santucci Date: Thu, 27 Jan 2022 16:31:51 -0500 Subject: [PATCH 5/5] Revert "enhance clues with predicate info" This reverts commit 19c5ecfd71feb116fff05246051b7ac7c1da81d3. --- .../datetime/jdk8/GenJdk8Properties.scala | 49 ++++++------------- 1 file changed, 14 insertions(+), 35 deletions(-) diff --git a/modules/scalacheck-toolbox-datetime/src/test/scala/com/fortysevendeg/scalacheck/datetime/jdk8/GenJdk8Properties.scala b/modules/scalacheck-toolbox-datetime/src/test/scala/com/fortysevendeg/scalacheck/datetime/jdk8/GenJdk8Properties.scala index 92f858e..54614c0 100644 --- a/modules/scalacheck-toolbox-datetime/src/test/scala/com/fortysevendeg/scalacheck/datetime/jdk8/GenJdk8Properties.scala +++ b/modules/scalacheck-toolbox-datetime/src/test/scala/com/fortysevendeg/scalacheck/datetime/jdk8/GenJdk8Properties.scala @@ -30,11 +30,6 @@ import scala.util.Try object GenJdk8Properties extends Properties("Java 8 Generators") { - case class LabeledPredicate[T](label: String, fn: T => Boolean) - - def predicateClue[T](predicate: LabeledPredicate[T]): String = - s"Predicate label: ${predicate.label}" - // Guards against generating values well outside of expected ranges, as users may run into JDK bugs implicit val yearRange: YearRange = YearRange.between(0, 10000) @@ -68,9 +63,7 @@ object GenJdk8Properties extends Properties("Java 8 Generators") { forAll((_: Instant) => passed) } - val granularitiesAndPredicates: List[ - (Granularity[ZonedDateTime], LabeledPredicate[ZonedDateTime]) - ] = { + val granularitiesAndPredicates: List[(Granularity[ZonedDateTime], ZonedDateTime => Boolean)] = { import java.time.temporal.ChronoField._ @@ -106,31 +99,24 @@ object GenJdk8Properties extends Properties("Java 8 Generators") { timezoneSwitch(dt) || (zeroHours(dt) && dt.get(DAY_OF_YEAR) == 1) List( - (granularity.seconds, LabeledPredicate[ZonedDateTime]("zero nanos", zeroNanos)), - (granularity.minutes, LabeledPredicate[ZonedDateTime]("zero seconds", zeroSeconds)), - (granularity.hours, LabeledPredicate[ZonedDateTime]("zero minutes", zeroMinutes)), - (granularity.days, LabeledPredicate[ZonedDateTime]("zero hours", zeroHours)), - (granularity.years, LabeledPredicate[ZonedDateTime]("first day", firstDay)) + (granularity.seconds, zeroNanos), + (granularity.minutes, zeroSeconds), + (granularity.hours, zeroMinutes), + (granularity.days, zeroHours), + (granularity.years, firstDay) ) } val granularitiesAndPredicatesWithDefault: List[ - (Granularity[ZonedDateTime], LabeledPredicate[ZonedDateTime]) + (Granularity[ZonedDateTime], ZonedDateTime => Boolean) ] = - ( - Granularity.identity[ZonedDateTime], - LabeledPredicate[ZonedDateTime]("identity", (_: ZonedDateTime) => true) - ) :: granularitiesAndPredicates + (Granularity.identity[ZonedDateTime], (_: ZonedDateTime) => true) :: granularitiesAndPredicates property("genZonedDateTime with a granularity generates appropriate ZonedDateTimes") = forAll(Gen.oneOf(granularitiesAndPredicates)) { case (granularity, predicate) => implicit val generatedGranularity: Granularity[ZonedDateTime] = granularity - forAll(genZonedDateTime)(dt => - predicate.fn( - dt - ) :| s"Granularity: ${granularity.description}; ${predicateClue(predicate)}; $dt" - ) + forAll(genZonedDateTime)(dt => predicate(dt) :| s"${granularity.description}: $dt") } property("arbitrary generation with a granularity generates appropriate ZonedDateTimes") = @@ -139,9 +125,7 @@ object GenJdk8Properties extends Properties("Java 8 Generators") { implicit val generatedGranularity: Granularity[ZonedDateTime] = granularity - forAll((dt: ZonedDateTime) => - predicate.fn(dt) :| s"${granularity.description}; ${predicateClue(predicate)}; $dt" - ) + forAll((dt: ZonedDateTime) => predicate(dt) :| s"${granularity.description}: $dt") } property("arbitrary generation with a granularity generates appropriate LocalDateTimes") = @@ -151,8 +135,7 @@ object GenJdk8Properties extends Properties("Java 8 Generators") { implicit val generatedGranularity: Granularity[ZonedDateTime] = granularity forAll { (dt: LocalDateTime) => - predicate - .fn(dt.atZone(ZoneOffset.UTC)) :| s"${granularity.description}; ${predicateClue(predicate)}; $dt" + predicate(dt.atZone(ZoneOffset.UTC)) :| s"${granularity.description}: $dt" } } @@ -163,9 +146,7 @@ object GenJdk8Properties extends Properties("Java 8 Generators") { implicit val generatedGranularity: Granularity[ZonedDateTime] = granularity forAll { (dt: LocalDate) => - predicate.fn( - dt.atStartOfDay(ZoneOffset.UTC) - ) :| s"${granularity.description}; ${predicateClue(predicate)}; $dt" + predicate(dt.atStartOfDay(ZoneOffset.UTC)) :| s"${granularity.description}: $dt" } } @@ -176,9 +157,7 @@ object GenJdk8Properties extends Properties("Java 8 Generators") { implicit val generatedGranularity: Granularity[ZonedDateTime] = granularity forAll { (instant: Instant) => - predicate.fn( - instant.atZone(ZoneOffset.UTC) - ) :| s"${granularity.description}; ${predicateClue(predicate)}; $instant" + predicate(instant.atZone(ZoneOffset.UTC)) :| s"${granularity.description}: $instant" } } @@ -232,7 +211,7 @@ object GenJdk8Properties extends Properties("Java 8 Generators") { .isBefore(generated) || granularity.normalize(lowerBound).isEqual(generated)) && (upperBound.isAfter(generated) || upperBound.isEqual(generated)) - val granularityCheck = predicate.fn(generated) + val granularityCheck = predicate(generated) val prop = rangeCheck && granularityCheck