aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJon Pretty <jon.pretty@propensive.com>2017-11-10 12:59:57 +0000
committerJon Pretty <jon.pretty@propensive.com>2017-11-10 12:59:57 +0000
commit657d2fb2c16b75c790bf3c3a63d1f830a42893db (patch)
tree619d43dd310eeb19ab964d3ea3bf7884b088ea71 /tests
parent6e90ebbe2f951305bd8f5f02fe4b04531bb31869 (diff)
downloadmagnolia-657d2fb2c16b75c790bf3c3a63d1f830a42893db.tar.gz
magnolia-657d2fb2c16b75c790bf3c3a63d1f830a42893db.tar.bz2
magnolia-657d2fb2c16b75c790bf3c3a63d1f830a42893db.zip
More build cleanup, and a couple of extra tests
Diffstat (limited to 'tests')
-rw-r--r--tests/src/main/scala/tests.scala38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/src/main/scala/tests.scala b/tests/src/main/scala/tests.scala
index f79a51b..10eb465 100644
--- a/tests/src/main/scala/tests.scala
+++ b/tests/src/main/scala/tests.scala
@@ -18,6 +18,14 @@ 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 Lunchbox(fruit: Fruit, drink: String)
+object Fruit {
+ import examples._
+ implicit val showFruit: Show[String, Fruit] =
+ new Show[String, Fruit] { def show(f: Fruit): String = f.name }
+}
+case class Fruit(name: String)
+
case class Item(name: String, quantity: Int = 1, price: Int)
sealed trait Color
@@ -45,6 +53,29 @@ object Tests extends TestApp {
implicitly[Show[String, Branch[String]]].show(Branch(Leaf("LHS"), Leaf("RHS")))
}.assert(_ == "Branch(left=Leaf(value=LHS),right=Leaf(value=RHS))")
+ test("local implicit beats Magnolia") {
+ import magnolia.examples._
+ implicit val showPerson: Show[String, Person] = new Show[String, Person] { def show(p: Person) = "nobody" }
+ implicitly[Show[String, Address]].show(Address("Home", Person("John Smith", 44)))
+ }.assert(_ == "Address(line1=Home,occupant=nobody)")
+
+ test("even low-priority implicit beats Magnolia for nested case") {
+ import magnolia.examples._
+ import Show.gen
+ implicitly[Show[String, Lunchbox]].show(Lunchbox(Fruit("apple"), "lemonade"))
+ }.assert(_ == "Lunchbox(fruit=apple,drink=lemonade)")
+
+ test("low-priority implicit does not beat Magnolia when not nested") {
+ import magnolia.examples._
+ import Show.gen
+ implicitly[Show[String, Fruit]].show(Fruit("apple"))
+ }.assert(_ == "Fruit(name=apple)")
+
+ test("typeclass implicit scope has lower priority than ADT implicit scope") {
+ import magnolia.examples._
+ implicitly[Show[String, Fruit]].show(Fruit("apple"))
+ }.assert(_ == "apple")
+
test("test equality false") {
import examples._
Eq.gen[Entity].equal(Person("John Smith", 34), Person("", 0))
@@ -124,5 +155,12 @@ object Tests extends TestApp {
| in parameter 'alpha' of product type Beta
|"""))
+ val tupleDerivation = test("derive for a tuple") {
+ implicitly[Show[String, (Int, String)]]
+ }.returns()
+
+ test("serialize a tuple") {
+ tupleDerivation().show((42, "Hello World"))
+ }.assert(_ == "Tuple2(_1=42,_2=Hello World)")
}
}