Skip to content

Commit

Permalink
Add tests for generically deriving schemas for enums
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesse-Bakker committed Jul 31, 2023
1 parent 85d4fd4 commit 33771a9
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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]
Expand All @@ -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
Expand Down Expand Up @@ -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$")))
},
Expand Down

0 comments on commit 33771a9

Please sign in to comment.