From c91b7cac849237062eea8a75134783e826dc21a0 Mon Sep 17 00:00:00 2001 From: Georgi Krastev Date: Wed, 13 Dec 2017 00:40:06 +0100 Subject: Move pathedCompanionRef to a GlobalUtil object That method is a workaround for a bug. It doesn't belong in the core Magnolia macro. Also: * Use `patchedCompanionRef` consistently * Add a test for the workaround (method-local classes) --- tests/src/main/scala/tests.scala | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) (limited to 'tests') diff --git a/tests/src/main/scala/tests.scala b/tests/src/main/scala/tests.scala index e275dee..e67813d 100644 --- a/tests/src/main/scala/tests.scala +++ b/tests/src/main/scala/tests.scala @@ -63,7 +63,7 @@ case class Portfolio(companies: Company*) object Tests extends TestApp { - def tests() = for (i <- 1 to 1) { + def tests(): Unit = for (i <- 1 to 1) { import examples._ test("construct a Show product instance with alternative apply functions") { @@ -237,21 +237,37 @@ object Tests extends TestApp { |""") } - class ParentClass() { - case class LocalClass(name: String) + class ParentClass { + case class InnerClass(name: String) + case class InnerClassWithDefault(name: String = "foo") - test("serialize a case class inside another class") { - implicitly[Show[String, LocalClass]].show(LocalClass("foo")) - }.assert(_ == "LocalClass(name=foo)") + def testInner(): Unit = { + test("serialize a case class inside another class") { + implicitly[Show[String, InnerClass]].show(InnerClass("foo")) + }.assert(_ == "InnerClass(name=foo)") - case class LocalClassWithDefault(name: String = "foo") + test("construct a default case class inside another class") { + Default.gen[InnerClassWithDefault].default + }.assert(_ == InnerClassWithDefault("foo")) + } + + def testLocal(): Unit = { + case class LocalClass(name: String) + case class LocalClassWithDefault(name: String = "foo") - test("construct a default case class inside another class") { - Default.gen[LocalClassWithDefault].default - }.assert(_ == LocalClassWithDefault("foo")) + test("serialize a case class inside a method") { + implicitly[Show[String, LocalClass]].show(LocalClass("foo")) + }.assert(_ == "LocalClass(name=foo)") + + test("construct a default case class inside a method") { + Default.gen[LocalClassWithDefault].default + }.assert(_ == LocalClassWithDefault("foo")) + } } - new ParentClass() + val parent = new ParentClass + parent.testInner() + parent.testLocal() test("show an Account") { Show.gen[Account].show(Account("john_doe", "john.doe@yahoo.com", "john.doe@gmail.com")) @@ -273,6 +289,5 @@ object Tests extends TestApp { implicit val stringTypeName: TypeName[String] = new TypeName[String] { def name = "" } TypeName.gen[Fruit].name }.assert(_ == "magnolia.tests.Fruit") - () } } -- cgit v1.2.3