scalacheck-shapeless

by alexarchambault

alexarchambault / scalacheck-shapeless

Generation of arbitrary case classes / ADTs instances with scalacheck and shapeless

211 Stars 30 Forks Last release: 8 months ago (v1.2.5) Apache License 2.0 383 Commits 26 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

scalacheck-shapeless

Generation of arbitrary case classes / ADTs instances with scalacheck and shapeless

Build Status Gitter Maven Central

Usage

Add to your

build.sbt
```scala resolvers += Resolver.sonatypeRepo("releases") // only needed if the release hasn't reached maven central yet

libraryDependencies += "com.github.alexarchambault" %% "scalacheck-shapeless_1.14" % "1.2.3" ```

If you are using scala 2.10.x, also add the macro paradise plugin to your build,

scala
libraryDependencies +=
  compilerPlugin("org.scalamacros" % "paradise" % "2.1.0" cross CrossVersion.patch)

scalacheck-shapeless depends on shapeless 2.3 and scalacheck 1.14. It is built against scala 2.10, 2.11, and 2.12.

If you are using shapeless 2.2 along with scalacheck 1.13, use the

1.0.0
version. If you are using shapeless 2.2 along with scalacheck 1.12, see the 0.3.x branch.

Import the content of

org.scalacheck.ScalacheckShapeless
close to where you want
Arbitrary
type classes to be automatically available for case classes / sealed hierarchies, ```scala import org.scalacheck.ScalacheckShapeless._

// If you defined:

// case class Foo(i: Int, s: String, blah: Boolean) // case class Bar(foo: Foo, other: String)

// sealed trait Base // case class BaseIntString(i: Int, s: String) extends Base // case class BaseDoubleBoolean(d: Double, b: Boolean) extends Base

// then you can now do

implicitly[Arbitrary[Foo]] implicitly[Arbitrary[Bar]] implicitly[Arbitrary[Base]] ```

and in particular, while writing property-based tests,

scala
property("some property about Foo") {
  forAll { foo: Foo =>
    // Ensure foo has the required property
  }
}
without having to define yourself an
Arbitrary
for
Foo
.

See also

License

Released under the Apache 2 license. See LICENSE file for more details.

Code of Conduct

See the Code of Conduct

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.