diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5739c9d..31f3be2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -69,7 +69,7 @@ jobs: run: sbt ++${{ matrix.scala }} test - name: Compress target directories - run: tar cf targets.tar target plugin/target examples/target project/target + run: tar cf targets.tar target plugin/target tests/target project/target - name: Upload target directories uses: actions/upload-artifact@v2 diff --git a/build.sbt b/build.sbt index 6f0146a..8397451 100644 --- a/build.sbt +++ b/build.sbt @@ -63,12 +63,11 @@ val plugin = project.settings( crossTarget := target.value / s"scala-${scalaVersion.value}", // workaround for https://github.com/sbt/sbt/issues/5097 crossVersion := CrossVersion.full, libraryDependencies ++= Seq( - scalaOrganization.value % "scala-compiler" % scalaVersion.value, - "org.scalatest" %% "scalatest" % "3.2.5" % Test + scalaOrganization.value % "scala-compiler" % scalaVersion.value ) ) -val examples = project.settings( +val tests = project.settings( skip in publish := true, commonSettings, scalacOptions ++= { @@ -80,7 +79,7 @@ val examples = project.settings( ) //borrowed from bm4 }, libraryDependencies ++= Seq( - "org.typelevel" %% "cats-core" % "2.4.2" + "org.scalatest" %% "scalatest" % "3.2.5" % Test ) ) @@ -89,4 +88,4 @@ val betterToString = .in(file(".")) .settings(name := "root") .settings(commonSettings, skip in publish := true) - .aggregate(plugin, examples) + .aggregate(plugin, tests) diff --git a/examples/src/main/scala/Demo.scala b/examples/src/main/scala/Demo.scala deleted file mode 100644 index 6099307..0000000 --- a/examples/src/main/scala/Demo.scala +++ /dev/null @@ -1,46 +0,0 @@ -import cats.Applicative - -object Demo extends App { - - final case class User(name: String, age: Int) - final case class MultiParameterList(name: String, age: Int)(val s: String) - - final case class Person(name: String) { - override def toString: String = "***" - } - - final case class HasOtherConstructors(s: String) { - def this(a: Int) = this("42") - } - - final case class NestedParent() { - case class NestedChild(name: String) - } - - def fun() = { - final case class LocalClass(name: String) - - LocalClass("a").toString() - } - - println(User("Joe", 23).toString) - println(MultiParameterList("foo", 20)("s")) - println(Person("boo").toString) - println(new HasOtherConstructors(0)) - println(Foo[cats.Id].foo) - println(NestedParent().NestedChild("a")) - println(fun()) -} - -trait Foo[F[_]] { - def foo: F[Unit] -} - -object Foo { - - def apply[F[_]](implicit F: Foo[F]): Foo[F] = F - - implicit def applicativeFoo[F[_]: Applicative]: Foo[F] = new Foo[F] { - def foo: F[Unit] = Applicative[F].unit - } -} diff --git a/tests/src/test/scala/Demo.scala b/tests/src/test/scala/Demo.scala new file mode 100644 index 0000000..8fc35bf --- /dev/null +++ b/tests/src/test/scala/Demo.scala @@ -0,0 +1,73 @@ +import org.scalatest.matchers.should.Matchers +import org.scalatest.wordspec.AnyWordSpec + +class Tests extends AnyWordSpec with Matchers { + + "Simple case class" should { + "stringify nicely" in { + SimpleCaseClass( + "Joe", + 23 + ).toString shouldBe "SimpleCaseClass(name = Joe, age = 23)" + + } + } + + "Case class with multiple parameter lists" should { + "only have the first list included" in { + MultiParameterList("foo", 20)( + "s" + ).toString shouldBe "MultiParameterList(name = foo, age = 20)" + } + } + + "Case class with custom toString" should { + "use it" in { + CustomTostring("Joe").toString shouldBe "***" + } + } + + "Method with alternate constructors" should { + "stringify based on primary constructor" in { + new HasOtherConstructors( + 10 + ).toString shouldBe "HasOtherConstructors(s = 10 beers)" + } + } + + "Class nested in another class" should { + "stringify normally" in { + new NestedParent().NestedChild("a").toString shouldBe "NestedChild(a)" + } + } + + "Method-local class" should { + "stringify normally" in { + MethodLocalWrapper.methodLocalClassStringify shouldBe "LocalClass(a)" + } + } +} + +final case class SimpleCaseClass(name: String, age: Int) +final case class MultiParameterList(name: String, age: Int)(val s: String) + +final case class CustomTostring(name: String) { + override def toString: String = "***" +} + +final case class HasOtherConstructors(s: String) { + def this(a: Int) = this(a.toString + " beers") +} + +final class NestedParent() { + case class NestedChild(name: String) +} + +object MethodLocalWrapper { + + def methodLocalClassStringify: String = { + final case class LocalClass(name: String) + + LocalClass("a").toString() + } +}