Skip to content

Commit

Permalink
add tests to generated Scala2 code
Browse files Browse the repository at this point in the history
  • Loading branch information
lemastero committed May 6, 2024
1 parent bb8d04f commit 20dc473
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 26 deletions.
32 changes: 7 additions & 25 deletions scala2/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,14 @@ crossScalaVersions := List(scala212, scala213)

resolvers += Resolver.sonatypeRepo("snapshots")

lazy val catsVersion = "2.10.0"
lazy val catsMtlVersion = "1.3.1"
lazy val scalaTestPlusVersion = "3.1.0.0-RC2"
lazy val scalacheckVersion = "1.17.0"
lazy val zioVersion = "2.0.22"

libraryDependencies ++= Seq(
// cats
"org.typelevel" %% "cats-core" % catsVersion,
"org.typelevel" %% "cats-effect" % "2.5.4",

"io.monix" %% "monix" % "3.4.1",

// Scalaz
"org.scalaz" %% "scalaz-core" % "7.3.7",

// ZIO
"dev.zio" %% "zio" % "2.0.18",
"dev.zio" %% "zio-prelude" % "1.0.0-RC8",

// algebra
"org.typelevel" %% "algebra" % "2.10.0",

// test
"org.scalacheck" %% "scalacheck" % scalacheckVersion % Test,
"org.scalatestplus" %% "scalatestplus-scalacheck" % scalaTestPlusVersion % Test,
"com.github.alexarchambault" %% "scalacheck-shapeless_1.15" % "1.3.0" % Test,
"org.scalatest" %% "scalatest" % "3.2.17" % Test,
"dev.zio" %% "zio" % zioVersion,
"dev.zio" %% "zio-test" % zioVersion % Test,
"dev.zio" %% "zio-test-sbt" % zioVersion % Test,
"dev.zio" %% "zio-test-junit" % zioVersion % Test,
"dev.zio" %% "zio-test-magnolia" % zioVersion % Test
)

scalacOptions ++= Seq(
Expand Down
4 changes: 3 additions & 1 deletion scala2/src/main/scala/examples/adts.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package examples

object adts {

sealed trait Rgb
Expand All @@ -13,5 +15,5 @@ final case class RgbPair(snd: Bool, fst: Rgb)

def idRgb(theArg: Rgb): Rgb = theArg

def and0(rgbArg: Rgb, rgbPairArg: RgbPair): RgbPair = rgbPairArg
def constRgbPair(rgbArg: Rgb, rgbPairArg: RgbPair): RgbPair = rgbPairArg
}
25 changes: 25 additions & 0 deletions scala2/src/test/scala/examples/RgbSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package examples

import zio.test.Assertion.equalTo
import zio.test.junit.JUnitRunnableSpec
import zio.test.{ assert, suite, test }

import examples.adts.{ Rgb, Red, Green, Blue, idRgb }
import examples.adts.{ RgbPair, constRgbPair }
import examples.adts.{ Bool, True, False }

object RgbSpec extends JUnitRunnableSpec {

def spec = suite("Test Rgb")(
test("identity on Rgb") {
assert(idRgb(Red))(equalTo(Red))
assert(idRgb(Green))(equalTo(Green))
assert(idRgb(Blue))(equalTo(Blue))
},
test("const on RgbPair") {
assert(constRgbPair(Red, RgbPair(True, Blue)))(equalTo(RgbPair(True, Blue)))
assert(constRgbPair(Green, RgbPair(False, Red)))(equalTo(RgbPair(False, Red)))
assert(constRgbPair(Blue, RgbPair(True, Blue)))(equalTo(RgbPair(True, Blue)))
}
)
}

0 comments on commit 20dc473

Please sign in to comment.