Skip to content

Commit

Permalink
Change examples into tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kubukoz committed Mar 6, 2021
1 parent 076b3be commit c44d335
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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 ++= {
Expand All @@ -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
)
)

Expand All @@ -89,4 +88,4 @@ val betterToString =
.in(file("."))
.settings(name := "root")
.settings(commonSettings, skip in publish := true)
.aggregate(plugin, examples)
.aggregate(plugin, tests)
46 changes: 0 additions & 46 deletions examples/src/main/scala/Demo.scala

This file was deleted.

73 changes: 73 additions & 0 deletions tests/src/test/scala/Demo.scala
Original file line number Diff line number Diff line change
@@ -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()
}
}

0 comments on commit c44d335

Please sign in to comment.