diff options
author | Kevin Wright <kevin.wright@bradyplc.com> | 2018-02-01 08:30:38 +0000 |
---|---|---|
committer | Kevin Wright <kevin.wright@bradyplc.com> | 2018-02-01 08:30:38 +0000 |
commit | a346b10556f8958834c14588e3443d3922d66f89 (patch) | |
tree | 261d69b43c4e2ee1fae83b9b22c4001e1fb3145f /tests | |
parent | 4d1bf3ad68b3def3bbdc7ac8c45cb1a72c2c4e09 (diff) | |
download | magnolia-a346b10556f8958834c14588e3443d3922d66f89.tar.gz magnolia-a346b10556f8958834c14588e3443d3922d66f89.tar.bz2 magnolia-a346b10556f8958834c14588e3443d3922d66f89.zip |
Added annotation capture to params
Added test for annotation capture
Updated to lamdafied syntax for SAM type construction
Minor changes to permit compilation under JDK 9
Added Kevin Wright as a contributor
Diffstat (limited to 'tests')
-rw-r--r-- | tests/src/main/scala/tests.scala | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/tests/src/main/scala/tests.scala b/tests/src/main/scala/tests.scala index 11a5d2f..0f962d2 100644 --- a/tests/src/main/scala/tests.scala +++ b/tests/src/main/scala/tests.scala @@ -1,12 +1,13 @@ package magnolia.tests import language.experimental.macros -import estrapade.{test, TestApp} +import estrapade.{TestApp, test} import contextual.data.scalac._ import contextual.data.fqt._ import contextual.data.txt._ import magnolia.examples._ +import scala.annotation.StaticAnnotation import scala.util.control.NonFatal sealed trait Tree[+T] @@ -29,8 +30,7 @@ class Length(val value: Int) extends AnyVal case class FruitBasket(fruits: Fruit*) case class Lunchbox(fruit: Fruit, drink: String) object Fruit { - implicit val showFruit: Show[String, Fruit] = - new Show[String, Fruit] { def show(f: Fruit): String = f.name } + implicit val showFruit: Show[String, Fruit] = (f: Fruit) => f.name } case class Fruit(name: String) @@ -41,6 +41,14 @@ case object Red extends Color case object Green extends Color case object Blue extends Color + +case class MyAnnotation(order: Int) extends StaticAnnotation + +case class Attributed( + @MyAnnotation(1) p1: String, + @MyAnnotation(2) p2: Int +) + case class `%%`(`/`: Int, `#`: String) case class Param(a: String, b: String) @@ -354,11 +362,14 @@ object Tests extends TestApp { implicit def showDefaultOption[A]( implicit showA: Show[String, A], defaultA: Default[A] - ): Show[String, Option[A]] = new Show[String, Option[A]] { - def show(optA: Option[A]) = showA.show(optA.getOrElse(defaultA.default)) - } + ): Show[String, Option[A]] = (optA: Option[A]) => showA.show(optA.getOrElse(defaultA.default)) Show.gen[Path[String]].show(OffRoad(Some(Crossroad(Destination("A"), Destination("B"))))) }.assert(_ == "OffRoad(path=Crossroad(left=Destination(value=A),right=Destination(value=B)))") + + test("capture attributes against params") { + Show.gen[Attributed].show(Attributed("xyz", 100)) + }.assert(_ == "Attributed(p1{MyAnnotation(1)}=xyz,p2{MyAnnotation(2)}=100)") + } } |