From 074122fc54090a5f59bdcaf8310fe0a6600708ae Mon Sep 17 00:00:00 2001 From: Alexander Date: Fri, 19 Apr 2024 23:59:04 +0300 Subject: [PATCH] misc: Use fewerBraces (#234) Closes #210 --- .scalafmt.conf | 11 +- borer/src/io/github/iltotore/iron/borer.scala | 3 +- .../io/github/iltotore/iron/BorerSuite.scala | 16 +-- cats/src/io/github/iltotore/iron/cats.scala | 4 +- .../io/github/iltotore/iron/CatsSuite.scala | 42 +++---- circe/src/io/github/iltotore/iron/circe.scala | 11 +- .../io/github/iltotore/iron/CirisSuite.scala | 12 +- .../iltotore/iron/RefinedOpsTypes.scala | 2 +- .../src/io/github/iltotore/iron/decline.scala | 4 +- .../github/iltotore/iron/DeclineSuite.scala | 16 +-- .../iltotore/iron/RefinedOpsTypes.scala | 2 +- .../src/io/github/iltotore/iron/doobie.scala | 12 +- .../iron/borerSerialization/Account.scala | 2 +- .../iron/borerSerialization/main.scala | 5 +- .../iltotore/iron/formCats/HttpServer.scala | 53 ++++----- .../iltotore/iron/formZio/HttpServer.scala | 19 ++- .../github/iltotore/iron/formZio/Main.scala | 2 +- .../github/iltotore/iron/JsoniterSuite.scala | 12 +- .../io/github/iltotore/iron/MapLogic.scala | 2 +- .../github/iltotore/iron/RefinedTypeOps.scala | 9 +- .../iltotore/iron/constraint/numeric.scala | 4 +- .../iltotore/iron/constraint/string.scala | 4 +- .../io/github/iltotore/iron/conversion.scala | 6 +- .../src/io/github/iltotore/iron/package.scala | 2 - .../iltotore/iron/testing/AnySuite.scala | 24 ++-- .../iltotore/iron/testing/CharSuite.scala | 20 ++-- .../iron/testing/CollectionSuite.scala | 108 ++++++------------ .../iltotore/iron/testing/NumericSuite.scala | 36 ++---- .../iron/testing/RefinedTypeOpsSuite.scala | 42 +++---- .../iltotore/iron/testing/StringSuite.scala | 76 ++++++------ .../iltotore/iron/testing/package.scala | 2 +- .../iltotore/iron/scalacheck/Adjacent.scala | 2 +- .../github/iltotore/iron/scalacheck/Max.scala | 1 - .../github/iltotore/iron/scalacheck/Min.scala | 1 - .../github/iltotore/iron/scalacheck/all.scala | 2 +- .../iltotore/iron/scalacheck/char.scala | 2 +- .../iltotore/iron/scalacheck/collection.scala | 89 ++++++++++++--- .../iltotore/iron/scalacheck/macros.scala | 7 +- .../iltotore/iron/scalacheck/numeric.scala | 18 +-- .../iltotore/iron/scalacheck/string.scala | 10 +- .../iltotore/iron/scalacheck/AnySuite.scala | 3 +- .../iltotore/iron/scalacheck/CharSuite.scala | 9 +- .../iron/scalacheck/CollectionSuite.scala | 32 ++---- .../scalacheck/ImplicitsOrderingSuite.scala | 3 +- .../iron/scalacheck/NumericSuite.scala | 27 ++--- .../iron/scalacheck/StringSuite.scala | 3 +- .../iltotore/iron/scalacheck/package.scala | 2 +- .../io/github/iltotore/iron/SkunkSuite.scala | 27 ++--- .../src/io/github/iltotore/iron/upickle.scala | 9 +- .../github/iltotore/iron/uPickleSuite.scala | 17 +-- zio/src/io/github/iltotore/iron/zio.scala | 2 +- .../io/github/iltotore/iron/ZIOSuite.scala | 9 +- .../src/io/github/iltotore/iron/zioJson.scala | 6 +- 53 files changed, 367 insertions(+), 477 deletions(-) diff --git a/.scalafmt.conf b/.scalafmt.conf index 44b348b2..6e7a2533 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -1,4 +1,4 @@ -version = "3.6.1" +version = "3.8.1" runner.dialect = "scala3" maxColumn = 150 @@ -7,7 +7,12 @@ newlines.source = keep rewrite.scala3 { convertToNewSyntax = yes - removeOptionalBraces = yes + removeOptionalBraces { + "enabled": true, + "fewerBracesMinSpan": 2, + "fewerBracesMaxSpan": 600, + "oldSyntaxToo": yes + } } align { @@ -25,4 +30,4 @@ docstrings { style = Asterisk oneline = keep wrap = no -} \ No newline at end of file +} diff --git a/borer/src/io/github/iltotore/iron/borer.scala b/borer/src/io/github/iltotore/iron/borer.scala index 2903325d..f7ec2b63 100644 --- a/borer/src/io/github/iltotore/iron/borer.scala +++ b/borer/src/io/github/iltotore/iron/borer.scala @@ -11,11 +11,10 @@ object borer: encoder.asInstanceOf[Encoder[A :| B]] inline given [A, B](using inline decoder: Decoder[A], inline constraint: Constraint[A, B]): Decoder[A :| B] = - Decoder { r => + Decoder: r => decoder.read(r).refineEither match case Left(msg) => r.validationFailure(msg) case Right(x) => x - } inline given [T](using m: RefinedTypeOps.Mirror[T], ev: Encoder[m.IronType]): Encoder[T] = ev.asInstanceOf[Encoder[T]] diff --git a/borer/test/src/io/github/iltotore/iron/BorerSuite.scala b/borer/test/src/io/github/iltotore/iron/BorerSuite.scala index 0cd35ff9..035349c6 100644 --- a/borer/test/src/io/github/iltotore/iron/BorerSuite.scala +++ b/borer/test/src/io/github/iltotore/iron/BorerSuite.scala @@ -8,23 +8,19 @@ object BorerSuite extends TestSuite: val tests: Tests = Tests { - test("opaque alias encoding") { + test("opaque alias encoding"): Json.encode(Temperature(15.0)).toUtf8String ==> "15.0" - } - test("opaque alias decoding") { + test("opaque alias decoding"): Json.decode("15.0".getBytes).to[Temperature].valueEither ==> Right(Temperature(15.0)) Json.decode("-15.0".getBytes).to[Temperature].valueEither.left.map(_.getMessage) ==> Left("Should be strictly positive (input position 0)") - } - test("transparent alias encoding") { - Json.encode(15.0:Moisture).toUtf8String ==> "15.0" - } + test("transparent alias encoding"): + Json.encode(15.0: Moisture).toUtf8String ==> "15.0" - test("transparent alias decoding") { - Json.decode("15.0".getBytes).to[Moisture].valueEither ==> Right(15.0:Moisture) + test("transparent alias decoding"): + Json.decode("15.0".getBytes).to[Moisture].valueEither ==> Right(15.0: Moisture) Json.decode("-15.0".getBytes).to[Moisture].valueEither.left.map(_.getMessage) ==> Left("Should be strictly positive (input position 0)") - } } diff --git a/cats/src/io/github/iltotore/iron/cats.scala b/cats/src/io/github/iltotore/iron/cats.scala index 0ccf25b4..ec4eb409 100644 --- a/cats/src/io/github/iltotore/iron/cats.scala +++ b/cats/src/io/github/iltotore/iron/cats.scala @@ -173,9 +173,9 @@ object cats extends IronCatsInstances: * Represent all Cats' typeclass instances for Iron. */ private trait IronCatsInstances extends IronCatsLowPriority, RefinedTypeOpsCats: - + given [F[_]](using functor: Functor[F]): MapLogic[F] with - + override def map[A, B](wrapper: F[A], f: A => B): F[B] = functor.map(wrapper)(f) // The `NotGiven` implicit parameter is mandatory to avoid ambiguous implicit error when both Eq[A] and Hash[A]/PartialOrder[A] exist diff --git a/cats/test/src/io/github/iltotore/iron/CatsSuite.scala b/cats/test/src/io/github/iltotore/iron/CatsSuite.scala index ec53085a..09ee93ff 100644 --- a/cats/test/src/io/github/iltotore/iron/CatsSuite.scala +++ b/cats/test/src/io/github/iltotore/iron/CatsSuite.scala @@ -36,15 +36,14 @@ object CatsSuite extends TestSuite: val tests: Tests = Tests { - test("Cats instances are resolved for String iron types") { + test("Cats instances are resolved for String iron types"): Eq[String :| NameR] Hash[String :| NameR] Order[String :| NameR] PartialOrder[String :| NameR] Show[String :| NameR] - } - test("Cats instances are resolved for new types") { + test("Cats instances are resolved for new types"): Eq[Temperature] Hash[Temperature] Order[Temperature] @@ -53,9 +52,8 @@ object CatsSuite extends TestSuite: Hash[Moisture] Order[Moisture] Show[Moisture] - } - test("Cats instances are resolved for Int iron types") { + test("Cats instances are resolved for Int iron types"): Eq[Int :| AgeR] Hash[Int :| AgeR] UpperBounded[Int :| AgeR] @@ -63,66 +61,57 @@ object CatsSuite extends TestSuite: PartialOrder[Int :| AgeR] Show[Int :| AgeR] LowerBounded[Int :| AgeR] - } - test("Cats instances are resolved for a case class with iron types") { + test("Cats instances are resolved for a case class with iron types"): Eq[Person] Order[Person] Show[Person] - } test("alley") { test("commutativeMonoid") { - test("int") { + test("int"): test("pos") - assert(CommutativeMonoid[Int :| Positive].combine(1, 5) == 6) test("neg") - assert(CommutativeMonoid[Int :| Negative].combine(-1, -5) == -6) - } - test("long") { + test("long"): test("pos") - assert(CommutativeMonoid[Long :| Positive].combine(1, 5) == 6) test("neg") - assert(CommutativeMonoid[Long :| Negative].combine(-1, -5) == -6) - } - test("float") { + test("float"): test("pos") - assert(CommutativeMonoid[Float :| Positive].combine(1, 5) == 6) test("neg") - assert(CommutativeMonoid[Float :| Negative].combine(-1, -5) == -6) - } - test("double") { + test("double"): test("pos") - assert(CommutativeMonoid[Double :| Positive].combine(1, 5) == 6) test("neg") - assert(CommutativeMonoid[Double :| Negative].combine(-1, -5) == -6) - } } } - test("eitherNec") { + test("eitherNec"): import io.github.iltotore.iron.cats.* val eitherNecWithFailingPredicate = Temperature.eitherNec(-5.0) assert(eitherNecWithFailingPredicate == Left(NonEmptyChain.one("Should be strictly positive")), "'eitherNec' returns left if predicate fails") val eitherNecWithSucceedingPredicate = Temperature.eitherNec(100) assert(eitherNecWithSucceedingPredicate == Right(Temperature(100)), "right should contain result of 'apply'") - } - test("eitherNel") { + test("eitherNel"): import io.github.iltotore.iron.cats.* val eitherNelWithFailingPredicate = Temperature.eitherNel(-5.0) assert(eitherNelWithFailingPredicate == Left(NonEmptyList.one("Should be strictly positive")), "'eitherNel' returns left if predicate fails") val eitherNelWithSucceedingPredicate = Temperature.eitherNel(100) assert(eitherNelWithSucceedingPredicate == Right(Temperature(100)), "right should contain result of 'apply'") - } - test("validated") { + test("validated"): import io.github.iltotore.iron.cats.* val validatedWithFailingPredicate = Temperature.validated(-5.0) assert(validatedWithFailingPredicate == Invalid("Should be strictly positive"), "'eitherNec' returns left if predicate fails") val validatedWithSucceedingPredicate = Temperature.validated(100) assert(validatedWithSucceedingPredicate == Valid(Temperature(100)), "right should contain result of 'apply'") - } - test("validatedNec") { + test("validatedNec"): import io.github.iltotore.iron.cats.* val validatedNecWithFailingPredicate = Temperature.validatedNec(-5.0) @@ -132,9 +121,8 @@ object CatsSuite extends TestSuite: ) val validatedNecWithSucceedingPredicate = Temperature.validatedNec(100) assert(validatedNecWithSucceedingPredicate == Valid(Temperature(100)), "valid should contain result of 'apply'") - } - test("validatedNel") { + test("validatedNel"): import io.github.iltotore.iron.cats.* val validatedNelWithFailingPredicate = Temperature.validatedNel(-5.0) @@ -144,10 +132,8 @@ object CatsSuite extends TestSuite: ) val validatedNelWithSucceedingPredicate = Temperature.validatedNel(100) assert(validatedNelWithSucceedingPredicate == Valid(Temperature(100)), "valid should contain result of 'apply'") - } - test("refineAll") { + test("refineAll"): test - assert(Temperature.optionAll(NonEmptyList.of(1, 2, -3)).isEmpty) test - assert(Temperature.optionAll(NonEmptyList.of(1, 2, 3)).contains(NonEmptyList.of(Temperature(1), Temperature(2), Temperature(3)))) - } } diff --git a/circe/src/io/github/iltotore/iron/circe.scala b/circe/src/io/github/iltotore/iron/circe.scala index be1da32c..4c3d5bbb 100644 --- a/circe/src/io/github/iltotore/iron/circe.scala +++ b/circe/src/io/github/iltotore/iron/circe.scala @@ -23,12 +23,12 @@ object circe: */ inline given [A, B](using inline encoder: Encoder[A]): Encoder[A :| B] = encoder.asInstanceOf[Encoder[A :| B]] - inline given[T](using mirror: RefinedTypeOps.Mirror[T], ev: Decoder[mirror.IronType]): Decoder[T] = + inline given [T](using mirror: RefinedTypeOps.Mirror[T], ev: Decoder[mirror.IronType]): Decoder[T] = ev.asInstanceOf[Decoder[T]] - inline given[T](using mirror: RefinedTypeOps.Mirror[T], ev: Encoder[mirror.IronType]): Encoder[T] = + inline given [T](using mirror: RefinedTypeOps.Mirror[T], ev: Encoder[mirror.IronType]): Encoder[T] = ev.asInstanceOf[Encoder[T]] - + /** * A [[KeyDecoder]] for refined types. Decodes to the underlying type then checks the constraint. * @@ -46,9 +46,8 @@ object circe: */ inline given [A, B](using inline encoder: KeyEncoder[A]): KeyEncoder[A :| B] = encoder.asInstanceOf[KeyEncoder[A :| B]] - inline given[T](using mirror: RefinedTypeOps.Mirror[T], ev: KeyDecoder[mirror.IronType]): KeyDecoder[T] = + inline given [T](using mirror: RefinedTypeOps.Mirror[T], ev: KeyDecoder[mirror.IronType]): KeyDecoder[T] = ev.asInstanceOf[KeyDecoder[T]] - inline given[T](using mirror: RefinedTypeOps.Mirror[T], ev: KeyEncoder[mirror.IronType]): KeyEncoder[T] = + inline given [T](using mirror: RefinedTypeOps.Mirror[T], ev: KeyEncoder[mirror.IronType]): KeyEncoder[T] = ev.asInstanceOf[KeyEncoder[T]] - diff --git a/ciris/test/src/io/github/iltotore/iron/CirisSuite.scala b/ciris/test/src/io/github/iltotore/iron/CirisSuite.scala index 439fad25..ca7fb0e5 100644 --- a/ciris/test/src/io/github/iltotore/iron/CirisSuite.scala +++ b/ciris/test/src/io/github/iltotore/iron/CirisSuite.scala @@ -6,17 +6,13 @@ import io.github.iltotore.iron.constraint.numeric.Positive import utest.* object CirisSuite extends TestSuite: - val tests: Tests = Tests { + val tests: Tests = Tests: - test("decoder") { - test("ironType") { + test("decoder"): + test("ironType"): test("success") - assert(summon[ConfigDecoder[String, Int :| Positive]].decode(None, "5") == Right(5)) test("failure") - assert(summon[ConfigDecoder[String, Int :| Positive]].decode(None, "-5").isLeft) - } - test("newType") { + test("newType"): test("success") - assert(summon[ConfigDecoder[String, Temperature]].decode(None, "5") == Right(Temperature(5))) test("failure") - assert(summon[ConfigDecoder[String, Temperature]].decode(None, "-5").isLeft) - } - } - } diff --git a/ciris/test/src/io/github/iltotore/iron/RefinedOpsTypes.scala b/ciris/test/src/io/github/iltotore/iron/RefinedOpsTypes.scala index 4b0c33c5..49b1183f 100644 --- a/ciris/test/src/io/github/iltotore/iron/RefinedOpsTypes.scala +++ b/ciris/test/src/io/github/iltotore/iron/RefinedOpsTypes.scala @@ -3,4 +3,4 @@ package io.github.iltotore.iron import io.github.iltotore.iron.constraint.numeric.Positive opaque type Temperature = Int :| Positive -object Temperature extends RefinedTypeOps[Int, Positive, Temperature] \ No newline at end of file +object Temperature extends RefinedTypeOps[Int, Positive, Temperature] diff --git a/decline/src/io/github/iltotore/iron/decline.scala b/decline/src/io/github/iltotore/iron/decline.scala index a6b59c90..fb4dcfe4 100644 --- a/decline/src/io/github/iltotore/iron/decline.scala +++ b/decline/src/io/github/iltotore/iron/decline.scala @@ -25,8 +25,8 @@ object decline: def read(string: String): ValidatedNel[String, A :| B] = argument.read(string) match case Valid(a) => a.refineEither[B] match - case Left(value) => Validated.invalidNel(value) - case Right(value) => Validated.validNel(value) + case Left(value) => Validated.invalidNel(value) + case Right(value) => Validated.validNel(value) case Invalid(e) => Validated.invalid(e) def defaultMetavar: String = argument.defaultMetavar diff --git a/decline/test/src/io/github/iltotore/iron/DeclineSuite.scala b/decline/test/src/io/github/iltotore/iron/DeclineSuite.scala index a1f0450c..7b06d0de 100644 --- a/decline/test/src/io/github/iltotore/iron/DeclineSuite.scala +++ b/decline/test/src/io/github/iltotore/iron/DeclineSuite.scala @@ -7,17 +7,13 @@ import io.github.iltotore.iron.constraint.numeric.Positive import utest.* object DeclineSuite extends TestSuite: - val tests: Tests = Tests { + val tests: Tests = Tests: - test("Argument") { - test("ironType") { - test("success") - assert(summon[Argument[Int :| Positive]].read("5") == Valid(5)) + test("Argument"): + test("ironType"): + test("success") - assert(summon[Argument[Int :| Positive]].read("5") == Valid(5)) test("failure") - assert(summon[Argument[Int :| Positive]].read("-5").isInvalid) - } - test("newType") { - test("success") - assert(summon[Argument[Temperature]].read("5") == Valid(5)) + test("newType"): + test("success") - assert(summon[Argument[Temperature]].read("5") == Valid(5)) test("failure") - assert(summon[Argument[Temperature]].read("-5").isInvalid) - } - } - } diff --git a/decline/test/src/io/github/iltotore/iron/RefinedOpsTypes.scala b/decline/test/src/io/github/iltotore/iron/RefinedOpsTypes.scala index 4b0c33c5..49b1183f 100644 --- a/decline/test/src/io/github/iltotore/iron/RefinedOpsTypes.scala +++ b/decline/test/src/io/github/iltotore/iron/RefinedOpsTypes.scala @@ -3,4 +3,4 @@ package io.github.iltotore.iron import io.github.iltotore.iron.constraint.numeric.Positive opaque type Temperature = Int :| Positive -object Temperature extends RefinedTypeOps[Int, Positive, Temperature] \ No newline at end of file +object Temperature extends RefinedTypeOps[Int, Positive, Temperature] diff --git a/doobie/src/io/github/iltotore/iron/doobie.scala b/doobie/src/io/github/iltotore/iron/doobie.scala index ac0f78c0..443e4e69 100644 --- a/doobie/src/io/github/iltotore/iron/doobie.scala +++ b/doobie/src/io/github/iltotore/iron/doobie.scala @@ -16,7 +16,7 @@ object doobie: * @tparam A the base type * @tparam C the constraint type */ - inline given[A, C] (using inline get: Get[A])(using Constraint[A, C], Show[A]): Get[A :| C] = + inline given [A, C](using inline get: Get[A])(using Constraint[A, C], Show[A]): Get[A :| C] = get.temap[A :| C](_.refineEither) /** @@ -26,7 +26,7 @@ object doobie: * @param ev the value getter of the underlying type * @tparam T the new type */ - inline given[T](using m: RefinedTypeOps.Mirror[T], ev: Get[m.IronType]): Get[T] = + inline given [T](using m: RefinedTypeOps.Mirror[T], ev: Get[m.IronType]): Get[T] = ev.asInstanceOf[Get[T]] /** @@ -37,7 +37,7 @@ object doobie: * @tparam A the base type * @tparam C the constraint type */ - inline given[A, C] (using inline put: Put[A])(using Constraint[A, C], Show[A]): Put[A :| C] = + inline given [A, C](using inline put: Put[A])(using Constraint[A, C], Show[A]): Put[A :| C] = put.tcontramap(identity) /** @@ -47,7 +47,7 @@ object doobie: * @param ev the value setter of the underlying type * @tparam T the new type */ - inline given[T](using m: RefinedTypeOps.Mirror[T], ev: Put[m.IronType]): Put[T] = + inline given [T](using m: RefinedTypeOps.Mirror[T], ev: Put[m.IronType]): Put[T] = ev.asInstanceOf[Put[T]] /** @@ -58,7 +58,7 @@ object doobie: * @tparam A the base type * @tparam C the constraint type */ - inline given[A, C] (using inline meta: Meta[A])(using Constraint[A, C], Show[A]): Meta[A :| C] = + inline given [A, C](using inline meta: Meta[A])(using Constraint[A, C], Show[A]): Meta[A :| C] = meta.tiemap[A :| C](_.refineEither)(identity) /** @@ -68,5 +68,5 @@ object doobie: * @param ev the value getter/setter of the underlying type * @tparam T the new type */ - inline given[T](using m: RefinedTypeOps.Mirror[T], ev: Meta[m.IronType]): Meta[T] = + inline given [T](using m: RefinedTypeOps.Mirror[T], ev: Meta[m.IronType]): Meta[T] = ev.asInstanceOf[Meta[T]] diff --git a/examples/borerSerialization/src/io/github/iltotore/iron/borerSerialization/Account.scala b/examples/borerSerialization/src/io/github/iltotore/iron/borerSerialization/Account.scala index 208d503c..4164567e 100644 --- a/examples/borerSerialization/src/io/github/iltotore/iron/borerSerialization/Account.scala +++ b/examples/borerSerialization/src/io/github/iltotore/iron/borerSerialization/Account.scala @@ -19,4 +19,4 @@ case class Account( name: String :| Username, password: String :| Password, age: Int :| Age -) derives Codec \ No newline at end of file +) derives Codec diff --git a/examples/borerSerialization/src/io/github/iltotore/iron/borerSerialization/main.scala b/examples/borerSerialization/src/io/github/iltotore/iron/borerSerialization/main.scala index e5de9953..4440b178 100644 --- a/examples/borerSerialization/src/io/github/iltotore/iron/borerSerialization/main.scala +++ b/examples/borerSerialization/src/io/github/iltotore/iron/borerSerialization/main.scala @@ -23,9 +23,8 @@ import io.github.iltotore.iron.* assert(decoding == Right(account)) val decoding2 = Json.decode(invalidEncoding.getBytes).to[Account].valueEither - decoding2 match { - case Left(e: Borer.Error.ValidationFailure[_]) => + decoding2 match + case Left(e: Borer.Error.ValidationFailure[?]) => // "Password must contain at least a letter, a digit and have a length between 6 and 20 (input position 26)" println(e.getMessage) case _ => throw new IllegalStateException - } \ No newline at end of file diff --git a/examples/formCats/src/io/github/iltotore/iron/formCats/HttpServer.scala b/examples/formCats/src/io/github/iltotore/iron/formCats/HttpServer.scala index 48daf756..3bcbd194 100644 --- a/examples/formCats/src/io/github/iltotore/iron/formCats/HttpServer.scala +++ b/examples/formCats/src/io/github/iltotore/iron/formCats/HttpServer.scala @@ -14,52 +14,51 @@ import org.http4s.circe.DecodingFailures object HttpServer: /** - * Register the given [[Account]]. - * - * @param account the [[Account]] to register. - * @return a program returning an "Ok" [[Response]]. - */ + * Register the given [[Account]]. + * + * @param account the [[Account]] to register. + * @return a program returning an "Ok" [[Response]]. + */ def register(account: Account): IO[Response[IO]] = IO.println(s"Registered $account") *> Ok(account) /** - * Create a "Bad request to the API". - * - * @param messages the error messages to "throw". - * @return a program returning a properly formatted "bad request" [[Response]]. - */ + * Create a "Bad request to the API". + * + * @param messages the error messages to "throw". + * @return a program returning a properly formatted "bad request" [[Response]]. + */ def badApiRequest(messages: NonEmptyList[String]): IO[Response[IO]] = BadRequest(Map("messages" -> messages)) /** - * Handle the given error. Print it and return the appropriated - * - * @param error the error to handle. - * @return a program returning a "bad request" or an "internal server error" [[Response]]. - */ + * Handle the given error. Print it and return the appropriated + * + * @param error the error to handle. + * @return a program returning a "bad request" or an "internal server error" [[Response]]. + */ def handleError(error: Throwable): IO[Response[IO]] = - val response = + val response = error match case InvalidMessageBodyFailure(defaultMessage, cause) => cause match case Some(DecodingFailure(message, _)) => badApiRequest(NonEmptyList.one(message)) - case Some(DecodingFailures(failures)) => badApiRequest(failures.map(_.message)) - case _ => badApiRequest(NonEmptyList.one(defaultMessage)) + case Some(DecodingFailures(failures)) => badApiRequest(failures.map(_.message)) + case _ => badApiRequest(NonEmptyList.one(defaultMessage)) case MalformedMessageBodyFailure(defaultMessage, cause) => cause match case Some(ParsingFailure(message, _)) => badApiRequest(NonEmptyList.one(message)) - case _ => badApiRequest(NonEmptyList.one(defaultMessage)) - case _=> InternalServerError() + case _ => badApiRequest(NonEmptyList.one(defaultMessage)) + case _ => InternalServerError() IO(error.printStackTrace()) *> response - /** - * The main logic of our mini web server. - * Register the given user passed as a `POST` [[Request]] to `/register` then return it as a `Response` - */ - val service = HttpRoutes.of[IO] { //Can be replaced with colon + indentation in Scala 3.3 - case request@POST -> Root / "register" => + * The main logic of our mini web server. + * Register the given user passed as a `POST` [[Request]] to `/register` then return it as a `Response` + */ + val service = HttpRoutes.of[IO]: + case request @ POST -> Root / "register" => val routine = for account <- request.as[Account] @@ -68,6 +67,4 @@ object HttpServer: routine.handleErrorWith(handleError) - case unknown => NotFound() - } diff --git a/examples/formZio/src/io/github/iltotore/iron/formZio/HttpServer.scala b/examples/formZio/src/io/github/iltotore/iron/formZio/HttpServer.scala index cad7cabe..228b6bbe 100644 --- a/examples/formZio/src/io/github/iltotore/iron/formZio/HttpServer.scala +++ b/examples/formZio/src/io/github/iltotore/iron/formZio/HttpServer.scala @@ -7,24 +7,23 @@ import Account.given object HttpServer: /** - * Create a "Bad request to the API". - * - * @param message the error message to "throw". - * @return a program returning a properly formatted "bad request" [[Response]]. - */ + * Create a "Bad request to the API". + * + * @param message the error message to "throw". + * @return a program returning a properly formatted "bad request" [[Response]]. + */ def badApiRequest(message: String): Response = Response .json(Map("message" -> message).toJson) .setStatus(Status.BadRequest) /** - * The main logic of our mini web server. - * Register the given user passed as a `POST` [[Request]] to `/register` then return it as a `Response` - */ + * The main logic of our mini web server. + * Register the given user passed as a `POST` [[Request]] to `/register` then return it as a `Response` + */ val app: HttpApp[Any, Throwable] = - Http.collectZIO[Request] { + Http.collectZIO[Request]: case req @ Method.POST -> !! / "register" => req.body.asString .map(_.fromJson[Account]) .map(_.fold(badApiRequest, account => Response.json(account.toJson))) - } \ No newline at end of file diff --git a/examples/formZio/src/io/github/iltotore/iron/formZio/Main.scala b/examples/formZio/src/io/github/iltotore/iron/formZio/Main.scala index 86dbe9fa..6f38d7b0 100644 --- a/examples/formZio/src/io/github/iltotore/iron/formZio/Main.scala +++ b/examples/formZio/src/io/github/iltotore/iron/formZio/Main.scala @@ -4,4 +4,4 @@ import zio.http.* object Main extends ZIOAppDefault: override val run = - Server.serve(HttpServer.app, None).provide(Server.default) \ No newline at end of file + Server.serve(HttpServer.app, None).provide(Server.default) diff --git a/jsoniter/test/src/io/github/iltotore/iron/JsoniterSuite.scala b/jsoniter/test/src/io/github/iltotore/iron/JsoniterSuite.scala index f92baaa7..bc52cda3 100644 --- a/jsoniter/test/src/io/github/iltotore/iron/JsoniterSuite.scala +++ b/jsoniter/test/src/io/github/iltotore/iron/JsoniterSuite.scala @@ -26,19 +26,15 @@ object JsoniterSuite extends TestSuite: def assertDecodingSuccess[A](expected: A)(using JsonValueCodec[A]): Unit = assert(Try(readFromString[A](value)).fold(_ => false, _ == expected)) def assertDecodingFailure[A](using JsonValueCodec[A]): Unit = assert(Try(readFromString[A](value)).isFailure) - val tests: Tests = Tests { - test("encoding") { + val tests: Tests = Tests: + test("encoding"): test - zero.assertEncoding("0") test - Number(0).assertEncoding("""{"zero":0}""") - } - test("decoding - valid predicate") { + test("decoding - valid predicate"): test - "0".assertDecodingSuccess[Int :| Zero](zero) test - """{"zero":0}""".assertDecodingSuccess[Number](Number(0)) - } - test("decoding - invalid predicate") { + test("decoding - invalid predicate"): test - "1".assertDecodingFailure[Zero] test - """{"zero":1}""".assertDecodingFailure[Number] - } - } diff --git a/main/src/io/github/iltotore/iron/MapLogic.scala b/main/src/io/github/iltotore/iron/MapLogic.scala index db82a503..b34bbda6 100644 --- a/main/src/io/github/iltotore/iron/MapLogic.scala +++ b/main/src/io/github/iltotore/iron/MapLogic.scala @@ -24,4 +24,4 @@ object MapLogic: given (using ExecutionContext): MapLogic[Future] with - override def map[A, B](wrapper: Future[A], f: A => B): Future[B] = wrapper.map(f) \ No newline at end of file + override def map[A, B](wrapper: Future[A], f: A => B): Future[B] = wrapper.map(f) diff --git a/main/src/io/github/iltotore/iron/RefinedTypeOps.scala b/main/src/io/github/iltotore/iron/RefinedTypeOps.scala index c6dd0e31..ce01b60e 100644 --- a/main/src/io/github/iltotore/iron/RefinedTypeOps.scala +++ b/main/src/io/github/iltotore/iron/RefinedTypeOps.scala @@ -7,7 +7,7 @@ import scala.util.boundary.break /** * Utility trait for new types' companion object. - * + * * @tparam A the base type of the new type * @tparam C the constraint type of the new type * @tparam T the new type (equivalent to `A :| C` if `T` is a transparent alias) @@ -120,15 +120,14 @@ trait RefinedTypeOps[A, C, T](using private val _rtc: RuntimeConstraint[A, C]): override type BaseType = A override type ConstraintType = C - inline given[R]: TypeTest[T, R] = summonInline[TypeTest[A :| C, R]].asInstanceOf[TypeTest[T, R]] + inline given [R]: TypeTest[T, R] = summonInline[TypeTest[A :| C, R]].asInstanceOf[TypeTest[T, R]] - given[L] (using test: TypeTest[L, A]): TypeTest[L, T] with + given [L](using test: TypeTest[L, A]): TypeTest[L, T] with override def unapply(value: L): Option[value.type & T] = test.unapply(value).filter(rtc.test(_)).asInstanceOf extension (wrapper: T) inline def value: IronType[A, C] = wrapper.asInstanceOf[IronType[A, C]] - object RefinedTypeOps: /** @@ -177,4 +176,4 @@ object RefinedTypeOps: * //FinalType =/= IronType * }}} */ - type FinalType = T \ No newline at end of file + type FinalType = T diff --git a/main/src/io/github/iltotore/iron/constraint/numeric.scala b/main/src/io/github/iltotore/iron/constraint/numeric.scala index f5476ee1..ec1861be 100644 --- a/main/src/io/github/iltotore/iron/constraint/numeric.scala +++ b/main/src/io/github/iltotore/iron/constraint/numeric.scala @@ -219,7 +219,7 @@ object numeric: override inline def test(value: BigInt): Boolean = value % BigInt(longValue[V]) == 0 - inline given[V <: NumConstant]: MultipleConstraint[BigDecimal, V] with + inline given [V <: NumConstant]: MultipleConstraint[BigDecimal, V] with override inline def test(value: BigDecimal): Boolean = value % BigDecimal(doubleValue[V]) == 0 @@ -244,7 +244,7 @@ object numeric: inline given [V <: Int | Long]: DivideConstraint[BigInt, V] with override inline def test(value: BigInt): Boolean = BigInt(longValue[V]) % value == 0 - inline given[V <: NumConstant]: DivideConstraint[BigDecimal, V] with + inline given [V <: NumConstant]: DivideConstraint[BigDecimal, V] with override inline def test(value: BigDecimal): Boolean = BigDecimal(doubleValue[V]) % value == 0 object NaN: diff --git a/main/src/io/github/iltotore/iron/constraint/string.scala b/main/src/io/github/iltotore/iron/constraint/string.scala index 024f7551..ab8e9955 100644 --- a/main/src/io/github/iltotore/iron/constraint/string.scala +++ b/main/src/io/github/iltotore/iron/constraint/string.scala @@ -84,7 +84,9 @@ object string: * Tests if the input is a valid semantic version as defined in [semver site](https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string). */ type SemanticVersion = - Match["^v?(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$"] + Match[ + "^v?(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$" + ] object Blank: given (Empty ==> Blank) = Implication() diff --git a/main/src/io/github/iltotore/iron/conversion.scala b/main/src/io/github/iltotore/iron/conversion.scala index b773a2a6..5c8ce8ed 100644 --- a/main/src/io/github/iltotore/iron/conversion.scala +++ b/main/src/io/github/iltotore/iron/conversion.scala @@ -114,7 +114,7 @@ extension [A, C1](value: A :| C1) inline def refineFurtherOption[C2](using inline constraint: Constraint[A, C2]): Option[A :| (C1 & C2)] = (value: A).refineOption[C2].map(_.assumeFurther[C1]) -extension[F[_], A, C1] (wrapper: F[A :| C1]) +extension [F[_], A, C1](wrapper: F[A :| C1]) /** * Refine the given value(s) again, assuming the constraint holds. @@ -148,7 +148,7 @@ extension[F[_], A, C1] (wrapper: F[A :| C1]) wrapper, _.refineFurtherEither[C2] match case Right(value) => value - case Left(error) => break(Left(error)) + case Left(error) => break(Left(error)) )) /** @@ -168,14 +168,12 @@ extension[F[_], A, C1] (wrapper: F[A :| C1]) )) extension [A, C1, C2](value: A :| C1 :| C2) - /** * Transform `A :| C1 :| C2` to `A :| (C1 & C2)` */ inline def compose: A :| (C1 & C2) = (value: A).assume[C1 & C2] extension [A, C1, C2](value: A :| (C1 & C2)) - /** * Transform `A :| (C1 & C2)` to `A :| C1 :| C2` */ diff --git a/main/src/io/github/iltotore/iron/package.scala b/main/src/io/github/iltotore/iron/package.scala index 148f45e7..0a6966f3 100644 --- a/main/src/io/github/iltotore/iron/package.scala +++ b/main/src/io/github/iltotore/iron/package.scala @@ -121,7 +121,6 @@ extension [F[_], A](wrapper: F[A]) inline def refineAllUnsafe[B](using mapLogic: MapLogic[F], inline constraint: Constraint[A, B]): F[A :| B] = mapLogic.map(wrapper, _.refineUnsafe[B]) - /** * Refine the given value(s) at runtime, resulting in an [[Either]]. * @@ -153,4 +152,3 @@ extension [F[_], A](wrapper: F[A]) case Some(value) => value case None => break(None) )) - diff --git a/main/test/src/io/github/iltotore/iron/testing/AnySuite.scala b/main/test/src/io/github/iltotore/iron/testing/AnySuite.scala index d5b5e074..3a61e78f 100644 --- a/main/test/src/io/github/iltotore/iron/testing/AnySuite.scala +++ b/main/test/src/io/github/iltotore/iron/testing/AnySuite.scala @@ -7,51 +7,43 @@ object AnySuite extends TestSuite: val tests: Tests = Tests { - test("constant") { + test("constant"): test("true") - Dummy.assertRefine[True] test("false") - Dummy.assertNotRefine[False] - } - test("describedAs") { + test("describedAs"): test - Dummy.assertRefine[True DescribedAs "test"] test - Dummy.assertNotRefine[False DescribedAs "test"] - } - test("not") { + test("not"): test - Dummy.assertRefine[Not[False]] test - Dummy.assertNotRefine[Not[True]] - } - test("xor") { + test("xor"): test - Dummy.assertRefine[Xor[True, False]] test - Dummy.assertNotRefine[Xor[True, True]] test - Dummy.assertNotRefine[Xor[False, False]] - } - test("union") { + test("union"): test - Dummy.assertRefine[True | True] test - Dummy.assertRefine[True | False] test - Dummy.assertNotRefine[False | False] - } - test("intersection") { + test("intersection"): test - Dummy.assertRefine[True & True] test - Dummy.assertNotRefine[True & False] test - Dummy.assertNotRefine[False & False] - } - test("strictEqual") { + test("strictEqual"): test - 0.assertRefine[StrictEqual[0]] test - 1.assertNotRefine[StrictEqual[0]] test - BigDecimal(0).assertRefine[StrictEqual[0]] test - BigDecimal(1).assertNotRefine[StrictEqual[0]] test - BigInt(0).assertRefine[StrictEqual[0]] test - BigInt(1).assertNotRefine[StrictEqual[0]] - } - test("in") { + test("in"): test - 0.assertRefine[In[(0, 1)]] test - 1.assertRefine[In[(0, 1)]] test - 2.assertNotRefine[In[(0, 1)]] - } } diff --git a/main/test/src/io/github/iltotore/iron/testing/CharSuite.scala b/main/test/src/io/github/iltotore/iron/testing/CharSuite.scala index 882e2051..665efcc5 100644 --- a/main/test/src/io/github/iltotore/iron/testing/CharSuite.scala +++ b/main/test/src/io/github/iltotore/iron/testing/CharSuite.scala @@ -8,7 +8,7 @@ object CharSuite extends TestSuite: val tests: Tests = Tests { - test("blank") { //See https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Character.html#isWhitespace(char) + test("blank"): // See https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Character.html#isWhitespace(char) test - ' '.assertRefine[Whitespace] test - '\t'.assertRefine[Whitespace] test - '\n'.assertRefine[Whitespace] @@ -20,41 +20,35 @@ object CharSuite extends TestSuite: test - '\u001E'.assertRefine[Whitespace] test - '\u001F'.assertRefine[Whitespace] test - 'a'.assertNotRefine[Whitespace] - } - test("lowercase") { + test("lowercase"): test - 'a'.assertRefine[LowerCase] test - 'A'.assertNotRefine[LowerCase] test - ' '.assertNotRefine[LowerCase] test - '1'.assertNotRefine[LowerCase] - } - test("uppercase") { + test("uppercase"): test - 'A'.assertRefine[UpperCase] test - 'a'.assertNotRefine[UpperCase] test - ' '.assertNotRefine[UpperCase] test - '1'.assertNotRefine[UpperCase] - } - test("digit") { + test("digit"): test - '1'.assertRefine[Digit] test - 'a'.assertNotRefine[Digit] test - 'A'.assertNotRefine[Digit] test - '-'.assertNotRefine[Digit] - } - test("letter") { + test("letter"): test - 'a'.assertRefine[Letter] test - 'A'.assertRefine[Letter] test - '1'.assertNotRefine[Letter] test - '-'.assertNotRefine[Letter] - } - test("special") { + test("special"): test - ' '.assertRefine[Special] test - '%'.assertRefine[Special] test - 'a'.assertNotRefine[Special] test - 'A'.assertNotRefine[Special] test - '1'.assertNotRefine[Special] - } - } \ No newline at end of file + } diff --git a/main/test/src/io/github/iltotore/iron/testing/CollectionSuite.scala b/main/test/src/io/github/iltotore/iron/testing/CollectionSuite.scala index 02b311dc..b9984325 100644 --- a/main/test/src/io/github/iltotore/iron/testing/CollectionSuite.scala +++ b/main/test/src/io/github/iltotore/iron/testing/CollectionSuite.scala @@ -17,175 +17,139 @@ object CollectionSuite extends TestSuite: val tests: Tests = Tests { - test("length") { - test("iterable") { + test("length"): + test("iterable"): test - List(1, 2, 3, 4).assertRefine[Length[Greater[3]]] test - List(1, 2, 3).assertNotRefine[Length[Greater[3]]] - } - test("string") { + test("string"): test - "1234".assertRefine[Length[Greater[3]]] test - "123".assertNotRefine[Length[Greater[3]]] - } - } - test("minLength") { - test("iterable") { + test("minLength"): + test("iterable"): test - List(1, 2, 3, 4).assertRefine[MinLength[4]] test - List(1, 2, 3).assertNotRefine[MinLength[4]] - } - test("string") { + test("string"): test - "abc".assertNotRefine[MinLength[4]] test - "abcd".assertRefine[MinLength[4]] - } - } - test("maxLength") { - test("iterable") { + test("maxLength"): + test("iterable"): test - List(1, 2, 3).assertRefine[MaxLength[3]] test - List(1, 2, 3, 4).assertNotRefine[MaxLength[3]] - } - test("string") { + test("string"): test - "abc".assertRefine[MaxLength[3]] test - "abcd".assertNotRefine[MaxLength[3]] - } - } - test("empty") { - test("iterable") { + test("empty"): + test("iterable"): test - Nil.assertRefine[Empty] test - List(1, 2, 3).assertNotRefine[Empty] - } - test("string") { + test("string"): test - "".assertRefine[Empty] test - "abc".assertNotRefine[Empty] - } - } - test("fixedLength") { - test("iterable") { + test("fixedLength"): + test("iterable"): test - List(1, 2, 3).assertRefine[FixedLength[3]] test - List(1, 2).assertNotRefine[FixedLength[3]] test - List(1, 2, 3, 4).assertNotRefine[FixedLength[3]] - } - test("string") { + test("string"): test - "abc".assertRefine[FixedLength[3]] test - "ab".assertNotRefine[FixedLength[3]] test - "abcd".assertNotRefine[FixedLength[3]] - } - } - test("contain") { - test("iterable") { + test("contain"): + test("iterable"): test - List(1, 2, 3).assertRefine[Contain[3]] test - List(1, 2, 4).assertNotRefine[Contain[3]] - } - test("string") { + test("string"): test - "abc".assertRefine[Contain["c"]] test - "abd".assertNotRefine[Contain["c"]] - } - } - test("forAll") { - test("iterable") { + test("forAll"): + test("iterable"): test - Nil.assertRefine[ForAll[IsA]] test - List('a', 'a', 'a').assertRefine[ForAll[IsA]] test - List('a', 'b', 'c').assertNotRefine[ForAll[IsA]] - } - test("string") { + test("string"): test - "".assertRefine[ForAll[IsA]] test - "aaa".assertRefine[ForAll[IsA]] test - "abc".assertNotRefine[ForAll[IsA]] - } - } - test("init") { - test("iterable") { + test("init"): + test("iterable"): test - Nil.assertRefine[Init[IsA]] test - List('b').assertRefine[Init[IsA]] test - List('a', 'a', 'b').assertRefine[Init[IsA]] test - List('a', 'a', 'a').assertRefine[Init[IsA]] test - List('a', 'b', 'c').assertNotRefine[Init[IsA]] - } - test("string") { + test("string"): test - "".assertRefine[Init[IsA]] test - "b".assertRefine[Init[IsA]] test - "aab".assertRefine[Init[IsA]] test - "aaa".assertRefine[Init[IsA]] test - "abc".assertNotRefine[Init[IsA]] - } - } - test("tail") { - test("iterable") { + test("tail"): + test("iterable"): test - Nil.assertRefine[Tail[IsA]] test - List('b').assertRefine[Tail[IsA]] test - List('b', 'a', 'a').assertRefine[Tail[IsA]] test - List('a', 'a', 'a').assertRefine[Tail[IsA]] test - List('a', 'b', 'c').assertNotRefine[Tail[IsA]] - } - test("string") { + test("string"): test - "".assertRefine[Tail[IsA]] test - "b".assertRefine[Tail[IsA]] test - "baa".assertRefine[Tail[IsA]] test - "aaa".assertRefine[Tail[IsA]] test - "abc".assertNotRefine[Tail[IsA]] - } - } - test("exists") { - test("iterable") { + test("exists"): + test("iterable"): test - List('a', 'a', 'a').assertRefine[Exists[IsA]] test - List('a', 'b', 'c').assertRefine[Exists[IsA]] test - List('b', 'b', 'c').assertNotRefine[Exists[IsA]] test - Nil.assertNotRefine[Exists[IsA]] - } - test("string") { + test("string"): test - "aaa".assertRefine[Exists[IsA]] test - "abc".assertRefine[Exists[IsA]] test - "bbc".assertNotRefine[Exists[IsA]] test - "".assertNotRefine[Exists[IsA]] - } - } - test("head") { - test("iterable") { + test("head"): + test("iterable"): test - List('a', 'b', 'c').assertRefine[Head[IsA]] test - List('c', 'b', 'a').assertNotRefine[Head[IsA]] test - List('b', 'b', 'c').assertNotRefine[Head[IsA]] test - Nil.assertNotRefine[Head[IsA]] - } - test("string") { + test("string"): test - "abc".assertRefine[Head[IsA]] test - "cba".assertNotRefine[Head[IsA]] test - "bbc".assertNotRefine[Head[IsA]] test - "".assertNotRefine[Head[IsA]] - } - } - test("last") { - test("iterable") { + test("last"): + test("iterable"): test - List('c', 'b', 'a').assertRefine[Last[IsA]] test - List('a', 'b', 'c').assertNotRefine[Last[IsA]] test - List('b', 'b', 'c').assertNotRefine[Last[IsA]] test - Nil.assertNotRefine[Last[IsA]] - } - test("string") { + test("string"): test - "cba".assertRefine[Last[IsA]] test - "abc".assertNotRefine[Last[IsA]] test - "bbc".assertNotRefine[Last[IsA]] test - "".assertNotRefine[Last[IsA]] - } - } } diff --git a/main/test/src/io/github/iltotore/iron/testing/NumericSuite.scala b/main/test/src/io/github/iltotore/iron/testing/NumericSuite.scala index 086c60d7..8e80ecb9 100644 --- a/main/test/src/io/github/iltotore/iron/testing/NumericSuite.scala +++ b/main/test/src/io/github/iltotore/iron/testing/NumericSuite.scala @@ -8,80 +8,71 @@ object NumericSuite extends TestSuite: val tests: Tests = Tests { - test("greater") { + test("greater"): test - 0.assertNotRefine[Greater[0]] test - 1.assertRefine[Greater[0]] test - BigDecimal(0).assertNotRefine[Greater[0]] test - BigDecimal(1).assertRefine[Greater[0]] test - BigInt(0).assertNotRefine[Greater[0]] test - BigInt(1).assertRefine[Greater[0]] - } - test("greaterEqual") { + test("greaterEqual"): test - -1.assertNotRefine[GreaterEqual[0]] test - 0.assertRefine[GreaterEqual[0]] test - 1.assertRefine[GreaterEqual[1]] - } - test("less") { + test("less"): test - 0.assertNotRefine[Less[0]] test - -1.assertRefine[Less[0]] test - BigDecimal(0).assertNotRefine[Less[0]] test - BigDecimal(-1).assertRefine[Less[0]] test - BigInt(0).assertNotRefine[Less[0]] test - BigInt(-1).assertRefine[Less[0]] - } - test("lessEqual") { + test("lessEqual"): test - 1.assertNotRefine[LessEqual[0]] test - 0.assertRefine[LessEqual[0]] test - -1.assertRefine[LessEqual[0]] - } test("interval") { - test("open") { + test("open"): test - 1.assertRefine[Interval.Open[0, 2]] test - 0.assertNotRefine[Interval.Open[0, 2]] test - 2.assertNotRefine[Interval.Open[0, 2]] test - -1.assertNotRefine[Interval.Open[0, 2]] test - 3.assertNotRefine[Interval.Open[0, 2]] - } - test("openClosed") { + test("openClosed"): test - 1.assertRefine[Interval.OpenClosed[0, 2]] test - 2.assertRefine[Interval.OpenClosed[0, 2]] test - 0.assertNotRefine[Interval.OpenClosed[0, 2]] test - -1.assertNotRefine[Interval.OpenClosed[0, 2]] test - 3.assertNotRefine[Interval.OpenClosed[0, 2]] - } - test("closedOpen") { + test("closedOpen"): test - 1.assertRefine[Interval.ClosedOpen[0, 2]] test - 0.assertRefine[Interval.ClosedOpen[0, 2]] test - 2.assertNotRefine[Interval.ClosedOpen[0, 2]] test - -1.assertNotRefine[Interval.ClosedOpen[0, 2]] test - 3.assertNotRefine[Interval.ClosedOpen[0, 2]] - } - test("closed") { + test("closed"): test - 1.assertRefine[Interval.Closed[0, 2]] test - 2.assertRefine[Interval.Closed[0, 2]] test - 0.assertRefine[Interval.Closed[0, 2]] test - -1.assertNotRefine[Interval.Closed[0, 2]] test - 3.assertNotRefine[Interval.Closed[0, 2]] - } } - test("multiple") { + test("multiple"): test - 1.assertNotRefine[Multiple[2]] test - 2.assertRefine[Multiple[2]] test - BigInt(1).assertNotRefine[Multiple[2]] test - BigInt(2).assertRefine[Multiple[2]] test - BigDecimal(1).assertNotRefine[Multiple[2]] test - BigDecimal(2).assertRefine[Multiple[2]] - } - test("divide") { + test("divide"): test - 1.assertRefine[Divide[2]] test - 2.assertRefine[Divide[2]] test - 3.assertNotRefine[Divide[2]] @@ -91,21 +82,18 @@ object NumericSuite extends TestSuite: test - BigDecimal(1).assertRefine[Divide[2]] test - BigDecimal(2).assertRefine[Divide[2]] test - BigDecimal(3).assertNotRefine[Divide[2]] - } - test("nan") { + test("nan"): test - Float.NaN.assertRefine[NaN] test - Double.NaN.assertRefine[NaN] test - 0f.assertNotRefine[NaN] test - 0d.assertNotRefine[NaN] - } - test("infinity") { + test("infinity"): test - Float.PositiveInfinity.assertRefine[Infinity] test - Float.NegativeInfinity.assertRefine[Infinity] test - Double.PositiveInfinity.assertRefine[Infinity] test - Double.NegativeInfinity.assertRefine[Infinity] test - 0f.assertNotRefine[Infinity] test - 0d.assertNotRefine[Infinity] - } } diff --git a/main/test/src/io/github/iltotore/iron/testing/RefinedTypeOpsSuite.scala b/main/test/src/io/github/iltotore/iron/testing/RefinedTypeOpsSuite.scala index 3452ccc2..9cbfa4e7 100644 --- a/main/test/src/io/github/iltotore/iron/testing/RefinedTypeOpsSuite.scala +++ b/main/test/src/io/github/iltotore/iron/testing/RefinedTypeOpsSuite.scala @@ -9,20 +9,18 @@ import scala.util.{Failure, Success, Try} object RefinedTypeOpsSuite extends TestSuite: val tests: Tests = Tests { - test("compile-time apply") { + test("compile-time apply"): val temperature = Temperature(100) compileError("Temperature(-100)") - } - test("value") { + test("value"): val t1 = Temperature(100) val t2 = Temperature(100) val result = t1.value + t2.value assert(result == 200.0) - } - test("re-eval") { + test("re-eval"): val x: Double :| Positive = 5.0 val y: Double :| Greater[10] = 15.0 val t1 = Temperature(x) @@ -30,47 +28,42 @@ object RefinedTypeOpsSuite extends TestSuite: assert(t1 == Temperature(5.0)) assert(t2 == Temperature(15.0)) - } test("assume") - assert(Temperature.assume(-15) == -15.0.asInstanceOf[Temperature]) - test("applyUnsafe") { - test - assertMatch(Try(Temperature.applyUnsafe(-100))) { case Failure(e) if e.getMessage == "Should be strictly positive" => } + test("applyUnsafe"): + test - assertMatch(Try(Temperature.applyUnsafe(-100))): + case Failure(e) if e.getMessage == "Should be strictly positive" => test - assert(Temperature.applyUnsafe(100) == Temperature(100)) - } - test("either") { + test("either"): val eitherWithFailingPredicate = Temperature.either(-5.0) assert(eitherWithFailingPredicate == Left("Should be strictly positive")) val eitherWithSucceedingPredicate = Temperature.either(100) assert(eitherWithSucceedingPredicate == Right(Temperature(100))) - } - test("option") { + test("option"): val fromWithFailingPredicate = Temperature.option(-5.0) assert(fromWithFailingPredicate.isEmpty) val fromWithSucceedingPredicate = Temperature.option(100) assert(fromWithSucceedingPredicate.contains(Temperature(100))) - } test("assumeAll") - assert(Temperature.assumeAll(List(1, -15)) == List(1, -15).asInstanceOf[List[Temperature]]) - test("applyAllUnsafe") { - test - assertMatch(Try(Temperature.applyAllUnsafe(List(1, 2, -3)))) { case Failure(e) if e.getMessage == "Should be strictly positive" => } + test("applyAllUnsafe"): + test - assertMatch(Try(Temperature.applyAllUnsafe(List(1, 2, -3)))): + case Failure(e) if e.getMessage == "Should be strictly positive" => test - assert(Temperature.applyAllUnsafe(List(1, 2, 3)) == List(Temperature(1), Temperature(2), Temperature(3))) - } - test("either") { + test("either"): test - assert(Temperature.eitherAll(List(1, 2, -3)) == Left("Should be strictly positive")) test - assert(Temperature.eitherAll(List(1, 2, 3)) == Right(List(Temperature(1), Temperature(2), Temperature(3)))) - } - test("option") { + test("option"): test - assert(Temperature.optionAll(List(1, 2, -3)).isEmpty) test - assert(Temperature.optionAll(List(1, 2, 3)).contains(List(Temperature(1), Temperature(2), Temperature(3)))) - } - test("nonOpaque") { + test("nonOpaque"): val moisture = Moisture(11) val positive: Double :| Positive = 11 val greaterThan10: Double :| Greater[10] = 11 @@ -82,18 +75,15 @@ object RefinedTypeOpsSuite extends TestSuite: test - assert(Moisture.either(100) == Right(Moisture(100))) test - assert(Moisture.option(-5.0).isEmpty) test - assert(Moisture.option(100).contains(Moisture(100))) - } - test("mirror") { + test("mirror"): val mirror = summonInline[RefinedTypeOps.Mirror[Temperature]] assertGiven[mirror.BaseType =:= Double] assertGiven[mirror.ConstraintType =:= Positive] assertGiven[mirror.FinalType =:= Temperature] - } - test("value") { + test("value"): val temperature = Temperature(10) assert(temperature.value == 10) - } } diff --git a/main/test/src/io/github/iltotore/iron/testing/StringSuite.scala b/main/test/src/io/github/iltotore/iron/testing/StringSuite.scala index a8276feb..f12993ba 100644 --- a/main/test/src/io/github/iltotore/iron/testing/StringSuite.scala +++ b/main/test/src/io/github/iltotore/iron/testing/StringSuite.scala @@ -8,56 +8,48 @@ object StringSuite extends TestSuite: val tests: Tests = Tests { - test("blank") { + test("blank"): test - "".assertRefine[Blank] test - " \t\n\u000B\f\r\u001C\u001D\u001E\u001F".assertRefine[Blank] test - "a".assertNotRefine[Blank] - } - test("trimmed") { + test("trimmed"): test - "".assertRefine[Trimmed] test - "abc".assertRefine[Trimmed] test - " ".assertNotRefine[Trimmed] test - " abc ".assertNotRefine[Trimmed] test - "abc\n".assertNotRefine[Trimmed] - } - test("lowercase") { + test("lowercase"): test - "abc 123 \n".assertRefine[LettersLowerCase] test - "ABC 123 \n".assertNotRefine[LettersLowerCase] - } - test("uppercase") { + test("uppercase"): test - "abc 123 \n".assertNotRefine[LettersUpperCase] test - "ABC 123 \n".assertRefine[LettersUpperCase] - } - test("alphanumeric") { + test("alphanumeric"): test - "abc".assertRefine[Alphanumeric] test - "123".assertRefine[Alphanumeric] test - "abc123".assertRefine[Alphanumeric] test - "".assertRefine[Alphanumeric] test - "abc123_".assertNotRefine[Alphanumeric] test - " ".assertNotRefine[Alphanumeric] - } - test("startWith") { + test("startWith"): test - "abc".assertRefine[StartWith["abc"]] test - "abc123".assertRefine[StartWith["abc"]] test - "ab".assertNotRefine[StartWith["abc"]] - } - test("endWith") { + test("endWith"): test - "abc".assertRefine[EndWith["abc"]] test - "123abc".assertRefine[EndWith["abc"]] test - "ab".assertNotRefine[EndWith["abc"]] - } - test("match") { + test("match"): test - "998".assertRefine[Match["[0-9]+"]] test - "abc".assertNotRefine[Match["[0-9]+"]] test - "".assertNotRefine[Match["[0-9]+"]] - } test("url") { test - "localhost".assertRefine[ValidURL] @@ -78,32 +70,32 @@ object StringSuite extends TestSuite: } test("semantic version") { - test - "1.0.0".assertRefine[SemanticVersion] - test - "1.0.0-alpha".assertRefine[SemanticVersion] - test - "1.0.0-alpha.1".assertRefine[SemanticVersion] - test - "1.0.0-0.3.7".assertRefine[SemanticVersion] - test - "1.0.0-x.7.z.92".assertRefine[SemanticVersion] - test - "1.0.0-alpha+001".assertRefine[SemanticVersion] - test - "1.0.0+20130313144700".assertRefine[SemanticVersion] - test - "1.0.0-beta+exp.sha.5114f85".assertRefine[SemanticVersion] - test - "1.0.0-rc.1+exp.sha.5114f85".assertRefine[SemanticVersion] - test - "1".assertNotRefine[SemanticVersion] - test - "1.0".assertNotRefine[SemanticVersion] - test - "x.0.0".assertNotRefine[SemanticVersion] - test - "0.y.0".assertNotRefine[SemanticVersion] - test - "0.0.z".assertNotRefine[SemanticVersion] - test - "x.y.z".assertNotRefine[SemanticVersion] - test - "00000001.0.0".assertNotRefine[SemanticVersion] - test - "0.00000001.0".assertNotRefine[SemanticVersion] - test - "0.0.00000001".assertNotRefine[SemanticVersion] - test - "1.0.0-rc.1+exp.sha.51_14f85".assertNotRefine[SemanticVersion] - test - "1.0.0-rc.1+exp.sha.51 14f85".assertNotRefine[SemanticVersion] - test - "1.0.0-rc.1+exp.sha.51?14f85".assertNotRefine[SemanticVersion] - test - "1.0.0-rc.1+exp.sha.51#14f85".assertNotRefine[SemanticVersion] - test - "1.0.0-rc.1+exp.sha.51@14f85".assertNotRefine[SemanticVersion] - test - "1.0.0-rc.1+exp.sha.51:14f85".assertNotRefine[SemanticVersion] - test - "1.0.0-rc.1+exp.sha.51*14f85".assertNotRefine[SemanticVersion] - test - "1.0.0-rc.1+exp.sha.51|14f85".assertNotRefine[SemanticVersion] + test - "1.0.0".assertRefine[SemanticVersion] + test - "1.0.0-alpha".assertRefine[SemanticVersion] + test - "1.0.0-alpha.1".assertRefine[SemanticVersion] + test - "1.0.0-0.3.7".assertRefine[SemanticVersion] + test - "1.0.0-x.7.z.92".assertRefine[SemanticVersion] + test - "1.0.0-alpha+001".assertRefine[SemanticVersion] + test - "1.0.0+20130313144700".assertRefine[SemanticVersion] + test - "1.0.0-beta+exp.sha.5114f85".assertRefine[SemanticVersion] + test - "1.0.0-rc.1+exp.sha.5114f85".assertRefine[SemanticVersion] + test - "1".assertNotRefine[SemanticVersion] + test - "1.0".assertNotRefine[SemanticVersion] + test - "x.0.0".assertNotRefine[SemanticVersion] + test - "0.y.0".assertNotRefine[SemanticVersion] + test - "0.0.z".assertNotRefine[SemanticVersion] + test - "x.y.z".assertNotRefine[SemanticVersion] + test - "00000001.0.0".assertNotRefine[SemanticVersion] + test - "0.00000001.0".assertNotRefine[SemanticVersion] + test - "0.0.00000001".assertNotRefine[SemanticVersion] + test - "1.0.0-rc.1+exp.sha.51_14f85".assertNotRefine[SemanticVersion] + test - "1.0.0-rc.1+exp.sha.51 14f85".assertNotRefine[SemanticVersion] + test - "1.0.0-rc.1+exp.sha.51?14f85".assertNotRefine[SemanticVersion] + test - "1.0.0-rc.1+exp.sha.51#14f85".assertNotRefine[SemanticVersion] + test - "1.0.0-rc.1+exp.sha.51@14f85".assertNotRefine[SemanticVersion] + test - "1.0.0-rc.1+exp.sha.51:14f85".assertNotRefine[SemanticVersion] + test - "1.0.0-rc.1+exp.sha.51*14f85".assertNotRefine[SemanticVersion] + test - "1.0.0-rc.1+exp.sha.51|14f85".assertNotRefine[SemanticVersion] } } diff --git a/main/test/src/io/github/iltotore/iron/testing/package.scala b/main/test/src/io/github/iltotore/iron/testing/package.scala index f397a79a..4606416e 100644 --- a/main/test/src/io/github/iltotore/iron/testing/package.scala +++ b/main/test/src/io/github/iltotore/iron/testing/package.scala @@ -8,4 +8,4 @@ extension [A](value: A) inline def assertRefine[B](using inline constraint: Constraint[A, B]): Unit = assert(constraint.test(value)) inline def assertNotRefine[B](using inline constraint: Constraint[A, B]): Unit = assert(!constraint.test(value)) -inline def assertGiven[T](using inline ev: T = null): Unit = assert(ev != null) \ No newline at end of file +inline def assertGiven[T](using inline ev: T = null): Unit = assert(ev != null) diff --git a/scalacheck/src/io/github/iltotore/iron/scalacheck/Adjacent.scala b/scalacheck/src/io/github/iltotore/iron/scalacheck/Adjacent.scala index 7e85bc10..5d8b3f3b 100644 --- a/scalacheck/src/io/github/iltotore/iron/scalacheck/Adjacent.scala +++ b/scalacheck/src/io/github/iltotore/iron/scalacheck/Adjacent.scala @@ -44,4 +44,4 @@ object Adjacent: override def nextUp(x: Double): Double = if x == Double.MaxValue then x else Math.nextUp(x) - override def nextDown(x: Double): Double = Math.nextDown(x) \ No newline at end of file + override def nextDown(x: Double): Double = Math.nextDown(x) diff --git a/scalacheck/src/io/github/iltotore/iron/scalacheck/Max.scala b/scalacheck/src/io/github/iltotore/iron/scalacheck/Max.scala index bcb8e377..96778966 100644 --- a/scalacheck/src/io/github/iltotore/iron/scalacheck/Max.scala +++ b/scalacheck/src/io/github/iltotore/iron/scalacheck/Max.scala @@ -21,4 +21,3 @@ object Max: given Max[Long] = Max(Long.MaxValue) given Max[Float] = Max(Float.MaxValue) given Max[Double] = Max(Double.MaxValue) - diff --git a/scalacheck/src/io/github/iltotore/iron/scalacheck/Min.scala b/scalacheck/src/io/github/iltotore/iron/scalacheck/Min.scala index a50281b0..d32659b3 100644 --- a/scalacheck/src/io/github/iltotore/iron/scalacheck/Min.scala +++ b/scalacheck/src/io/github/iltotore/iron/scalacheck/Min.scala @@ -21,4 +21,3 @@ object Min: given Min[Long] = Min(Long.MinValue) given Min[Float] = Min(Float.MinValue) given Min[Double] = Min(Double.MinValue) - diff --git a/scalacheck/src/io/github/iltotore/iron/scalacheck/all.scala b/scalacheck/src/io/github/iltotore/iron/scalacheck/all.scala index 5b0a05dd..084e38ae 100644 --- a/scalacheck/src/io/github/iltotore/iron/scalacheck/all.scala +++ b/scalacheck/src/io/github/iltotore/iron/scalacheck/all.scala @@ -4,4 +4,4 @@ object all extends AnyArbitrary: export char.given export collection.given export numeric.given - export string.given \ No newline at end of file + export string.given diff --git a/scalacheck/src/io/github/iltotore/iron/scalacheck/char.scala b/scalacheck/src/io/github/iltotore/iron/scalacheck/char.scala index 0fb50e21..890bdf30 100644 --- a/scalacheck/src/io/github/iltotore/iron/scalacheck/char.scala +++ b/scalacheck/src/io/github/iltotore/iron/scalacheck/char.scala @@ -21,4 +21,4 @@ object char: private val specialASCIIChars: Seq[Char] = (Char.MinValue until '0') ++ (':' until 'A') ++ ('[' until 'a') ++ ('{' to 127.toChar) - inline given special: Arbitrary[Char :| Special] = Arbitrary(Gen.oneOf(specialASCIIChars)).asInstanceOf \ No newline at end of file + inline given special: Arbitrary[Char :| Special] = Arbitrary(Gen.oneOf(specialASCIIChars)).asInstanceOf diff --git a/scalacheck/src/io/github/iltotore/iron/scalacheck/collection.scala b/scalacheck/src/io/github/iltotore/iron/scalacheck/collection.scala index a78edbca..1df77a5e 100644 --- a/scalacheck/src/io/github/iltotore/iron/scalacheck/collection.scala +++ b/scalacheck/src/io/github/iltotore/iron/scalacheck/collection.scala @@ -11,36 +11,66 @@ import scala.compiletime.constValue object collection: - inline given empty[A, CC[_]](using arbElem: Arbitrary[A], evb: Buildable[A, CC[A]], evt: CC[A] => Iterable[A]): Arbitrary[CC[A] :| Empty] = exactLength[A, CC, 0].asInstanceOf + inline given empty[A, CC[_]](using arbElem: Arbitrary[A], evb: Buildable[A, CC[A]], evt: CC[A] => Iterable[A]): Arbitrary[CC[A] :| Empty] = + exactLength[A, CC, 0].asInstanceOf - inline given exactLength[A, CC[_], V <: Int](using arbElem: Arbitrary[A], evb: Buildable[A, CC[A]], evt: CC[A] => Iterable[A]): Arbitrary[CC[A] :| FixedLength[V]] = + inline given exactLength[A, CC[_], V <: Int](using + arbElem: Arbitrary[A], + evb: Buildable[A, CC[A]], + evt: CC[A] => Iterable[A] + ): Arbitrary[CC[A] :| FixedLength[V]] = Arbitrary(Gen.infiniteLazyList(arbElem.arbitrary).flatMap(ll => evb.fromIterable(ll.take(constValue[V])))).asInstanceOf - - inline given minLength[A, CC[_], V <: Int](using arbElem: Arbitrary[A], evb: Buildable[A,CC[A]], evt: CC[A] => Iterable[A]): Arbitrary[CC[A] :| MinLength[V]] = + + inline given minLength[A, CC[_], V <: Int](using + arbElem: Arbitrary[A], + evb: Buildable[A, CC[A]], + evt: CC[A] => Iterable[A] + ): Arbitrary[CC[A] :| MinLength[V]] = Arbitrary( for prefix <- Gen.infiniteLazyList(arbElem.arbitrary) postfix <- Gen.listOf(arbElem.arbitrary) - yield - evb.fromIterable(prefix.take(constValue[V]) ++ postfix) + yield evb.fromIterable(prefix.take(constValue[V]) ++ postfix) ).asInstanceOf - - inline given maxLength[A, CC[_], V <: Int](using arbElem: Arbitrary[A], evb: Buildable[A,CC[A]], evt: CC[A] => Iterable[A]): Arbitrary[CC[A] :| MaxLength[V]] = + + inline given maxLength[A, CC[_], V <: Int](using + arbElem: Arbitrary[A], + evb: Buildable[A, CC[A]], + evt: CC[A] => Iterable[A] + ): Arbitrary[CC[A] :| MaxLength[V]] = Arbitrary(Gen.containerOf(arbElem.arbitrary).flatMap(cc => Gen.const(evt(cc).take(constValue[V])))).asInstanceOf[Arbitrary[CC[A] :| MaxLength[V]]] - inline given length[A, CC[_], C](using arbLength: Arbitrary[Int :| C], arbElem: Arbitrary[A], evb: Buildable[A,CC[A]], evt: CC[A] => Iterable[A]): Arbitrary[CC[A] :| Length[C]] = + inline given length[A, CC[_], C](using + arbLength: Arbitrary[Int :| C], + arbElem: Arbitrary[A], + evb: Buildable[A, CC[A]], + evt: CC[A] => Iterable[A] + ): Arbitrary[CC[A] :| Length[C]] = Arbitrary(arbLength.arbitrary.flatMap(n => Gen.containerOfN(n, arbElem.arbitrary))).asInstanceOf - inline given contain[A, V <: A, CC[_]] (using arb: Arbitrary[A], buildable: Buildable[A, CC[A]], evt: CC[A] => Iterable[A]): Arbitrary[CC[A] :| Contain[V]] = + inline given contain[A, V <: A, CC[_]](using + arb: Arbitrary[A], + buildable: Buildable[A, CC[A]], + evt: CC[A] => Iterable[A] + ): Arbitrary[CC[A] :| Contain[V]] = Arbitrary( Gen.containerOf(arb.arbitrary) .map(cc => (buildable.builder ++= evt(cc) += constValue[V]).result()) ).asInstanceOf - inline given forAll[A, CC[_], C](using arb: Arbitrary[A :| C], evb: Buildable[A :| C, CC[A :| C]], evt: CC[A :| C] => Iterable[A :| C]): Arbitrary[CC[A] :| ForAll[C]] = + inline given forAll[A, CC[_], C](using + arb: Arbitrary[A :| C], + evb: Buildable[A :| C, CC[A :| C]], + evt: CC[A :| C] => Iterable[A :| C] + ): Arbitrary[CC[A] :| ForAll[C]] = Arbitrary.arbContainer[CC, A :| C].asInstanceOf - inline given init[A, CC[_], C](using arb: Arbitrary[A], arbConstrained: Arbitrary[A :| C], buildable: Buildable[A, CC[A]], evt: CC[A] => Iterable[A]): Arbitrary[CC[A] :| Init[C]] = + inline given init[A, CC[_], C](using + arb: Arbitrary[A], + arbConstrained: Arbitrary[A :| C], + buildable: Buildable[A, CC[A]], + evt: CC[A] => Iterable[A] + ): Arbitrary[CC[A] :| Init[C]] = Arbitrary( for headValue <- arb.arbitrary @@ -48,15 +78,25 @@ object collection: yield (buildable.builder ++= evt(constrainedValues) += headValue).result() ).asInstanceOf - inline given tail[A, CC[_], C](using arb: Arbitrary[A], arbConstrained: Arbitrary[A :| C], buildable: Buildable[A, CC[A]], evt: CC[A] => Iterable[A]): Arbitrary[CC[A] :| Tail[C]] = + inline given tail[A, CC[_], C](using + arb: Arbitrary[A], + arbConstrained: Arbitrary[A :| C], + buildable: Buildable[A, CC[A]], + evt: CC[A] => Iterable[A] + ): Arbitrary[CC[A] :| Tail[C]] = Arbitrary( for headValue <- arb.arbitrary constrainedValues <- Gen.containerOf[CC, A](arbConstrained.arbitrary) - yield (buildable.builder += headValue ++= evt(constrainedValues) ).result() + yield (buildable.builder += headValue ++= evt(constrainedValues)).result() ).asInstanceOf - inline given exists[A, CC[_], C](using arb: Arbitrary[A], arbConstrained: Arbitrary[A :| C], buildable: Buildable[A, CC[A]], evt: CC[A] => Iterable[A]): Arbitrary[CC[A] :| Exists[C]] = + inline given exists[A, CC[_], C](using + arb: Arbitrary[A], + arbConstrained: Arbitrary[A :| C], + buildable: Buildable[A, CC[A]], + evt: CC[A] => Iterable[A] + ): Arbitrary[CC[A] :| Exists[C]] = Arbitrary( for constrainedValue <- arbConstrained.arbitrary @@ -65,7 +105,12 @@ object collection: yield (buildable.builder ++= evt(init) += constrainedValue ++= evt(tail)).result() ).asInstanceOf - inline given head[A, CC[_], C](using arb: Arbitrary[A], arbConstrained: Arbitrary[A :| C], buildable: Buildable[A, CC[A]], evt: CC[A] => Iterable[A]): Arbitrary[CC[A] :| Head[C]] = + inline given head[A, CC[_], C](using + arb: Arbitrary[A], + arbConstrained: Arbitrary[A :| C], + buildable: Buildable[A, CC[A]], + evt: CC[A] => Iterable[A] + ): Arbitrary[CC[A] :| Head[C]] = Arbitrary( for constrainedHead <- arbConstrained.arbitrary @@ -73,12 +118,18 @@ object collection: yield (buildable.builder += constrainedHead ++= evt(tail)).result() ).asInstanceOf - inline given last[A, CC[_], C](using arb: Arbitrary[A], arbConstrained: Arbitrary[A :| C], buildable: Buildable[A, CC[A]], evt: CC[A] => Iterable[A]): Arbitrary[CC[A] :| Last[C]] = + inline given last[A, CC[_], C](using + arb: Arbitrary[A], + arbConstrained: Arbitrary[A :| C], + buildable: Buildable[A, CC[A]], + evt: CC[A] => Iterable[A] + ): Arbitrary[CC[A] :| Last[C]] = Arbitrary( for constrainedLast <- arbConstrained.arbitrary init <- Gen.containerOf[CC, A](arb.arbitrary) - yield (buildable.builder ++= evt(init) += constrainedLast ).result() + yield (buildable.builder ++= evt(init) += constrainedLast).result() ).asInstanceOf - inline given notEmptyCollection[CC, A](using evb: Buildable[A, CC], ev2: CC => Iterable[A], arb: Arbitrary[A]): Arbitrary[CC :| Not[Empty]] = Arbitrary(Gen.nonEmptyBuildableOf[CC, A](arb.arbitrary)).asInstanceOf + inline given notEmptyCollection[CC, A](using evb: Buildable[A, CC], ev2: CC => Iterable[A], arb: Arbitrary[A]): Arbitrary[CC :| Not[Empty]] = + Arbitrary(Gen.nonEmptyBuildableOf[CC, A](arb.arbitrary)).asInstanceOf diff --git a/scalacheck/src/io/github/iltotore/iron/scalacheck/macros.scala b/scalacheck/src/io/github/iltotore/iron/scalacheck/macros.scala index 9fffae6e..1825456d 100644 --- a/scalacheck/src/io/github/iltotore/iron/scalacheck/macros.scala +++ b/scalacheck/src/io/github/iltotore/iron/scalacheck/macros.scala @@ -13,13 +13,12 @@ private def unionGenImpl[A, C](using Quotes, Type[A], Type[C]): Expr[Gen[A :| C] def rec(tpe: TypeRepr): Expr[Gen[?]] = tpe.dealias match - case OrType(left, right) => '{ Gen.oneOf(${rec(left)}, ${rec(right)}) } + case OrType(left, right) => '{ Gen.oneOf(${ rec(left) }, ${ rec(right) }) } case constraintTpe => - type ConstraintPart given Type[ConstraintPart] = constraintTpe.asType.asInstanceOf - '{scala.compiletime.summonInline[Arbitrary[A :| ConstraintPart]].arbitrary} + '{ scala.compiletime.summonInline[Arbitrary[A :| ConstraintPart]].arbitrary } - '{${rec(TypeRepr.of[C])}.asInstanceOf[Gen[A :| C]]}.asExprOf[Gen[A :| C]] + '{ ${ rec(TypeRepr.of[C]) }.asInstanceOf[Gen[A :| C]] }.asExprOf[Gen[A :| C]] diff --git a/scalacheck/src/io/github/iltotore/iron/scalacheck/numeric.scala b/scalacheck/src/io/github/iltotore/iron/scalacheck/numeric.scala index 0a2dc22c..67520f35 100644 --- a/scalacheck/src/io/github/iltotore/iron/scalacheck/numeric.scala +++ b/scalacheck/src/io/github/iltotore/iron/scalacheck/numeric.scala @@ -9,10 +9,10 @@ import org.scalacheck.Gen.Choose object numeric: - inline given gt[A : Numeric : Choose, V1 <: A](using max: Max[A], adj: Adjacent[A]): Arbitrary[A :| Greater[V1]] = + inline given gt[A: Numeric: Choose, V1 <: A](using max: Max[A], adj: Adjacent[A]): Arbitrary[A :| Greater[V1]] = intervalArbitrary(adj.nextUp(constValue[V1]), max.value) - inline given gteq[A : Numeric: Choose, V1 <: A](using max: Max[A]): Arbitrary[A :| GreaterEqual[V1]] = + inline given gteq[A: Numeric: Choose, V1 <: A](using max: Max[A]): Arbitrary[A :| GreaterEqual[V1]] = intervalArbitrary(constValue[V1], max.value) inline given lt[A: Numeric: Choose, V1 <: A](using min: Min[A], adj: Adjacent[A]): Arbitrary[A :| Less[V1]] = @@ -20,18 +20,18 @@ object numeric: inline given lteq[A: Numeric: Choose, V1 <: A](using min: Min[A]): Arbitrary[A :| LessEqual[V1]] = intervalArbitrary(min.value, constValue[V1]) - - inline given closed[A : Numeric : Choose, V1 <: A, V2 <: A]: Arbitrary[A :| Interval.Closed[V1, V2]] = + + inline given closed[A: Numeric: Choose, V1 <: A, V2 <: A]: Arbitrary[A :| Interval.Closed[V1, V2]] = intervalArbitrary(constValue[V1], constValue[V2]) - inline given openClosed[A : Numeric : Choose, V1 <: A, V2 <: A](using adj: Adjacent[A]): Arbitrary[A :| Interval.OpenClosed[V1, V2]] = + inline given openClosed[A: Numeric: Choose, V1 <: A, V2 <: A](using adj: Adjacent[A]): Arbitrary[A :| Interval.OpenClosed[V1, V2]] = intervalArbitrary(adj.nextUp(constValue[V1]), constValue[V2]) - inline given closedOpen[A : Numeric : Choose, V1 <: A, V2 <: A](using adj: Adjacent[A]): Arbitrary[A :| Interval.ClosedOpen[V1, V2]] = + inline given closedOpen[A: Numeric: Choose, V1 <: A, V2 <: A](using adj: Adjacent[A]): Arbitrary[A :| Interval.ClosedOpen[V1, V2]] = intervalArbitrary(constValue[V1], adj.nextDown(constValue[V2])) - inline given open[A : Numeric : Choose, V1 <: A, V2 <: A](using adj: Adjacent[A]): Arbitrary[A :| Interval.Open[V1, V2]] = + inline given open[A: Numeric: Choose, V1 <: A, V2 <: A](using adj: Adjacent[A]): Arbitrary[A :| Interval.Open[V1, V2]] = intervalArbitrary(adj.nextUp(constValue[V1]), adj.nextDown(constValue[V2])) - def intervalArbitrary[A : Numeric : Choose, C](min: A, max: A): Arbitrary[A :| C] = - Arbitrary(Gen.chooseNum(min, max)).asInstanceOf \ No newline at end of file + def intervalArbitrary[A: Numeric: Choose, C](min: A, max: A): Arbitrary[A :| C] = + Arbitrary(Gen.chooseNum(min, max)).asInstanceOf diff --git a/scalacheck/src/io/github/iltotore/iron/scalacheck/string.scala b/scalacheck/src/io/github/iltotore/iron/scalacheck/string.scala index 0c49f8cd..fd6903aa 100644 --- a/scalacheck/src/io/github/iltotore/iron/scalacheck/string.scala +++ b/scalacheck/src/io/github/iltotore/iron/scalacheck/string.scala @@ -14,7 +14,7 @@ object string: Arbitrary(Gen.asciiStr.map(constValue[V] + _)).asInstanceOf inline given endWith[V <: String]: Arbitrary[String :| EndWith[V]] = Arbitrary(Gen.asciiStr.map(_ + constValue[V])).asInstanceOf - inline given minLength[V <: Int](using listArb: Arbitrary[List[Char] :| MinLength[V]]) : Arbitrary[String :| MinLength[V]] = reuseCollection + inline given minLength[V <: Int](using listArb: Arbitrary[List[Char] :| MinLength[V]]): Arbitrary[String :| MinLength[V]] = reuseCollection inline given maxLength[V <: Int](using listArb: Arbitrary[List[Char] :| MaxLength[V]]): Arbitrary[String :| MaxLength[V]] = reuseCollection inline given exactLength[V <: Int](using listArb: Arbitrary[List[Char] :| FixedLength[V]]): Arbitrary[String :| FixedLength[V]] = reuseCollection inline given emptyLength(using listArb: Arbitrary[List[Char] :| Empty]): Arbitrary[String :| Empty] = reuseCollection @@ -24,9 +24,9 @@ object string: inline given head[V](using listArb: Arbitrary[List[Char] :| Head[V]]): Arbitrary[String :| Head[V]] = reuseCollection inline given last[V](using listArb: Arbitrary[List[Char] :| Last[V]]): Arbitrary[String :| Last[V]] = reuseCollection inline given contain[V <: String](using stringArb: Arbitrary[String]): Arbitrary[String :| Contain[V]] = - Arbitrary(for { + Arbitrary(for prefix <- stringArb.arbitrary suffix <- stringArb.arbitrary - } yield prefix + constValue[V] + suffix).asInstanceOf - private inline def reuseCollection[C1, C2](using arb: Arbitrary[List[Char] :| C1]): Arbitrary[String :| C2] = - Arbitrary(arb.arbitrary.map(_.mkString(""))).asInstanceOf \ No newline at end of file + yield prefix + constValue[V] + suffix).asInstanceOf + private inline def reuseCollection[C1, C2](using arb: Arbitrary[List[Char] :| C1]): Arbitrary[String :| C2] = + Arbitrary(arb.arbitrary.map(_.mkString(""))).asInstanceOf diff --git a/scalacheck/test/src/io/github/iltotore/iron/scalacheck/AnySuite.scala b/scalacheck/test/src/io/github/iltotore/iron/scalacheck/AnySuite.scala index 4fab8f3c..16b987c6 100644 --- a/scalacheck/test/src/io/github/iltotore/iron/scalacheck/AnySuite.scala +++ b/scalacheck/test/src/io/github/iltotore/iron/scalacheck/AnySuite.scala @@ -8,8 +8,7 @@ import utest.* object AnySuite extends TestSuite: - val tests: Tests = Tests { + val tests: Tests = Tests: test("fallback") - testGen[Boolean, StrictEqual[true]] test("union") - testGen[Int, StrictEqual[1] | StrictEqual[2] | StrictEqual[3]] - } \ No newline at end of file diff --git a/scalacheck/test/src/io/github/iltotore/iron/scalacheck/CharSuite.scala b/scalacheck/test/src/io/github/iltotore/iron/scalacheck/CharSuite.scala index 4d711458..5ecba4e0 100644 --- a/scalacheck/test/src/io/github/iltotore/iron/scalacheck/CharSuite.scala +++ b/scalacheck/test/src/io/github/iltotore/iron/scalacheck/CharSuite.scala @@ -8,17 +8,16 @@ import utest.* object CharSuite extends TestSuite: - val tests: Tests = Tests { + val tests: Tests = Tests: test("whitespace") - testGen[Char, Whitespace] test("lowercase") - testGen[Char, LowerCase] - + test("uppercase") - testGen[Char, UpperCase] test("digit") - testGen[Char, Digit] - + test("letter") - testGen[Char, Letter] - + test("special") - testGen[Char, Special] - } diff --git a/scalacheck/test/src/io/github/iltotore/iron/scalacheck/CollectionSuite.scala b/scalacheck/test/src/io/github/iltotore/iron/scalacheck/CollectionSuite.scala index 063a9192..cfd920f2 100644 --- a/scalacheck/test/src/io/github/iltotore/iron/scalacheck/CollectionSuite.scala +++ b/scalacheck/test/src/io/github/iltotore/iron/scalacheck/CollectionSuite.scala @@ -10,45 +10,35 @@ import utest.* object CollectionSuite extends TestSuite: val tests: Tests = Tests { - test("minLength") { + test("minLength"): test("seq") - testGen[Seq[Boolean], MinLength[5]] test("string") - testGen[String, MinLength[5]] - } - test("maxLength") { + test("maxLength"): test("seq") - testGen[Seq[Boolean], MaxLength[5]] test("string") - testGen[String, MaxLength[5]] - } - test("exactLength") { + test("exactLength"): test("seq") - testGen[Seq[Boolean], FixedLength[5]] test("string") - testGen[String, FixedLength[5]] - } - test("empty") { + test("empty"): test("seq") - testGen[Seq[Boolean], Empty] test("string") - testGen[String, Empty] test("not empty") - testGen[Seq[Boolean], Not[Empty]] - } - test("contain") { + test("contain"): test("seq") - testGen[Seq[Boolean], Contain[true]] test("string") - testGen[String, Contain["a"]] - } - test("forAll") { + test("forAll"): test("seq") - testGen[Seq[Boolean], ForAll[StrictEqual[true]]] test("string") - testGen[String, ForAll[StrictEqual['a']]] - } - test("init") { + test("init"): test("seq") - testGen[Seq[Boolean], Init[StrictEqual[true]]] test("string") - testGen[String, Init[StrictEqual['a']]] - } - test("tail") { + test("tail"): test("seq") - testGen[Seq[Boolean], Tail[StrictEqual[true]]] test("string") - testGen[String, Tail[StrictEqual['a']]] - } - test("head") { + test("head"): test("seq") - testGen[Seq[Boolean], Head[StrictEqual[true]]] test("string") - testGen[String, Head[StrictEqual['a']]] - } - test("last") { + test("last"): test("seq") - testGen[Seq[Boolean], Last[StrictEqual[true]]] test("string") - testGen[String, Last[StrictEqual['a']]] - } - } \ No newline at end of file + } diff --git a/scalacheck/test/src/io/github/iltotore/iron/scalacheck/ImplicitsOrderingSuite.scala b/scalacheck/test/src/io/github/iltotore/iron/scalacheck/ImplicitsOrderingSuite.scala index 8c6bc213..6d20d4a4 100644 --- a/scalacheck/test/src/io/github/iltotore/iron/scalacheck/ImplicitsOrderingSuite.scala +++ b/scalacheck/test/src/io/github/iltotore/iron/scalacheck/ImplicitsOrderingSuite.scala @@ -6,6 +6,5 @@ import utest.* object ImplicitsOrderingSuite extends TestSuite: - val tests: Tests = Tests { + val tests: Tests = Tests: test("should resolve implicits using all.given import") - testGen[String, Empty] - } diff --git a/scalacheck/test/src/io/github/iltotore/iron/scalacheck/NumericSuite.scala b/scalacheck/test/src/io/github/iltotore/iron/scalacheck/NumericSuite.scala index c1856ada..bf293a1d 100644 --- a/scalacheck/test/src/io/github/iltotore/iron/scalacheck/NumericSuite.scala +++ b/scalacheck/test/src/io/github/iltotore/iron/scalacheck/NumericSuite.scala @@ -11,68 +11,59 @@ object NumericSuite extends TestSuite: val tests: Tests = Tests { - test("greater") { + test("greater"): test("int") - testGen[Int, Greater[5]] test("long") - testGen[Long, Greater[5L]] test("float") - testGen[Float, Greater[5f]] test("double") - testGen[Double, Greater[5d]] - } - test("greaterEqual") { + test("greaterEqual"): test("int") - testGen[Int, GreaterEqual[5]] test("long") - testGen[Long, GreaterEqual[5L]] test("float") - testGen[Float, GreaterEqual[5f]] test("double") - testGen[Double, GreaterEqual[5d]] - } - test("less") { + test("less"): test("int") - testGen[Int, Less[5]] test("long") - testGen[Long, Less[5L]] test("float") - testGen[Float, Less[5f]] test("double") - testGen[Double, Less[5d]] - } - test("lessEqual") { + test("lessEqual"): test("int") - testGen[Int, LessEqual[5]] test("long") - testGen[Long, LessEqual[5L]] test("float") - testGen[Float, LessEqual[5f]] test("double") - testGen[Double, LessEqual[5d]] - } - test("strictEqual") { + test("strictEqual"): test("int") - testGen[Int, StrictEqual[5]] test("long") - testGen[Long, StrictEqual[5L]] test("float") - testGen[Float, StrictEqual[5f]] test("double") - testGen[Double, StrictEqual[5d]] - } test("interval") { - test("open") { + test("open"): test("int") - testGen[Int, Interval.Open[0, 5]] test("long") - testGen[Long, Interval.Open[0L, 5L]] test("float") - testGen[Float, Interval.Open[0f, 5f]] test("double") - testGen[Double, Interval.Open[0d, 5d]] - } - test("openClosed") { + test("openClosed"): test("int") - testGen[Int, Interval.OpenClosed[0, 5]] test("long") - testGen[Long, Interval.OpenClosed[0L, 5L]] test("float") - testGen[Float, Interval.OpenClosed[0f, 5f]] test("double") - testGen[Double, Interval.OpenClosed[0d, 5d]] - } - test("closedOpen") { + test("closedOpen"): test("int") - testGen[Int, Interval.ClosedOpen[0, 5]] test("long") - testGen[Long, Interval.ClosedOpen[0L, 5L]] test("float") - testGen[Float, Interval.ClosedOpen[0f, 5f]] test("double") - testGen[Double, Interval.ClosedOpen[0d, 5d]] - } - test("closed") { + test("closed"): test("int") - testGen[Int, Interval.Closed[0, 5]] test("long") - testGen[Long, Interval.Closed[0L, 5L]] test("float") - testGen[Float, Interval.Closed[0f, 5f]] test("double") - testGen[Double, Interval.Closed[0d, 5d]] - } } } diff --git a/scalacheck/test/src/io/github/iltotore/iron/scalacheck/StringSuite.scala b/scalacheck/test/src/io/github/iltotore/iron/scalacheck/StringSuite.scala index 0f8e6ca4..b7ecfbac 100644 --- a/scalacheck/test/src/io/github/iltotore/iron/scalacheck/StringSuite.scala +++ b/scalacheck/test/src/io/github/iltotore/iron/scalacheck/StringSuite.scala @@ -9,8 +9,7 @@ import utest.* object StringSuite extends TestSuite: - val tests: Tests = Tests { + val tests: Tests = Tests: test("startWith") - testGen[String, StartWith["abc"]] test("endWith") - testGen[String, EndWith["abc"]] test("not empty string") - testGen[String, Not[Empty]] - } diff --git a/scalacheck/test/src/io/github/iltotore/iron/scalacheck/package.scala b/scalacheck/test/src/io/github/iltotore/iron/scalacheck/package.scala index 8f40f9da..2b9e57b2 100644 --- a/scalacheck/test/src/io/github/iltotore/iron/scalacheck/package.scala +++ b/scalacheck/test/src/io/github/iltotore/iron/scalacheck/package.scala @@ -16,4 +16,4 @@ inline def testGen[A, C](using inline arb: Arbitrary[A :| C], inline constraint: throw AssertionError(s"Some constrained values failed for ${constraint.message}", getTestValues(args)) case Test.Exhausted => throw new java.lang.AssertionError("Exhausted") case Test.PropException(args, e, _) => - throw AssertionError(s"An error occurred for ${constraint.message}", getTestValues(args), e) \ No newline at end of file + throw AssertionError(s"An error occurred for ${constraint.message}", getTestValues(args), e) diff --git a/skunk/test/src/io/github/iltotore/iron/SkunkSuite.scala b/skunk/test/src/io/github/iltotore/iron/SkunkSuite.scala index e7552678..d8b77850 100644 --- a/skunk/test/src/io/github/iltotore/iron/SkunkSuite.scala +++ b/skunk/test/src/io/github/iltotore/iron/SkunkSuite.scala @@ -19,39 +19,30 @@ object SkunkSuite extends TestSuite: val tests: Tests = Tests { - test("codec") { - test("ironType") { + test("codec"): + test("ironType"): test("success") - assert(summon[Codec[Int :| Positive]].decode(0, List(Some("5"))) == Right(5)) test("failure") - assert(summon[Codec[Int :| Positive]].decode(0, List(Some("-5"))).isLeft) test("success") - assert(summon[Codec[Int :| Positive]].encode(5) == List(Some("5"))) - } - test("newType") { + test("newType"): test("success") - assert(summon[Codec[PositiveInt]].decode(0, List(Some("5"))) == Right(PositiveInt(5))) test("failure") - assert(summon[Codec[PositiveInt]].decode(0, List(Some("-5"))).isLeft) test("success") - assert(summon[Codec[PositiveInt]].encode(PositiveInt(5)) == List(Some("5"))) - } - } - test("encoder") { - test("ironType") { + test("encoder"): + test("ironType"): test("success") - assert(summon[Encoder[Int :| Positive]].encode(5) == List(Some("5"))) - } - test("newType") { + test("newType"): test("success") - assert(summon[Encoder[PositiveInt]].encode(PositiveInt(5)) == List(Some("5"))) - } - } - test("decoder") { - test("ironType") { + test("decoder"): + test("ironType"): test("success") - assert(summon[Decoder[Int :| Positive]].decode(0, List(Some("5"))) == Right(PositiveInt(5))) test("failure") - assert(summon[Decoder[Int :| Positive]].decode(0, List(Some("-5"))).isLeft) - } - test("newType") { + test("newType"): test("success") - assert(summon[Decoder[PositiveInt]].decode(0, List(Some("5"))) == Right(PositiveInt(5))) test("failure") - assert(summon[Decoder[PositiveInt]].decode(0, List(Some("-5"))).isLeft) - } - } } diff --git a/upickle/src/io/github/iltotore/iron/upickle.scala b/upickle/src/io/github/iltotore/iron/upickle.scala index 23733c57..5e29c911 100644 --- a/upickle/src/io/github/iltotore/iron/upickle.scala +++ b/upickle/src/io/github/iltotore/iron/upickle.scala @@ -17,10 +17,9 @@ object upickle: */ inline given [A, B](using inline reader: Reader[A], inline constraint: Constraint[A, B]): Reader[A :| B] = reader.map(value => - value.refineEither match { + value.refineEither match case Right(refinedValue) => refinedValue - case Left(errorMessage) => throw Abort(errorMessage) - } + case Left(errorMessage) => throw Abort(errorMessage) ) /** @@ -36,7 +35,7 @@ object upickle: * @param mirror the type mirror for refined types. * @param ev the underlying `Reader` for the iron type. */ - inline given[T](using mirror: RefinedTypeOps.Mirror[T], ev: Reader[mirror.IronType]): Reader[T] = + inline given [T](using mirror: RefinedTypeOps.Mirror[T], ev: Reader[mirror.IronType]): Reader[T] = ev.asInstanceOf[Reader[T]] /** @@ -45,5 +44,5 @@ object upickle: * @param mirror the type mirror for refined types. * @param ev the underlying `Writer` for the iron type. */ - inline given[T](using mirror: RefinedTypeOps.Mirror[T], ev: Writer[mirror.IronType]): Writer[T] = + inline given [T](using mirror: RefinedTypeOps.Mirror[T], ev: Writer[mirror.IronType]): Writer[T] = ev.asInstanceOf[Writer[T]] diff --git a/upickle/test/src/io/github/iltotore/iron/uPickleSuite.scala b/upickle/test/src/io/github/iltotore/iron/uPickleSuite.scala index b105528d..1e2f618f 100644 --- a/upickle/test/src/io/github/iltotore/iron/uPickleSuite.scala +++ b/upickle/test/src/io/github/iltotore/iron/uPickleSuite.scala @@ -10,27 +10,20 @@ import scala.util.Try import utest.* - object uPickleSuite extends TestSuite: import scala.runtime.stdLibPatches.Predef.summon - val tests: Tests = Tests { + val tests: Tests = Tests: - test("reader") { - test("ironType") { + test("reader"): + test("ironType"): test("success") - assert(Try(read[Int :| Positive]("10")).isSuccess) test("failure") - assert(Try(read[Int :| Positive]("-10")).isFailure) - } - } - test("writer") { - test("ironType") { + test("writer"): + test("ironType"): val p: Int :| Positive = 10 test("success") - assert(write(p) == "10") - } - } - } - end uPickleSuite diff --git a/zio/src/io/github/iltotore/iron/zio.scala b/zio/src/io/github/iltotore/iron/zio.scala index 3cb6b636..9d731a65 100644 --- a/zio/src/io/github/iltotore/iron/zio.scala +++ b/zio/src/io/github/iltotore/iron/zio.scala @@ -34,7 +34,7 @@ object zio extends RefinedTypeOpsZio: */ def validation(value: A): Validation[String, T] = Validation.fromPredicateWith(ops.rtc.message)(value)(ops.rtc.test(_)).asInstanceOf[Validation[String, T]] - + given [F[+_]](using covariant: Covariant[F]): MapLogic[F] with override def map[A, B](wrapper: F[A], f: A => B): F[B] = covariant.map(f)(wrapper) diff --git a/zio/test/src/io/github/iltotore/iron/ZIOSuite.scala b/zio/test/src/io/github/iltotore/iron/ZIOSuite.scala index 89e54c88..29065b57 100644 --- a/zio/test/src/io/github/iltotore/iron/ZIOSuite.scala +++ b/zio/test/src/io/github/iltotore/iron/ZIOSuite.scala @@ -10,19 +10,16 @@ import _root_.zio.Chunk import _root_.zio.NonEmptyChunk object ZIOSuite extends TestSuite: - val tests: Tests = Tests { + val tests: Tests = Tests: - test("ZIO validation") { + test("ZIO validation"): assert(Temperature.validation(2.0) == ZValidation.Success[String, Temperature](Chunk.empty, Temperature(2.0))) assert( Temperature.validation(0.0) == ZValidation.Failure[String, String](Chunk.empty, NonEmptyChunk.single("Should be strictly positive")) ) - } - test("refineAll") { + test("refineAll"): test - assert(Temperature.optionAll(NonEmptyChunk(1, 2, 3)).contains(NonEmptyChunk(Temperature(1), Temperature(2), Temperature(3)))) test - assert(Temperature.optionAll(NonEmptyChunk(1, 2, -3)).isEmpty) - } - } diff --git a/zioJson/src/io/github/iltotore/iron/zioJson.scala b/zioJson/src/io/github/iltotore/iron/zioJson.scala index 0ad3c392..921027e4 100644 --- a/zioJson/src/io/github/iltotore/iron/zioJson.scala +++ b/zioJson/src/io/github/iltotore/iron/zioJson.scala @@ -10,8 +10,8 @@ object zioJson: inline given [A, C](using inline encoder: JsonEncoder[A]): JsonEncoder[A :| C] = encoder.asInstanceOf[JsonEncoder[A :| C]] - inline given[T](using mirror: RefinedTypeOps.Mirror[T], ev: JsonDecoder[mirror.IronType]): JsonDecoder[T] = + inline given [T](using mirror: RefinedTypeOps.Mirror[T], ev: JsonDecoder[mirror.IronType]): JsonDecoder[T] = ev.asInstanceOf[JsonDecoder[T]] - inline given[T](using mirror: RefinedTypeOps.Mirror[T], ev: JsonEncoder[mirror.IronType]): JsonEncoder[T] = - ev.asInstanceOf[JsonEncoder[T]] \ No newline at end of file + inline given [T](using mirror: RefinedTypeOps.Mirror[T], ev: JsonEncoder[mirror.IronType]): JsonEncoder[T] = + ev.asInstanceOf[JsonEncoder[T]]