From 33771a9df35e77ac3c0ff8367bafaa17f2e71038 Mon Sep 17 00:00:00 2001 From: Jesse Bakker Date: Fri, 19 May 2023 15:25:03 +0200 Subject: [PATCH] Add tests for generically deriving schemas for enums --- .../test/scala/zio/schema/DeriveSchemaSpec.scala | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/zio-schema-derivation/shared/src/test/scala/zio/schema/DeriveSchemaSpec.scala b/zio-schema-derivation/shared/src/test/scala/zio/schema/DeriveSchemaSpec.scala index 1f2316e4b..7f35b9b7d 100644 --- a/zio-schema-derivation/shared/src/test/scala/zio/schema/DeriveSchemaSpec.scala +++ b/zio-schema-derivation/shared/src/test/scala/zio/schema/DeriveSchemaSpec.scala @@ -77,12 +77,6 @@ object DeriveSchemaSpec extends ZIOSpecDefault with VersionSpecificDeriveSchemaS implicit lazy val schema: Schema[Recursive] = DeriveSchema.gen[Recursive] } - case class GenericType[T](t: T) - - object GenericType { - implicit def schema[T: Schema]: Schema[GenericType[T]] = DeriveSchema.gen[GenericType[T]] - } - case class Cyclic(field1: Long, child: CyclicChild1) object Cyclic { @@ -171,6 +165,8 @@ object DeriveSchemaSpec extends ZIOSpecDefault with VersionSpecificDeriveSchemaS case class Branch[A](left: Tree[A], right: Tree[A]) extends Tree[A] case class Leaf[A](value: A) extends Tree[A] case object Root extends Tree[Nothing] + + implicit def schema[A: Schema]: Schema[Tree[A]] = DeriveSchema.gen[Tree[A]] } sealed trait RBTree[+A, +B] @@ -179,6 +175,8 @@ object DeriveSchemaSpec extends ZIOSpecDefault with VersionSpecificDeriveSchemaS case class Branch[A, B](left: RBTree[A, B], right: RBTree[A, B]) extends RBTree[A, B] case class RLeaf[A](value: A) extends RBTree[A, Nothing] case class BLeaf[B](value: B) extends RBTree[Nothing, B] + + implicit def schema[A: Schema, B: Schema]: Schema[RBTree[A, B]] = DeriveSchema.gen[RBTree[A, B]] } @annotation1("enum") sealed trait AnnotatedEnum @@ -393,10 +391,16 @@ object DeriveSchemaSpec extends ZIOSpecDefault with VersionSpecificDeriveSchemaS val derived: Schema[Tree[Recursive]] = DeriveSchema.gen[Tree[Recursive]] assert(derived)(anything) }, + test("correctly derives generic recursive Enum") { + assert(Schema[Tree[Recursive]].toString)(not(containsString("null")) && not(equalTo("$Lazy$"))) + }, test("correctly derives recursive Enum with multiple type parameters") { val derived: Schema[RBTree[String, Int]] = DeriveSchema.gen[RBTree[String, Int]] assert(derived)(anything) }, + test("correctly derives generic recursive Enum with multiple type parameters") { + assert(Schema[RBTree[String, Int]].toString)(not(containsString("null")) && not(equalTo("$Lazy$"))) + }, test("correctly derives recursive Enum") { assert(Schema[RecursiveEnum].toString)(not(containsString("null")) && not(equalTo("$Lazy$"))) },