diff options
author | Jon Pretty <jon.pretty@propensive.com> | 2017-11-30 13:47:15 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-30 13:47:15 +0100 |
commit | c698d7db4b6e89392b8ae399333a89b167db20c7 (patch) | |
tree | bf4a34e519dec8992ded3f92b7ec4acec08c1826 /tests/src | |
parent | 834af65ed610d6b1b278b5204801306808a90645 (diff) | |
parent | e2191e2687b671d4a8610544251e7e807f2793da (diff) | |
download | magnolia-c698d7db4b6e89392b8ae399333a89b167db20c7.tar.gz magnolia-c698d7db4b6e89392b8ae399333a89b167db20c7.tar.bz2 magnolia-c698d7db4b6e89392b8ae399333a89b167db20c7.zip |
Merge branch 'master' into patch-1
Diffstat (limited to 'tests/src')
-rw-r--r-- | tests/src/main/scala/tests.scala | 45 |
1 files changed, 43 insertions, 2 deletions
diff --git a/tests/src/main/scala/tests.scala b/tests/src/main/scala/tests.scala index 727fb70..6d883da 100644 --- a/tests/src/main/scala/tests.scala +++ b/tests/src/main/scala/tests.scala @@ -6,8 +6,6 @@ import contextual.data.scalac._ import contextual.data.fqt._ import contextual.data.txt._ -import scala.util._ - sealed trait Tree[+T] case class Leaf[+L](value: L) extends Tree[L] case class Branch[+B](left: Tree[B], right: Tree[B]) extends Tree[B] @@ -37,11 +35,30 @@ case object Blue extends Color case class `%%`(`/`: Int, `#`: String) +case class Param(a: String, b: String) +case class Test(param: Param) +object Test { + def apply(): Test = Test(Param("", "")) + + def apply(a: String)(implicit b: Int): Test = Test(Param(a, b.toString)) + + def apply(a: String, b: String): Test = Test(Param(a, b)) +} + +case class Account(id: String, emails: String*) + +case class Portfolio(companies: Company*) + object Tests extends TestApp { def tests() = for (i <- 1 to 1000) { import examples._ + test("construct a Show product instance with alternative apply functions") { + import examples._ + Show.gen[Test].show(Test("a", "b")) + }.assert(_ == """Test(param=Param(a=a,b=b))""") + test("construct a Show product instance") { import examples._ Show.gen[Person].show(Person("John Smith", 34)) @@ -161,6 +178,16 @@ object Tests extends TestApp { | in parameter 'alpha' of product type Beta |""")) + test("not attempt to instantiate Unit when producing error stack") { + scalac""" + import magnolia.examples._ + case class Gamma(unit: Unit) + Show.gen[Gamma] + """ + }.assert(_ == TypecheckError(txt"""magnolia: could not find typeclass for type Unit + | in parameter 'unit' of product type Gamma + |""")) + test("typenames and labels are not encoded") { implicitly[Show[String, `%%`]].show(`%%`(1, "two")) }.assert(_ == "%%(/=1,#=two)") @@ -177,6 +204,7 @@ object Tests extends TestApp { Show.gen[Length].show(new Length(100)) }.assert(_ == "100") + class ParentClass { case class InnerClass(name: String) @@ -186,5 +214,18 @@ object Tests extends TestApp { } new ParentClass + + 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])") + + test("construct a default Account") { + Default.gen[Account].default + }.assert(_ == Account("")) + + test("show a Portfolio of Companies") { + Show.gen[Portfolio].show(Portfolio(Company("Alice Inc"), Company("Bob & Co"))) + }.assert(_ == "Portfolio(companies=[Company(name=Alice Inc),Company(name=Bob & Co)])") + } } |