From 979fb5dfc12d9f492a8a378b9b6d958692b296ad Mon Sep 17 00:00:00 2001 From: Mateusz Kubuszok Date: Tue, 8 Oct 2024 17:26:04 +0200 Subject: [PATCH] Add tests for .everyItem in OuterTransformers without nesting --- .../PartialTransformerIntegrationsSpec.scala | 58 ++++++++++++++----- .../TotalTransformerIntegrationsSpec.scala | 5 ++ 2 files changed, 47 insertions(+), 16 deletions(-) diff --git a/chimney/src/test/scala/io/scalaland/chimney/PartialTransformerIntegrationsSpec.scala b/chimney/src/test/scala/io/scalaland/chimney/PartialTransformerIntegrationsSpec.scala index 47c067d0c..06407620a 100644 --- a/chimney/src/test/scala/io/scalaland/chimney/PartialTransformerIntegrationsSpec.scala +++ b/chimney/src/test/scala/io/scalaland/chimney/PartialTransformerIntegrationsSpec.scala @@ -13,51 +13,77 @@ class PartialTransformerIntegrationsSpec extends ChimneySpec { test("transform using TotalOuterTransformer") { import OuterTransformers.totalNonEmptyToSorted + val result = NonEmptyWrapper("b", "a").transformIntoPartial[SortedWrapper[String]] + result.asOption ==> Some(SortedWrapper("a", "b")) + result.asEither ==> Right(SortedWrapper("a", "b")) + result.asErrorPathMessageStrings ==> Iterable.empty + implicit val barOrdering: Ordering[Bar] = Ordering[String].on[Bar](_.value) - val result = NonEmptyWrapper(Foo("b"), Foo("a")).transformIntoPartial[SortedWrapper[Bar]] - result.asOption ==> Some(SortedWrapper(Bar("a"), Bar("b"))) - result.asEither ==> Right(SortedWrapper(Bar("a"), Bar("b"))) - result.asErrorPathMessageStrings ==> Iterable.empty + val result2 = NonEmptyWrapper(Foo("b"), Foo("a")).transformIntoPartial[SortedWrapper[Bar]] + result2.asOption ==> Some(SortedWrapper(Bar("a"), Bar("b"))) + result2.asEither ==> Right(SortedWrapper(Bar("a"), Bar("b"))) + result2.asErrorPathMessageStrings ==> Iterable.empty } test("transform using TotalOuterTransformer with an override") { import OuterTransformers.totalNonEmptyToSorted + val result = NonEmptyWrapper("b", "a") + .intoPartial[SortedWrapper[String]] + .withFieldConst(_.everyItem, "c") + .transform + result.asOption ==> Some(SortedWrapper("c")) + result.asEither ==> Right(SortedWrapper("c")) + result.asErrorPathMessageStrings ==> Iterable.empty + implicit val barOrdering: Ordering[Bar] = Ordering[String].on[Bar](_.value) - val result = NonEmptyWrapper(Foo("b"), Foo("a")) + val result2 = NonEmptyWrapper(Foo("b"), Foo("a")) .intoPartial[SortedWrapper[Bar]] .withFieldConst(_.everyItem.value, "c") .transform - result.asOption ==> Some(SortedWrapper(Bar("c"))) - result.asEither ==> Right(SortedWrapper(Bar("c"))) - result.asErrorPathMessageStrings ==> Iterable.empty + result2.asOption ==> Some(SortedWrapper(Bar("c"))) + result2.asEither ==> Right(SortedWrapper(Bar("c"))) + result2.asErrorPathMessageStrings ==> Iterable.empty } test("transform using PartialOuterTransformer") { import OuterTransformers.partialNonEmptyToSorted + val result = NonEmptyWrapper("b", "a").transformIntoPartial[SortedWrapper[String]] + result.asOption ==> Some(SortedWrapper("a", "b")) + result.asEither ==> Right(SortedWrapper("a", "b")) + result.asErrorPathMessageStrings ==> Iterable.empty + implicit val barOrdering: Ordering[Bar] = Ordering[String].on[Bar](_.value) - val result = NonEmptyWrapper(Foo("b"), Foo("a")).transformIntoPartial[SortedWrapper[Bar]] - result.asOption ==> Some(SortedWrapper(Bar("a"), Bar("b"))) - result.asEither ==> Right(SortedWrapper(Bar("a"), Bar("b"))) - result.asErrorPathMessageStrings ==> Iterable.empty + val result2 = NonEmptyWrapper(Foo("b"), Foo("a")).transformIntoPartial[SortedWrapper[Bar]] + result2.asOption ==> Some(SortedWrapper(Bar("a"), Bar("b"))) + result2.asEither ==> Right(SortedWrapper(Bar("a"), Bar("b"))) + result2.asErrorPathMessageStrings ==> Iterable.empty } test("transform using PartialOuterTransformer with an override") { import OuterTransformers.partialNonEmptyToSorted + val result = NonEmptyWrapper("b", "a") + .intoPartial[SortedWrapper[String]] + .withFieldConst(_.everyItem, "c") + .transform + result.asOption ==> Some(SortedWrapper("c")) + result.asEither ==> Right(SortedWrapper("c")) + result.asErrorPathMessageStrings ==> Iterable.empty + implicit val barOrdering: Ordering[Bar] = Ordering[String].on[Bar](_.value) - val result = NonEmptyWrapper(Foo("b"), Foo("a")) + val result2 = NonEmptyWrapper(Foo("b"), Foo("a")) .intoPartial[SortedWrapper[Bar]] .withFieldConst(_.everyItem.value, "c") .transform - result.asOption ==> Some(SortedWrapper(Bar("c"))) - result.asEither ==> Right(SortedWrapper(Bar("c"))) - result.asErrorPathMessageStrings ==> Iterable.empty + result2.asOption ==> Some(SortedWrapper(Bar("c"))) + result2.asEither ==> Right(SortedWrapper(Bar("c"))) + result2.asErrorPathMessageStrings ==> Iterable.empty } test("transform using PartialOuterTransformer resolving total-partial-conflict") { diff --git a/chimney/src/test/scala/io/scalaland/chimney/TotalTransformerIntegrationsSpec.scala b/chimney/src/test/scala/io/scalaland/chimney/TotalTransformerIntegrationsSpec.scala index b2585f51d..25c5a438c 100644 --- a/chimney/src/test/scala/io/scalaland/chimney/TotalTransformerIntegrationsSpec.scala +++ b/chimney/src/test/scala/io/scalaland/chimney/TotalTransformerIntegrationsSpec.scala @@ -17,6 +17,7 @@ class TotalTransformerIntegrationsSpec extends ChimneySpec { implicit val barOrdering: Ordering[Bar] = Ordering[String].on[Bar](_.value) + NonEmptyWrapper("b", "a").transformInto[SortedWrapper[String]] ==> SortedWrapper("a", "b") NonEmptyWrapper(Foo("b"), Foo("a")).transformInto[SortedWrapper[Bar]] ==> SortedWrapper(Bar("a"), Bar("b")) } @@ -25,6 +26,10 @@ class TotalTransformerIntegrationsSpec extends ChimneySpec { implicit val barOrdering: Ordering[Bar] = Ordering[String].on[Bar](_.value) + NonEmptyWrapper("b", "a") + .into[SortedWrapper[String]] + .withFieldConst(_.everyItem, "c") + .transform ==> SortedWrapper("c") NonEmptyWrapper(Foo("b"), Foo("a")) .into[SortedWrapper[Bar]] .withFieldConst(_.everyItem.value, "c")