From a346b10556f8958834c14588e3443d3922d66f89 Mon Sep 17 00:00:00 2001 From: Kevin Wright Date: Thu, 1 Feb 2018 08:30:38 +0000 Subject: 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 --- tests/src/main/scala/tests.scala | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'tests') 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)") + } } -- cgit v1.2.3