Skip to content

Instantly share code, notes, and snippets.

@chiller
Created July 3, 2019 07:53
Show Gist options
  • Save chiller/9fd2b69b627266ec3e1a40681f735df1 to your computer and use it in GitHub Desktop.
Save chiller/9fd2b69b627266ec3e1a40681f735df1 to your computer and use it in GitHub Desktop.
Prettifying
name := "prettyprop"
version := "0.1"
scalaVersion := "2.12.8"
scalacOptions += "-Ypartial-unification"
libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest" % "3.0.8",
"org.scalacheck" %% "scalacheck" % "1.14.0",
"com.github.alexarchambault" %% "scalacheck-shapeless_1.14" % "1.2.0"
)
package graphPermissions
import java.util.UUID
import org.scalatest.prop.Checkers.check
import org.scalatest.prop.{Generator, PropertyChecks}
import org.scalatest.{FunSpec, Matchers}
import org.scalacheck.{Shrink, Prop => ScalaCheckProp}
import org.scalacheck.ScalacheckShapeless._
import org.scalacheck.util.Pretty
import org.scalactic.Prettifier
import org.scalatest.prop.Checkers.check
import org.scalacheck.Prop.forAllNoShrink
class PrettyPropSpec extends FunSpec with Matchers with PropertyChecks {
case class Burger(patties: Int, ketchup: Boolean, name: String)
implicit val prettyBurger: Prettifier = new Prettifier {
def apply(o: Any): String = {
o match {
case null => "null"
case _: Unit => "<(), the Unit value>"
case aString: String => "\"" + aString + "\""
case _: Burger => "HOTDOG"
case _: UUID => "UUID!!!"
case anythingElse => anythingElse.toString
}
}
}
describe("Pretty things") {
implicit def myPrettyUUID(t: UUID): Pretty = Pretty {_ =>
s"""UUID("${t.toString}")"""
}
implicit def myPretty(t: Any): Pretty = Pretty { _ =>
t match {
case _: UUID => s"""UUID("${t.toString}")"""
case _ => t.toString
}
}
it("scalatest style") {
forAll { b: Burger =>
{
b.patties shouldBe 0
}
}
}
it("scalacheck hybrid style") {
check {
forAllNoShrink { uid: UUID =>
{
uid.toString == ""
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment