diff options
author | Jakob Odersky <jakob@odersky.com> | 2018-02-14 12:17:15 -0800 |
---|---|---|
committer | Jakob Odersky <jakob@odersky.com> | 2018-02-14 12:17:15 -0800 |
commit | eada4c48b3954241e130f5d9b5e7feebe8c1e3f2 (patch) | |
tree | d017b30fb264b0560cbf7df3540f26e705da8ec0 /src/test/scala/CoproductTypeFormats.scala | |
parent | af6845cc08ae223ad67ebad61559d8264fd3346b (diff) | |
download | spray-json-derivation-eada4c48b3954241e130f5d9b5e7feebe8c1e3f2.tar.gz spray-json-derivation-eada4c48b3954241e130f5d9b5e7feebe8c1e3f2.tar.bz2 spray-json-derivation-eada4c48b3954241e130f5d9b5e7feebe8c1e3f2.zip |
Prepare for releasing
Diffstat (limited to 'src/test/scala/CoproductTypeFormats.scala')
-rw-r--r-- | src/test/scala/CoproductTypeFormats.scala | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/test/scala/CoproductTypeFormats.scala b/src/test/scala/CoproductTypeFormats.scala new file mode 100644 index 0000000..f16e4c7 --- /dev/null +++ b/src/test/scala/CoproductTypeFormats.scala @@ -0,0 +1,58 @@ +package xyz.driver.json + +import spray.json._ + +import org.scalatest._ + +class CoproductTypeFormats + extends FlatSpec + with FormatTests + with DefaultJsonProtocol + with DerivedFormats { + + sealed trait Expr + case class Zero() extends Expr + case class Value(x: Int) extends Expr + case class Plus(lhs: Expr, rhs: Expr) extends Expr + case object One extends Expr + + "No-parameter case class child" should behave like checkCoherence[Expr]( + Zero(), + """{"type":"Zero"}""" + ) + + "Simple parameter case class child" should behave like checkCoherence[Expr]( + Value(42), + """{"type":"Value","x":42}""" + ) + + "Nested parameter case class child" should behave like checkCoherence[Expr]( + Plus(Value(42), Value(0)), + """{"type":"Plus","lhs":{"type":"Value","x":42},"rhs":{"type":"Value","x":0}}""" + ) + + // "Case object child" should behave like checkCoherence[Expr]( + // One, + // """{"type":"One"}""" + // ) + + @gadt("kind") + sealed abstract class Keyword(`type`: String) + case class If(`type`: String) extends Keyword(`type`) + + "GADT with type field alias" should behave like checkCoherence[Keyword]( + If("class"), + """{"kind":"If","type":"class"}""" + ) + + @enum + sealed trait Enum + case object A extends Enum + case object B extends Enum + + "Enum" should behave like checkCoherence[List[Enum]]( + A :: B :: Nil, + """["A", "B"]""" + ) + +} |