From 3f23cb5bca4ea8be889b714008a85141fe5e213c Mon Sep 17 00:00:00 2001 From: Jon Pretty Date: Wed, 8 Nov 2017 11:17:53 +0000 Subject: Added better scaladocs and provide default values --- tests/src/main/scala/tests.scala | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'tests') diff --git a/tests/src/main/scala/tests.scala b/tests/src/main/scala/tests.scala index 06ccd30..14345af 100644 --- a/tests/src/main/scala/tests.scala +++ b/tests/src/main/scala/tests.scala @@ -18,6 +18,8 @@ case class Company(name: String) extends Entity case class Person(name: String, age: Int) extends Entity case class Address(line1: String, occupant: Person) +case class Item(name: String, quantity: Int = 1, price: Int) + sealed trait Color case object Red extends Color case object Green extends Color @@ -25,41 +27,41 @@ case object Blue extends Color object Tests extends TestApp { - def tests() = for(i <- 1 to 10000) { + def tests() = for(i <- 1 to 1000) { import examples._ test("construct a Show product instance") { import examples._ - Show.generic[Person].show(Person("John Smith", 34)) + Show.gen[Person].show(Person("John Smith", 34)) }.assert(_ == """Person(name=John Smith,age=34)""") test("construct a Show coproduct instance") { import examples._ - Show.generic[Person].show(Person("John Smith", 34)) + Show.gen[Person].show(Person("John Smith", 34)) }.assert(_ == "Person(name=John Smith,age=34)") test("serialize a Branch") { import magnolia.examples._ implicitly[Show[String, Branch[String]]].show(Branch(Leaf("LHS"), Leaf("RHS"))) - }.assert(_ == "Branch[String](left=Leaf[String](value=LHS),right=Leaf[String](value=RHS))") + }.assert(_ == "Branch(left=Leaf(value=LHS),right=Leaf(value=RHS))") test("test equality false") { import examples._ - Eq.generic[Entity].equal(Person("John Smith", 34), Person("", 0)) + Eq.gen[Entity].equal(Person("John Smith", 34), Person("", 0)) }.assert(_ == false) test("test equality true") { import examples._ - Eq.generic[Entity].equal(Person("John Smith", 34), Person("John Smith", 34)) + Eq.gen[Entity].equal(Person("John Smith", 34), Person("John Smith", 34)) }.assert(_ == true) test("test branch equality true") { import examples._ - Eq.generic[Tree[String]].equal(Branch(Leaf("one"), Leaf("two")), Branch(Leaf("one"), Leaf("two"))) + Eq.gen[Tree[String]].equal(Branch(Leaf("one"), Leaf("two")), Branch(Leaf("one"), Leaf("two"))) }.assert(_ == true) test("construct a default value") { - Default.generic[Entity].default + Default.gen[Entity].default }.assert(_ == Company("")) test("construction of Show instance for Leaf") { @@ -78,16 +80,20 @@ object Tests extends TestApp { test("serialize a Leaf") { implicitly[Show[String, Leaf[String]]].show(Leaf("testing")) - }.assert(_ == "Leaf[String](value=testing)") + }.assert(_ == "Leaf(value=testing)") test("serialize a Branch as a Tree") { implicitly[Show[String, Tree[String]]].show(Branch(Leaf("LHS"), Leaf("RHS"))) - }.assert(_ == "Branch[String](left=Leaf[String](value=LHS),right=Leaf[String](value=RHS))") + }.assert(_ == "Branch(left=Leaf(value=LHS),right=Leaf(value=RHS))") test("serialize case object") { implicitly[Show[String, Red.type]].show(Red) }.assert(_ == "Red()") + test("access default constructor values") { + implicitly[Default[Item]].default + }.assert(_ == Item("", 1, 0)) + test("serialize case object as a sealed trait") { implicitly[Show[String, Color]].show(Blue) }.assert(_ == "Blue()") @@ -97,7 +103,7 @@ object Tests extends TestApp { }.assert(_ == Company("Acme Inc")) test("decode a Person as an Entity") { - implicitly[Decoder[Entity]].decode("""Person(name=John Smith,age=32)""") + implicitly[Decoder[Entity]].decode("""magnolia.tests.Person(name=John Smith,age=32)""") }.assert(_ == Person("John Smith", 32)) test("decode a nested product") { @@ -109,7 +115,7 @@ object Tests extends TestApp { import magnolia.examples._ case class Alpha(integer: Double) case class Beta(alpha: Alpha) - Show.generic[Beta] + Show.gen[Beta] """ }.assert(_ == TypecheckError(txt"""magnolia: could not find typeclass for type Double | in parameter 'integer' of product type Alpha -- cgit v1.2.3