aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJon Pretty <jon.pretty@propensive.com>2017-11-30 18:51:35 +0000
committerJon Pretty <jon.pretty@propensive.com>2017-11-30 18:51:35 +0000
commite1bb3f9c514a2b473076e5fd98b87c26885cd223 (patch)
tree6b9ce78c34d9f0f1c33d6596688ffc8d5d6459c4 /tests
parentd88b15e99e2727558bb901fcc08398862f633c11 (diff)
parent6cdb7d145f2784712bc5b56824cbc7f04f9a32e4 (diff)
downloadmagnolia-e1bb3f9c514a2b473076e5fd98b87c26885cd223.tar.gz
magnolia-e1bb3f9c514a2b473076e5fd98b87c26885cd223.tar.bz2
magnolia-e1bb3f9c514a2b473076e5fd98b87c26885cd223.zip
Merge branch 'joroKr21-existentials'
Diffstat (limited to 'tests')
-rw-r--r--tests/src/main/scala/tests.scala27
1 files changed, 26 insertions, 1 deletions
diff --git a/tests/src/main/scala/tests.scala b/tests/src/main/scala/tests.scala
index 96a2c2b..df4dfd6 100644
--- a/tests/src/main/scala/tests.scala
+++ b/tests/src/main/scala/tests.scala
@@ -47,10 +47,19 @@ object Test {
def apply(a: String, b: String): Test = Test(Param(a, b))
}
+sealed trait Politician[+S]
+case class Accountable[+S](slogan: S) extends Politician[S]
+case class Corrupt[+S, +L <: Seq[Company]](slogan: S, lobby: L) extends Politician[S]
+
+sealed trait Box[+A]
+case class SimpleBox[+A](value: A) extends Box[A]
+case class LabelledBox[+A, L <: String](value: A, var label: L) extends Box[A]
+
case class Account(id: String, emails: String*)
case class Portfolio(companies: Company*)
+
object Tests extends TestApp {
def tests() = for (i <- 1 to 1) {
@@ -206,6 +215,22 @@ object Tests extends TestApp {
Show.gen[Length].show(new Length(100))
}.assert(_ == "100")
+
+ // Corrupt being covariant in L <: Seq[Company] enables the derivation for Corrupt[String, _]
+ test("show a Politician with covariant lobby") {
+ Show.gen[Politician[String]].show(Corrupt("wall", Seq(Company("Alice Inc"))))
+ }.assert(_ == "Corrupt(slogan=wall,lobby=[Company(name=Alice Inc)])")
+
+ // LabelledBox being invariant in L <: String prohibits the derivation for LabelledBox[Int, _]
+ test("can't show a Box with invariant label") {
+ scalac"Show.gen[Box[Int]]"
+ }.assert { _ == TypecheckError(
+ txt"""magnolia: could not find typeclass for type L
+ | in parameter 'label' of product type magnolia.tests.LabelledBox[Int, _ <: String]
+ | in coproduct type magnolia.tests.Box[Int]
+ |""")
+ }
+
test("show an Account") {
Show.gen[Account].show(Account("john_doe", "john.doe@yahoo.com", "john.doe@gmail.com"))
}.assert(_ == "Account(id=john_doe,emails=[john.doe@yahoo.com,john.doe@gmail.com])")
@@ -226,6 +251,6 @@ object Tests extends TestApp {
implicit val stringTypeName: TypeName[String] = new TypeName[String] { def name = "" }
TypeName.gen[Fruit].name
}.assert(_ == "magnolia.tests.Fruit")
-
+ ()
}
}