From 86c66ba93b5dc15301ac305fa28e24952e232613 Mon Sep 17 00:00:00 2001 From: Jon Pretty Date: Mon, 30 Oct 2017 13:58:33 +0100 Subject: All variants now deriving Though there's a stack overflow when trying to derive a `Decoder`. --- tests/src/main/scala/main.scala | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/src/main/scala/main.scala b/tests/src/main/scala/main.scala index 7dee065..99ffe56 100644 --- a/tests/src/main/scala/main.scala +++ b/tests/src/main/scala/main.scala @@ -11,6 +11,7 @@ import scala.util._ object Tests extends TestApp { def tests() = { + import examples._ test("construct a Show product instance") { import examples._ @@ -42,40 +43,46 @@ object Tests extends TestApp { Eq.generic[Tree].equal(Branch(Leaf("one"), Leaf("two")), Branch(Leaf("one"), Leaf("two"))) }.assert(_ == true) - /*test("construction of Show instance for Leaf") { + test("construct a default value") { + Default.generic[Entity].default + }.assert(_ == (Company(""): Entity)) + + test("construction of Show instance for Leaf") { scalac""" import magnolia.examples._ implicitly[Show[Leaf]] """ - }.assert(_ == Returns(fqt"magnolia.examples.Show[magnolia.examples.Leaf]")) + }.assert(_ == (Returns(fqt"magnolia.examples.Show[magnolia.examples.Leaf]"): Compilation)) test("construction of Show instance for Tree") { scalac""" import magnolia.examples._ implicitly[Show[Tree]] """ - }.assert(_ == Returns(fqt"magnolia.examples.Show[magnolia.examples.Tree]")) + }.assert(_ == (Returns(fqt"magnolia.examples.Show[magnolia.examples.Tree]"): Compilation)) test("serialize a Leaf") { - import magnolia.examples._ implicitly[Show[Leaf]].show(Leaf("testing")) }.assert(_ == "{value=testing}") test("serialize a Branch as a Tree") { - import magnolia.examples._ implicitly[Show[Tree]].show(Branch(Leaf("LHS"), Leaf("RHS"))) }.assert(_ == "{left={value=LHS},right={value=RHS}}") + /*test("construct a decoder") { + Decoder.generic[Tree].decode("string") + }.assert(_ == (Leaf("something"): Tree))*/ + test("show error stack") { scalac""" import magnolia.examples._ - case class Alpha(integer: Int) + case class Alpha(integer: Double) case class Beta(alpha: Alpha) Show.generic[Beta] """ - }.assert(_ == TypecheckError(txt"""magnolia: could not find typeclass for type Int + }.assert(_ == (TypecheckError(txt"""magnolia: could not find typeclass for type Double | in parameter 'integer' of product type Alpha | in parameter 'alpha' of product type Beta - |"""))*/ + |"""): Compilation)) } } -- cgit v1.2.3