Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #315 #342 #343

Merged
merged 5 commits into from Apr 9, 2016
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion build.sbt
Expand Up @@ -43,6 +43,7 @@ lazy val buildSettings = Seq(
lazy val scalaz = Def.setting("org.scalaz" %%% "scalaz-core" % "7.2.1")
lazy val shapeless = Def.setting("com.chuusai" %%% "shapeless" % "2.3.0")
lazy val refinedDep = Def.setting("eu.timepit" %%% "refined" % "0.3.7")
lazy val refinedScalaCheckDep = Def.setting("eu.timepit" %%% "refined-scalacheck" % "0.3.7")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add "test" modifier


lazy val discpline = Def.setting("org.typelevel" %%% "discipline" % "0.4")
lazy val scalatest = Def.setting("org.scalatest" %%% "scalatest" % "3.0.0-M7" % "test")
Expand Down Expand Up @@ -130,7 +131,7 @@ lazy val refinedJS = refined.js
lazy val refined = crossProject.dependsOn(core)
.settings(moduleName := "monocle-refined")
.configure(monocleCrossSettings)
.settings(libraryDependencies ++= Seq(scalaz.value, refinedDep.value))
.settings(libraryDependencies ++= Seq(scalaz.value, refinedDep.value, refinedScalaCheckDep.value))

lazy val lawJVM = law.jvm
lazy val lawJS = law.js
Expand Down
Expand Up @@ -10,14 +10,16 @@ import scalaz.Equal

object LensTests extends Laws {

def apply[S: Arbitrary : Equal, A: Arbitrary : Equal](lens: Lens[S, A]): RuleSet = {
val laws: LensLaws[S, A] = new LensLaws(lens)
def apply[S: Arbitrary : Equal, A: Arbitrary : Equal](lens: Lens[S, A]): RuleSet =
apply[S, A, Unit](_ => lens)

def apply[S: Arbitrary : Equal, A: Arbitrary : Equal, I: Arbitrary](f: I => Lens[S, A]): RuleSet = {
new SimpleRuleSet("Lens",
"set what you get" -> forAll( (s: S) => laws.getSet(s)),
"get what you set" -> forAll( (s: S, a: A) => laws.setGet(s, a)),
"set idempotent" -> forAll( (s: S, a: A) => laws.setIdempotent(s, a)),
"modify id = id" -> forAll( (s: S) => laws.modifyIdentity(s)),
"modifyF Id = Id" -> forAll( (s: S) => laws.modifyFId(s))
"set what you get" -> forAll( (s: S, i: I) => new LensLaws(f(i)).getSet(s)),
"get what you set" -> forAll( (s: S, a: A, i: I) => new LensLaws(f(i)).setGet(s, a)),
"set idempotent" -> forAll( (s: S, a: A, i: I) => new LensLaws(f(i)).setIdempotent(s, a)),
"modify id = id" -> forAll( (s: S, i: I) => new LensLaws(f(i)).modifyIdentity(s)),
"modifyF Id = Id" -> forAll( (s: S, i: I) => new LensLaws(f(i)).modifyFId(s))
)
}

Expand Down
@@ -1,6 +1,6 @@
package monocle.law.discipline

import monocle.Optional
import monocle._
import monocle.law.OptionalLaws
import org.scalacheck.Arbitrary
import org.scalacheck.Prop._
Expand All @@ -11,16 +11,17 @@ import scalaz.std.option._

object OptionalTests extends Laws {

def apply[S: Arbitrary : Equal, A: Arbitrary : Equal](optional: Optional[S, A]): RuleSet = {
val laws: OptionalLaws[S, A] = new OptionalLaws(optional)
def apply[S: Arbitrary : Equal, A: Arbitrary : Equal](optional: Optional[S, A]): RuleSet =
apply[S, A, Unit](_ => optional)

def apply[S: Arbitrary : Equal, A: Arbitrary : Equal, I: Arbitrary](f: I => Optional[S, A]): RuleSet =
new SimpleRuleSet("Optional",
"set what you get" -> forAll( (s: S) => laws.getOptionSet(s)),
"get what you set" -> forAll( (s: S, a: A) => laws.setGetOption(s, a)),
"set idempotent" -> forAll( (s: S, a: A) => laws.setIdempotent(s, a)),
"modify id = id" -> forAll( (s: S) => laws.modifyIdentity(s)),
"modifyF Id = Id" -> forAll( (s: S) => laws.modifyFId(s)),
"modifyOption" -> forAll( (s: S) => laws.modifyOptionIdentity(s))
"set what you get" -> forAll( (s: S, i: I) => new OptionalLaws(f(i)).getOptionSet(s)),
"get what you set" -> forAll( (s: S, a: A, i: I) => new OptionalLaws(f(i)).setGetOption(s, a)),
"set idempotent" -> forAll( (s: S, a: A, i: I) => new OptionalLaws(f(i)).setIdempotent(s, a)),
"modify id = id" -> forAll( (s: S, i: I) => new OptionalLaws(f(i)).modifyIdentity(s)),
"modifyF Id = Id" -> forAll( (s: S, i: I) => new OptionalLaws(f(i)).modifyFId(s)),
"modifyOption" -> forAll( (s: S, i: I) => new OptionalLaws(f(i)).modifyOptionIdentity(s))
)
}

}
Expand Up @@ -7,18 +7,17 @@ import org.scalacheck.Arbitrary
import org.typelevel.discipline.Laws

import scalaz.Equal
import scalaz.std.option._

object AtTests extends Laws {

def apply[S, I, A](i: I)(implicit aEq: Equal[A], aArb: Arbitrary[A],
sEq: Equal[S], sArb: Arbitrary[S],
evAt: At[S, I, A]): RuleSet =
new SimpleRuleSet("At", LensTests(at(i)).props: _*)
def apply[S, I, A](implicit aEq: Equal[A], aArb: Arbitrary[A],
sEq: Equal[S], sArb: Arbitrary[S],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you mind to maintain the vertical alignment

iArb: Arbitrary[I], evAt: At[S, I, A]): RuleSet = {
new SimpleRuleSet("At", LensTests(at(_: I)).props: _*)
}

def defaultIntIndex[S, A](implicit aEq: Equal[A], aArb: Arbitrary[A],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can probably remove defaultIntIndex

sEq: Equal[S], sArb: Arbitrary[S],
evAt: At[S, Int, A]): RuleSet =
apply[S, Int, A](2)

sEq: Equal[S], sArb: Arbitrary[S],
iArb: Arbitrary[Int], evAt: At[S, Int, A]): RuleSet =
apply[S, Int, A]
}
Expand Up @@ -10,14 +10,14 @@ import scalaz.Equal

object IndexTests extends Laws {

def apply[S, I, A](i: I)(implicit aEq: Equal[A], aArb: Arbitrary[A],
sEq: Equal[S], sArb: Arbitrary[S],
evIndex: Index[S, I, A]): RuleSet =
new SimpleRuleSet("Index", OptionalTests(index(i)).props: _*)
def apply[S, I, A](implicit aEq: Equal[A], aArb: Arbitrary[A],
sEq: Equal[S], sArb: Arbitrary[S],
iArb: Arbitrary[I], evIndex: Index[S, I, A]): RuleSet =
new SimpleRuleSet("Index", OptionalTests(index(_ : I)).props: _*)

def defaultIntIndex[S, A](implicit aEq: Equal[A], aArb: Arbitrary[A],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

sEq: Equal[S], sArb: Arbitrary[S],
evIndex: Index[S, Int, A]): RuleSet =
apply[S, Int, A](2)
sEq: Equal[S], sArb: Arbitrary[S],
evIndex: Index[S, Int, A]): RuleSet =
apply[S, Int, A]

}
Expand Up @@ -100,7 +100,7 @@ private[monocle] trait BitsInstances {
def signed(a: Long): Boolean = a.signum > 0
def negate(a: Long): Long = ~a
def testBit(a: Long, n: Int): Boolean = bitwiseAnd(a, singleBit(n)) != 0
def singleBit(n: Int): Long = (1 << n).toLong
def singleBit(n: Int): Long = 1L << n

def shiftR(a: Long, n: Int): Long = a >> n
def shiftL(a: Long, n: Int): Long = a << n
Expand Down
9 changes: 5 additions & 4 deletions test/shared/src/test/scala/monocle/refined/BitsSpec.scala
Expand Up @@ -2,12 +2,13 @@ package monocle.refined

import eu.timepit.refined._
import eu.timepit.refined.auto._
import eu.timepit.refined.scalacheck.numeric._
import monocle.MonocleSuite
import monocle.law.discipline.function.AtTests

class BitsSpec extends MonocleSuite {
checkAll("Byte at bit", AtTests[Byte, ZeroTo[W.`7`.T], Boolean](0))
checkAll("Char at bit", AtTests[Char, ZeroTo[W.`15`.T], Boolean](0))
checkAll("Int at bit", AtTests[Int, ZeroTo[W.`31`.T], Boolean](0))
checkAll("Long at bit", AtTests[Long, ZeroTo[W.`63`.T], Boolean](0))
checkAll("Byte at bit", AtTests[Byte, ZeroTo[W.`7`.T], Boolean])
checkAll("Char at bit", AtTests[Char, ZeroTo[W.`15`.T], Boolean])
checkAll("Int at bit", AtTests[Int, ZeroTo[W.`31`.T], Boolean])
checkAll("Long at bit", AtTests[Long, ZeroTo[W.`63`.T], Boolean])
}