-
-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ffacb9d
commit 61ceedb
Showing
26 changed files
with
239 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
...scala/monocle/generic/CoproductSpec.scala → ...scala/monocle/generic/CoproductSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
...t/scala/monocle/generic/ProductSpec.scala → ...t/scala/monocle/generic/ProductSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
30
macro/src/test/scala-2.x/monocle/macros/GenPrismSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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])) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
|
||
} |
8 changes: 4 additions & 4 deletions
8
...scala/other/MacroOutSideMonocleSpec.scala → ...a-2.x/other/MacroOutSideMonocleSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))) | ||
|
||
} |
Oops, something went wrong.