Skip to content

Commit

Permalink
Use discipline-scalatest
Browse files Browse the repository at this point in the history
  • Loading branch information
travisbrown committed Feb 18, 2020
1 parent 869b931 commit 37beb52
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 36 deletions.
7 changes: 3 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ lazy val optics = crossProject(JSPlatform, JVMPlatform)
"io.circe" %%% "circe-core" % circeVersion,
"io.circe" %%% "circe-generic" % circeVersion % Test,
"io.circe" %%% "circe-testing" % circeVersion % Test,
"org.scalatestplus" %%% "scalatestplus-scalacheck" % "3.1.0.0-RC2" % Test
"org.scalatestplus" %%% "scalacheck-1-14" % "3.1.0.1" % Test,
"org.typelevel" %%% "discipline-scalatest" % "1.0.0" % Test
),
ghpagesNoJekyll := true,
docMappingsApiDir := "api",
Expand All @@ -89,9 +90,7 @@ lazy val publishSettings = Seq(
licenses := Seq("Apache 2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0")),
publishMavenStyle := true,
publishArtifact in Test := false,
pomIncludeRepository := { _ =>
false
},
pomIncludeRepository := { _ => false },
publishTo := {
val nexus = "https://oss.sonatype.org/"
if (isSnapshot.value)
Expand Down
2 changes: 2 additions & 0 deletions optics/src/test/scala/io/circe/optics/CirceSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import io.circe.testing.{ ArbitraryInstances, EqInstances }
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatestplus.scalacheck.{ Checkers, ScalaCheckDrivenPropertyChecks }
import org.typelevel.discipline.Laws
import org.typelevel.discipline.scalatest.FlatSpecDiscipline
import scala.language.implicitConversions

/**
* An opinionated stack of traits to improve consistency and reduce boilerplate in circe tests.
*/
trait CirceSuite
extends AnyFlatSpec
with FlatSpecDiscipline
with ScalaCheckDrivenPropertyChecks
with AllInstances
with AllSyntax
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ class DeriveWithIsoSuite extends CirceSuite {
case class UserSnake(id: Long, first_name: String, last_name: String)
case class UserCamel(id: Long, firstName: String, lastName: String)

val snake2camel = Iso[UserSnake, UserCamel] { (s: UserSnake) =>
UserCamel(s.id, s.first_name, s.last_name)
} { (s: UserCamel) =>
UserSnake(s.id, s.firstName, s.lastName)
val snake2camel = Iso[UserSnake, UserCamel]((s: UserSnake) => UserCamel(s.id, s.first_name, s.last_name)) {
(s: UserCamel) => UserSnake(s.id, s.firstName, s.lastName)
}

val john: Json = Json.obj(
Expand Down
3 changes: 2 additions & 1 deletion optics/src/test/scala/io/circe/optics/LawsTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ object LawsTests extends Laws {
"modify id = id" -> Prop.forAll((s: S, i: I) => laws(i).modifyIdentity(s)),
"compose modify" -> Prop.forAll((s: S, g: A => A, h: A => A, i: I) => laws(i).composeModify(s, g, h)),
"consistent set with modify" -> Prop.forAll((s: S, a: A, i: I) => laws(i).consistentSetModify(s, a)),
"consistent modify with modifyId" -> Prop.forAll((s: S, g: A => A, i: I) => laws(i).consistentModifyModifyId(s, g)
"consistent modify with modifyId" -> Prop.forAll((s: S, g: A => A, i: I) =>
laws(i).consistentModifyModifyId(s, g)
),
"consistent getOption with modifyId" -> Prop.forAll((s: S, i: I) => laws(i).consistentGetOptionModifyId(s))
)
Expand Down
54 changes: 27 additions & 27 deletions optics/src/test/scala/io/circe/optics/OpticsSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,33 @@ class OpticsSuite extends CirceSuite {
(x.isNaN && y.isNaN) || x == y
}

checkLaws("Json to Unit", LawsTests.prismTests(jsonNull))
checkLaws("Json to Boolean", LawsTests.prismTests(jsonBoolean))
checkLaws("Json to BigDecimal", LawsTests.prismTests(jsonBigDecimal))
checkLaws("Json to Double", LawsTests.prismTests(jsonDouble))
checkLaws("Json to BigInt", LawsTests.prismTests(jsonBigInt))
checkLaws("Json to Long", LawsTests.prismTests(jsonLong))
checkLaws("Json to Int", LawsTests.prismTests(jsonInt))
checkLaws("Json to Short", LawsTests.prismTests(jsonShort))
checkLaws("Json to Byte", LawsTests.prismTests(jsonByte))
checkLaws("Json to String", LawsTests.prismTests(jsonString))
checkLaws("Json to JsonNumber", LawsTests.prismTests(jsonNumber))
checkLaws("Json to JsonObject", LawsTests.prismTests(jsonObject))
checkLaws("Json to Vector[Json]", LawsTests.prismTests(jsonArray))

checkLaws("JsonNumber to BigDecimal", LawsTests.prismTests(jsonNumberBigDecimal))
checkLaws("JsonNumber to BigInt", LawsTests.prismTests(jsonNumberBigInt))
checkLaws("JsonNumber to Long", LawsTests.prismTests(jsonNumberLong))
checkLaws("JsonNumber to Int", LawsTests.prismTests(jsonNumberInt))
checkLaws("JsonNumber to Short", LawsTests.prismTests(jsonNumberShort))
checkLaws("JsonNumber to Byte", LawsTests.prismTests(jsonNumberByte))

checkLaws("plated Json", LawsTests.traversalTests(plate[Json]))

checkLaws("jsonObjectEach", LawsTests.eachTests[JsonObject, Json])
checkLaws("jsonObjectAt", LawsTests.atTests[JsonObject, String, Option[Json]])
checkLaws("jsonObjectIndex", LawsTests.indexTests[JsonObject, String, Json])
checkLaws("jsonObjectFilterIndex", LawsTests.filterIndexTests[JsonObject, String, Json])
checkAll("Json to Unit", LawsTests.prismTests(jsonNull))
checkAll("Json to Boolean", LawsTests.prismTests(jsonBoolean))
checkAll("Json to BigDecimal", LawsTests.prismTests(jsonBigDecimal))
checkAll("Json to Double", LawsTests.prismTests(jsonDouble))
checkAll("Json to BigInt", LawsTests.prismTests(jsonBigInt))
checkAll("Json to Long", LawsTests.prismTests(jsonLong))
checkAll("Json to Int", LawsTests.prismTests(jsonInt))
checkAll("Json to Short", LawsTests.prismTests(jsonShort))
checkAll("Json to Byte", LawsTests.prismTests(jsonByte))
checkAll("Json to String", LawsTests.prismTests(jsonString))
checkAll("Json to JsonNumber", LawsTests.prismTests(jsonNumber))
checkAll("Json to JsonObject", LawsTests.prismTests(jsonObject))
checkAll("Json to Vector[Json]", LawsTests.prismTests(jsonArray))

checkAll("JsonNumber to BigDecimal", LawsTests.prismTests(jsonNumberBigDecimal))
checkAll("JsonNumber to BigInt", LawsTests.prismTests(jsonNumberBigInt))
checkAll("JsonNumber to Long", LawsTests.prismTests(jsonNumberLong))
checkAll("JsonNumber to Int", LawsTests.prismTests(jsonNumberInt))
checkAll("JsonNumber to Short", LawsTests.prismTests(jsonNumberShort))
checkAll("JsonNumber to Byte", LawsTests.prismTests(jsonNumberByte))

checkAll("plated Json", LawsTests.traversalTests(plate[Json]))

checkAll("jsonObjectEach", LawsTests.eachTests[JsonObject, Json])
checkAll("jsonObjectAt", LawsTests.atTests[JsonObject, String, Option[Json]])
checkAll("jsonObjectIndex", LawsTests.indexTests[JsonObject, String, Json])
checkAll("jsonObjectFilterIndex", LawsTests.filterIndexTests[JsonObject, String, Json])

"jsonDouble" should "round-trip in reverse with Double.NaN" in {
assert(jsonDouble.getOption(jsonDouble.reverseGet(Double.NaN)) === Some(Double.NaN))
Expand Down

0 comments on commit 37beb52

Please sign in to comment.