Skip to content

Commit

Permalink
Merge pull request #36 from kubukoz/scala3
Browse files Browse the repository at this point in the history
  • Loading branch information
kubukoz authored May 13, 2021
2 parents 4e327e8 + 3fcf201 commit b315f24
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 53 deletions.
13 changes: 12 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ jobs:
- 3.0.0-RC1
- 3.0.0-RC2
- 3.0.0-RC3
- 3.0.0
java: [[email protected]]
runs-on: ${{ matrix.os }}
steps:
Expand Down Expand Up @@ -88,7 +89,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
scala: [3.0.0-RC3]
scala: [3.0.0]
java: [[email protected]]
runs-on: ${{ matrix.os }}
steps:
Expand Down Expand Up @@ -244,6 +245,16 @@ jobs:
tar xf targets.tar
rm targets.tar
- name: Download target directories (3.0.0)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-3.0.0-${{ matrix.java }}

- name: Inflate target directories (3.0.0)
run: |
tar xf targets.tar
rm targets.tar
- uses: olafurpg/setup-gpg@v3

- run: sbt ++${{ matrix.scala }} ci-release
23 changes: 11 additions & 12 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ val GraalVM11 = "[email protected]"
// for dottydoc
ThisBuild / resolvers += Resolver.JCenterRepository

ThisBuild / scalaVersion := "3.0.0-RC3"
ThisBuild / scalaVersion := "3.0.0"
ThisBuild / crossScalaVersions := Seq(
"2.12.10",
"2.12.11",
Expand All @@ -43,7 +43,8 @@ ThisBuild / crossScalaVersions := Seq(
"3.0.0-M3",
"3.0.0-RC1",
"3.0.0-RC2",
"3.0.0-RC3"
"3.0.0-RC3",
"3.0.0"
)

ThisBuild / githubWorkflowJavaVersions := Seq(GraalVM11)
Expand Down Expand Up @@ -71,22 +72,15 @@ val commonSettings = Seq(
scalacOptions -= "-Xfatal-warnings"
)

def scalatestVersion(scalaVersion: String) =
scalaVersion match {
case "3.0.0-M3" => "3.2.3"
case "3.0.0-RC1" => "3.2.5"
case "3.0.0-RC2" => "3.2.7"
case _ => "3.2.8"
}

val plugin = project.settings(
name := "better-tostring",
commonSettings,
crossTarget := target.value / s"scala-${scalaVersion.value}", // workaround for https://github.com/sbt/sbt/issues/5097
crossVersion := CrossVersion.full,
libraryDependencies ++= Seq(
scalaOrganization.value % (
if (scalaVersion.value.startsWith("3"))
if (scalaVersion.value == "3.0.0") "scala3-compiler_3"
else if (scalaVersion.value.startsWith("3"))
s"scala3-compiler_${scalaVersion.value}"
else "scala-compiler"
) % scalaVersion.value
Expand All @@ -105,7 +99,12 @@ val tests = project.settings(
) //borrowed from bm4
},
libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest" % scalatestVersion(scalaVersion.value) % Test
"org.scalameta" %% "munit" % (scalaVersion.value match {
case "3.0.0-M3" => "0.7.22"
case "3.0.0-RC1" => "0.7.23"
case "3.0.0-RC2" => "0.7.25"
case _ => "0.7.26"
}) % Test
)
)

Expand Down
92 changes: 52 additions & 40 deletions tests/src/test/scala/Demo.scala
Original file line number Diff line number Diff line change
@@ -1,68 +1,78 @@
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec
import munit.FunSuite

class Tests extends AnyWordSpec with Matchers {
class Tests extends FunSuite {

"Simple case class" should {
"stringify nicely" in {
test("Simple case class stringifies nicely") {
assertEquals(
SimpleCaseClass(
"Joe",
23
).toString shouldBe "SimpleCaseClass(name = Joe, age = 23)"

}
).toString,
"SimpleCaseClass(name = Joe, age = 23)"
)
}

"Case class with multiple parameter lists" should {
"only have the first list included" in {
test("Case class with multiple parameter lists only has the first list included") {
assertEquals(
MultiParameterList("foo", 20)(
"s"
).toString shouldBe "MultiParameterList(name = foo, age = 20)"
}
).toString,
"MultiParameterList(name = foo, age = 20)"
)
}

"Case class with custom toString" should {
"use it" in {
CustomTostring("Joe").toString shouldBe "***"
}
test("Case class with custom toString should not be overridden") {
assertEquals(
CustomTostring("Joe").toString,
"***"
)
}

"Method with alternate constructors" should {
"stringify based on primary constructor" in {
test("Method with alternate constructors should stringify based on primary constructor") {
assertEquals(
new HasOtherConstructors(
10
).toString shouldBe "HasOtherConstructors(s = 10 beers)"
}
).toString,
"HasOtherConstructors(s = 10 beers)"
)
}

"Class nested in an object" should {
"include enclosing object's name" in {
ObjectNestedParent.ObjectNestedClass("Joe").toString shouldBe "ObjectNestedParent.ObjectNestedClass(name = Joe)"
}
test("Class nested in an object should include enclosing object's name") {
assertEquals(
ObjectNestedParent.ObjectNestedClass("Joe").toString,
"ObjectNestedParent.ObjectNestedClass(name = Joe)"
)
}

"Class nested in a package object" should {
"not include package's name" in {
pack.InPackageObject("Joe").toString shouldBe "InPackageObject(name = Joe)"
}
test("Class nested in a package object should not include package's name") {
assertEquals(
pack.InPackageObject("Joe").toString,
"InPackageObject(name = Joe)"
)
}

"Class nested in another class" should {
"stringify normally" in {
new NestedParent().NestedChild("a").toString shouldBe "NestedChild(a)"
}
test("Class nested in another class should stringify normally") {
assertEquals(
new NestedParent().NestedChild("a").toString,
"NestedChild(a)"
)
}

"Class nested in an object itself nested in a class" should {
"stringify normally" in {
new DeeplyNestedInClassGrandparent().DeeplyNestedInClassParent.DeeplyNestedInClassClass("a").toString shouldBe "DeeplyNestedInClassClass(a)"
}
test("Class nested in an object itself nested in a class should stringify normally") {
assertEquals(
new DeeplyNestedInClassGrandparent()
.DeeplyNestedInClassParent
.DeeplyNestedInClassClass("a")
.toString,
"DeeplyNestedInClassClass(a)"
)
}

"Method-local class" should {
"stringify normally" in {
MethodLocalWrapper.methodLocalClassStringify shouldBe "LocalClass(a)"
}
test("Method-local class should stringify normally") {
assertEquals(
MethodLocalWrapper.methodLocalClassStringify,
"LocalClass(a)"
)
}
}

Expand All @@ -86,9 +96,11 @@ object ObjectNestedParent {
}

final class DeeplyNestedInClassGrandparent {

object DeeplyNestedInClassParent {
case class DeeplyNestedInClassClass(name: String)
}

}

object MethodLocalWrapper {
Expand Down

0 comments on commit b315f24

Please sign in to comment.