Skip to content

Commit

Permalink
Showcase failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Igosuki committed May 7, 2019
1 parent b5727a8 commit 648ab74
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ lazy val tests = project
// Specifically to import XML stuff that got modularised
"javax.xml.bind" % "jaxb-api" % "2.3.0" % "compile",
"com.sun.xml.bind" % "jaxb-impl" % "2.3.0" % "compile",
"io.circe" %% "circe-core" % "0.9.3"
"io.circe" %% "circe-core" % "0.11.1"
)
)
.dependsOn(examplesJVM)
Expand Down
43 changes: 43 additions & 0 deletions tests/src/main/scala/CirceListTypeTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import estrapade.{TestApp, test}

import language.experimental.macros
import MagnoliaEncoder.genEncoder
import io.circe.Encoder

case class Recursive(field: Int, recursion: List[Recursive])

/**
* Problem here is that we expect the same behaviour as shapeless Lazy provides -
* the derived codec itself would be visible and used to construct the codec for List using circe std one.
* Magnolia doesn't see it and derives coproduct codec for List instead, which doesn't look nice for json API:
* {{{
* {
* "::" : {
* "head" : {
* "field" : 2,
* "recursion" : {
* "Nil" : "Nil"
* }
* },
* "tl$access$1" : {
* "Nil" : "Nil"
* }
* }
* }
* }
* }}}
*/
object CirceRecursiveTypeTest extends TestApp {

def tests(): Unit = {

val encoderl = Encoder[List[Recursive]]
test("Use available encoders for an immutable list") {
encoderl(List(Recursive(1, List(Recursive(2, Nil), Recursive(3, Nil)))))
}
.assert(
j => j.asArray.isDefined,
_.toString()
)
}
}
8 changes: 8 additions & 0 deletions tests/src/main/scala/CirceRecursiveTypeTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,13 @@ object CirceRecursiveTypeTest extends TestApp {
j => j.asObject.flatMap(_ ("recursion")).exists(_.isArray),
_.toString()
)
val encoderl = Encoder[List[Recursive]]
test("Use available encoders for an immutable list") {
encoderl(List(Recursive(1, List(Recursive(2, Nil), Recursive(3, Nil)))))
}
.assert(
j => j.asArray.isDefined,
_.toString()
)
}
}

0 comments on commit 648ab74

Please sign in to comment.