Skip to content

Commit

Permalink
Merge pull request #149 from keynmol/scala-3-roundtrip-tests
Browse files Browse the repository at this point in the history
Codec roundtrip tests on Scala3
  • Loading branch information
keynmol authored Oct 1, 2021
2 parents 6f91af9 + 8cd20de commit 5a5097a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ align = none
project.git = true

project.excludeFilters = [
"(.*)/src/main/scala-3/(.*)"
"(.*)/src/main/scala-3/(.*)",
"(.*)/src/test/scala-3/(.*)"
]
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ lazy val tests = crossProject(JVMPlatform, JSPlatform, NativePlatform)
Seq(
"com.github.alexarchambault" %%% "scalacheck-shapeless_1.15" % "1.3.0"
)
else Seq.empty
else Seq("org.typelevel" %% "shapeless3-deriving" % "3.0.3")
},
graalVMNativeImageOptions ++= {
val reflectionFile =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package metaconfig

import org.scalacheck.Prop.forAll

class CodecRoundtripSuite extends munit.ScalaCheckSuite {

def checkRoundtrip[T: ConfCodec](a: T): Boolean = {
val conf = ConfEncoder[T].write(a)
val b = ConfDecoder[T].read(conf).get
a == b
}

property("roundtrip AllTheAnnotations") {
forAll { (a: AllTheAnnotations) => checkRoundtrip(a) }
}

property("roundtrip Outer") {
forAll { (a: Outer) => checkRoundtrip(a) }
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package metaconfig
import org.scalacheck._
import shapeless3.deriving.*

given [A](using inst: K0.ProductInstances[Arbitrary, A]): Arbitrary[A] =
Arbitrary(inst.construct([t] => (ma: Arbitrary[t]) => ma.arbitrary.sample.get))

0 comments on commit 5a5097a

Please sign in to comment.