Skip to content

Commit

Permalink
massive yak shaving
Browse files Browse the repository at this point in the history
  • Loading branch information
julien-truffaut committed Feb 8, 2021
1 parent ffacb9d commit 61ceedb
Show file tree
Hide file tree
Showing 26 changed files with 239 additions and 176 deletions.
18 changes: 9 additions & 9 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ lazy val buildSettings = Seq(
"UTF-8",
"-feature",
"-unchecked",
"-Xfatal-warnings",
"-deprecation",
),
) ++ { if(isDotty.value) Seq() else Seq("-Xfatal-warnings") }, // Scala 3 doesn't support -Wconf
scalacOptions in (Compile, console) -= "-Ywarn-unused:imports",
scalacOptions ++= {
if (isDotty.value)
Expand Down Expand Up @@ -183,14 +182,14 @@ lazy val core = crossProject(JVMPlatform, JSPlatform)

lazy val generic = crossProject(JVMPlatform, JSPlatform)
.crossType(CrossType.Pure)
.dependsOn(core)
.dependsOn(core, law % "test->test")
.settings(moduleName := "monocle-generic")
.configureCross(
_.jvmSettings(monocleJvmSettings),
_.jsSettings(monocleJsSettings)
)
.jvmSettings(mimaSettings("generic"): _*)
.settings(libraryDependencies ++= Seq(cats.value, shapeless.value))
.settings(libraryDependencies ++= Seq(cats.value, shapeless.value, munitDiscipline.value))

lazy val refined = crossProject(JVMPlatform, JSPlatform)
.crossType(CrossType.Pure)
Expand Down Expand Up @@ -220,7 +219,7 @@ lazy val law = crossProject(JVMPlatform, JSPlatform)

lazy val macros = crossProject(JVMPlatform, JSPlatform)
.crossType(CrossType.Pure)
.dependsOn(core)
.dependsOn(core, law % "test->test")
.in(file("macro"))
.settings(moduleName := "monocle-macro")
.configureCross(
Expand All @@ -231,10 +230,11 @@ lazy val macros = crossProject(JVMPlatform, JSPlatform)
crossScalaVersions ++= dottyVersions,
scalacOptions += "-language:experimental.macros",
libraryDependencies ++= {
if (isDotty.value) Seq.empty else Seq(
Seq(munitDiscipline.value) ++
{if (isDotty.value) Seq.empty else Seq(
scalaOrganization.value % "scala-reflect" % scalaVersion.value,
scalaOrganization.value % "scala-compiler" % scalaVersion.value % "provided"
)
)}
}
)

Expand Down Expand Up @@ -265,18 +265,18 @@ lazy val unsafe = crossProject(JVMPlatform, JSPlatform)
.jvmSettings(mimaSettings("unsafe"): _*)
.settings(libraryDependencies ++= Seq(cats.value, alleycats.value))

lazy val test = crossProject(JVMPlatform, JSPlatform).dependsOn(core, generic, macros, law, state, refined, unsafe)
lazy val test = crossProject(JVMPlatform, JSPlatform).dependsOn(core, law, state, refined, unsafe)
.settings(moduleName := "monocle-test")
.configureCross(
_.jvmSettings(monocleJvmSettings),
_.jsSettings(monocleJsSettings)
)
.settings(noPublishSettings: _*)
.settings(
crossScalaVersions ++= dottyVersions,
libraryDependencies ++= Seq(
cats.value,
catsLaws.value,
shapeless.value,
munitDiscipline.value,
refinedScalacheck.value
)
Expand Down
3 changes: 2 additions & 1 deletion example/src/test/scala/monocle/function/ReverseExample.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package monocle.function

import monocle._
import monocle.generic.GenericInstances

import scala.annotation.nowarn

@nowarn
class ReverseExample extends MonocleSuite {
class ReverseExample extends MonocleSuite with GenericInstances {
test("reverse creates an Iso from a List to its reversed version") {
assertEquals((List(1, 2, 3) applyIso reverse get), List(3, 2, 1))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import shapeless.{:+:, CNil, Coproduct}
import scala.annotation.nowarn

@nowarn
class CoproductExample extends MonocleSuite {
class CoproductExample extends MonocleSuite with GenericInstances {
type ISB = Int :+: String :+: Boolean :+: CNil

test("coProductPrism creates a Prism between a Coproduct and one of its choice") {
Expand Down
2 changes: 1 addition & 1 deletion example/src/test/scala/monocle/generic/HListExample.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import shapeless.HNil
import scala.annotation.nowarn

@nowarn
class HListExample extends MonocleSuite {
class HListExample extends MonocleSuite with GenericInstances {
case class Example(i: Int, s: String, b: Boolean)

test("toHList creates an Iso between a Generic (typically a case class) and HList") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import scala.annotation.nowarn
case class Example(i: Int, s: String, b: Boolean)

@nowarn
class ProductExample extends MonocleSuite {
class ProductExample extends MonocleSuite with GenericInstances {
test("productToTuple creates an Iso between a Product and a Tuple") {
assertEquals((Example(1, "Hello", true) applyIso productToTuple).get, ((1, "Hello", true)))
assertEquals(productToTuple[Example].reverseGet((1, "Hello", true)), Example(1, "Hello", true))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package monocle.generic

import monocle.MonocleSuite
import monocle.law.discipline.{IsoTests, PrismTests}
import org.scalacheck.Arbitrary._
import org.scalacheck.{Arbitrary, Cogen, Gen}
import shapeless.{:+:, CNil, Coproduct, Inl, Inr}
import cats.Eq
import monocle.std.StdInstances
import munit.DisciplineSuite

import scala.annotation.nowarn

@nowarn
class CoproductSpec extends MonocleSuite {
class CoproductSpec extends DisciplineSuite with StdInstances with GenericOptics with GenericInstances {
type IB = Int :+: Boolean :+: CNil

implicit val isbArbitrary = Arbitrary(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ package monocle.generic

import cats.Eq
import cats.implicits._
import monocle.MonocleSuite
import monocle.law.discipline.IsoTests
import org.scalacheck.{Arbitrary, Cogen}
import shapeless.HList._
import shapeless.ops.hlist.{IsHCons, Init => HListInit}
import shapeless.{::, HNil}

import scala.annotation.nowarn
import munit.DisciplineSuite
import monocle.generic.all._
import monocle.function.all._

@nowarn
class HListSpec extends MonocleSuite {
class HListSpec extends DisciplineSuite {
case class Example(i: Int, b: Boolean, c: Char, f: Float, l: Long, d: Double)

type H = Int :: Boolean :: Char :: Float :: Long :: Double :: HNil
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package monocle.generic

import monocle.MonocleSuite
import monocle.law.discipline.IsoTests
import monocle.law.discipline.function.EachTests
import monocle.generic.all._
import org.scalacheck.Arbitrary
import cats.Eq
import munit.DisciplineSuite

import scala.annotation.nowarn

@nowarn
class ProductSpec extends MonocleSuite {
class ProductSpec extends DisciplineSuite {
case class Person(name: String, age: Int)

implicit val personEq: Eq[Person] = Eq.fromUniversalEquals
Expand Down
1 change: 0 additions & 1 deletion macro/src/main/scala-3.x/monocle.macros/GenLens.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ import monocle.Lens
import monocle.Focus.MkFocus

object GenLens {
@deprecated("use monocle.Focus", since = "3.0.0-M1")
def apply[A] = new MkFocus[A]
}
39 changes: 39 additions & 0 deletions macro/src/test/scala-2.x/monocle/macros/GenIsoSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package monocle.macros

import cats.Eq
import munit.DisciplineSuite
import org.scalacheck.Arbitrary.arbitrary
import org.scalacheck.{Arbitrary, Gen}
import monocle.law.discipline._

class GenIsoSpec extends DisciplineSuite {

case object AnObject
implicit val anObjectGen: Arbitrary[AnObject.type] = Arbitrary(Gen.const(AnObject))
implicit val anObjectEq = Eq.fromUniversalEquals[AnObject.type]

case class IntWrapper(i: Int)
implicit val intWrapperGen: Arbitrary[IntWrapper] = Arbitrary(arbitrary[Int].map(IntWrapper.apply))
implicit val intWrapperEq: Eq[IntWrapper] = Eq.fromUniversalEquals[IntWrapper]

case class IdWrapper[A](value: A)
implicit def idWrapperGen[A: Arbitrary]: Arbitrary[IdWrapper[A]] =
Arbitrary(arbitrary[A].map(IdWrapper.apply))
implicit def idWrapperEq[A: Eq]: Eq[IdWrapper[A]] = Eq.fromUniversalEquals

case class EmptyCase()
implicit val emptyCaseGen: Arbitrary[EmptyCase] = Arbitrary(Gen.const(EmptyCase()))
implicit val emptyCaseEq: Eq[EmptyCase] = Eq.fromUniversalEquals[EmptyCase]

case class EmptyCaseType[A]()
implicit def emptyCaseTypeGen[A]: Arbitrary[EmptyCaseType[A]] =
Arbitrary(Gen.const(EmptyCaseType()))
implicit def emptyCaseTypeEq[A]: Eq[EmptyCaseType[A]] = Eq.fromUniversalEquals[EmptyCaseType[A]]

checkAll("GenIso", IsoTests(GenIso[IntWrapper, Int]))
checkAll("GenIso with type param", IsoTests(GenIso[IdWrapper[Int], Int]))
checkAll("GenIso.unit object", IsoTests(GenIso.unit[AnObject.type]))
checkAll("GenIso.unit empty case class", IsoTests(GenIso.unit[EmptyCase]))
checkAll("GenIso.unit empty case class with type param", IsoTests(GenIso.unit[EmptyCaseType[Int]]))

}
30 changes: 30 additions & 0 deletions macro/src/test/scala-2.x/monocle/macros/GenPrismSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package monocle.macros

import cats.Eq
import munit.DisciplineSuite
import org.scalacheck.Arbitrary.arbitrary
import org.scalacheck.{Arbitrary, Cogen, Gen}
import monocle.law.discipline._

class GenPrismSpec extends DisciplineSuite {
sealed trait IntOrString
case class I(i: Int) extends IntOrString
case class S(s: String) extends IntOrString

implicit val iArb: Arbitrary[I] = Arbitrary(arbitrary[Int].map(I))
implicit val sArb: Arbitrary[S] = Arbitrary(arbitrary[String].map(S))

implicit val intOrStringArb: Arbitrary[IntOrString] =
Arbitrary(Gen.oneOf(iArb.arbitrary, sArb.arbitrary))

implicit val intOrStringEq: Eq[IntOrString] = Eq.fromUniversalEquals[IntOrString]
implicit val iEq: Eq[I] = Eq.fromUniversalEquals[I]
implicit val sEq: Eq[S] = Eq.fromUniversalEquals[S]

implicit val iCogen: Cogen[I] = Cogen.cogenInt.contramap(_.i)
implicit val sCogen: Cogen[S] = Cogen.cogenString.contramap(_.s)

checkAll("GenPrism I", PrismTests(GenPrism[IntOrString, I]))
checkAll("GenPrism S", PrismTests(GenPrism[IntOrString, S]))

}
37 changes: 37 additions & 0 deletions macro/src/test/scala-2.x/monocle/macros/LensesSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package monocle.macros

import cats.Eq
import munit.DisciplineSuite
import org.scalacheck.Arbitrary.arbitrary
import org.scalacheck.Arbitrary
import monocle.law.discipline._

@Lenses case class Example2(s: String, x: Int)
@Lenses case class Foo[A, B](q: Map[(A, B), Double], default: Double)

// a few more examples that should compile
@Lenses case class HasCompanion1[A](a: A)
object HasCompanion1

@Lenses case class HasCompanion2[A](a: A)
object HasCompanion2 { def foo = () }

trait Bar; trait Baz
@Lenses case class HasCompanion3[A](a: A)
object HasCompanion3 extends Bar with Baz

class annot extends annotation.StaticAnnotation
@Lenses case class HasCompanion4(l: Long, s: String)
@annot object HasCompanion4

class LensesSpec extends DisciplineSuite {
implicit val exampleArb: Arbitrary[Example2] = Arbitrary(for {
s <- arbitrary[String]
x <- arbitrary[Int]
} yield Example2(s, x))

implicit val exampleEq: Eq[Example2] = Eq.fromUniversalEquals[Example2]

checkAll("Lenses", LensTests(Example2.s))

}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package other

import monocle.{Iso, MonocleSuite}
import cats.kernel.Eq
import monocle.Iso
import monocle.law.discipline.{IsoTests, LensTests, PrismTests}
import monocle.macros.{GenIso, GenLens, GenPrism}
import munit.DisciplineSuite
import org.scalacheck.Arbitrary.{arbOption => _, _}
import org.scalacheck.{Arbitrary, Cogen, Gen}

import cats.Eq

class MacroOutSideMonocleSpec extends MonocleSuite {
class MacroOutSideMonocleSpec extends DisciplineSuite {
case class Example(i: Int)
case class Example2(l: Long, s: String)
case object ExampleObject
Expand Down
24 changes: 24 additions & 0 deletions macro/src/test/scala/monocle/macros/GenLensSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package monocle.macros

import cats.Eq
import munit.DisciplineSuite
import org.scalacheck.Arbitrary
import org.scalacheck.Arbitrary.arbitrary
import monocle.law.discipline._

class GenLensSpec extends DisciplineSuite {
case class Point(x: Int, y: Int)
case class Example(s: String, p: Point)

implicit val exampleArb: Arbitrary[Example] = Arbitrary(for {
s <- arbitrary[String]
x <- arbitrary[Int]
y <- arbitrary[Int]
} yield Example(s, Point(x, y)))

implicit val exampleEq: Eq[Example] = Eq.fromUniversalEquals[Example]

checkAll("GenLens", LensTests(GenLens[Example](_.s)))
checkAll("GenLens chain", LensTests(GenLens[Example](_.p.x)))

}
Loading

0 comments on commit 61ceedb

Please sign in to comment.