Skip to content

Commit

Permalink
#648 fix tests commented for 2.13 (#659)
Browse files Browse the repository at this point in the history
  • Loading branch information
julien-truffaut committed Apr 30, 2019
1 parent d7c6cb1 commit 72e5792
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 40 deletions.
4 changes: 3 additions & 1 deletion core/shared/src/main/scala/monocle/function/Index.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ object Index extends IndexFunctions{
if (i < 0)
Optional[Stream[A], A](_ => None)(_ => identity)
else
Optional[Stream[A], A](_.drop(i).headOption)(a => s => Try(s.updated(i, a)).getOrElse(s))
Optional[Stream[A], A](_.drop(i).headOption)(a => s =>
s.zipWithIndex.map{ case (value, index) => if(i == index) a else value }
)
)

implicit val stringIndex: Index[String, Int, Char] = Index(
Expand Down
17 changes: 8 additions & 9 deletions example/src/test/scala/monocle/function/IndexExample.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@ class IndexExample extends MonocleSuite {
(IMap("One" -> 1, "Two" -> 2) applyOptional index("One") set 2) shouldEqual IMap("One" -> 2, "Two" -> 2)
}

// TODO commented for 2.13
// test("index creates an Optional from a List, IList, Vector or Stream to a value at the index") {
// (List(0,1,2,3) applyOptional index(1) getOption) shouldEqual Some(1)
// (List(0,1,2,3) applyOptional index(8) getOption) shouldEqual None
//
// (Vector(0,1,2,3) applyOptional index(1) modify(_ + 1)) shouldEqual Vector(0,2,2,3)
// // setting or modifying a value at an index without value is a no op
// (Stream(0,1,2,3) applyOptional index(64) set 10) shouldEqual Stream(0,1,2,3)
// }
test("index creates an Optional from a List, IList, Vector or Stream to a value at the index") {
(List(0,1,2,3) applyOptional index(1) getOption) shouldEqual Some(1)
(List(0,1,2,3) applyOptional index(8) getOption) shouldEqual None

(Vector(0,1,2,3) applyOptional index(1) modify(_ + 1)) shouldEqual Vector(0,2,2,3)
// setting or modifying a value at an index without value is a no op
(Stream(0,1,2,3) applyOptional index(64) set 10) shouldEqual Stream(0,1,2,3)
}

test("index creates an Optional from a OneAnd to a value at the index") {
(OneAnd(1, List(2,3)) applyOptional index(0) getOption) shouldEqual Some(1)
Expand Down
16 changes: 0 additions & 16 deletions test/shared/src/test/scala/monocle/function/AtSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,4 @@ class AtSpec extends MonocleSuite {

checkAll("fromIso", AtTests[MMap[Int, String], Int, Option[String]])

// TODO commented for 2.13
// test("remove deletes a key") {
//
// val mapAndIndexGen: Gen[(Map[Int, String], Int)] = for {
// m <- Arbitrary.arbitrary[Map[Int, String]]
// i <- if(m.isEmpty) Arbitrary.arbInt.arbitrary
// else Gen.frequency(
// (8, Gen.oneOf(m.keys.toList)),
// (2, Arbitrary.arbInt.arbitrary))
// } yield (m, i)
//
// forAll(mapAndIndexGen) { case (m, i) =>
// remove(i)(m) should be (m - i)
// }
// }

}
3 changes: 1 addition & 2 deletions test/shared/src/test/scala/monocle/std/StreamSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ class StreamSpec extends MonocleSuite {
checkAll("cons Stream", ConsTests[Stream[Int], Int])
checkAll("snoc Stream", SnocTests[Stream[Int], Int])
checkAll("each Stream", EachTests[Stream[Int], Int])
// TODO commented for 2.13
// checkAll("index Stream", IndexTests[Stream[Int], Int, Int])
checkAll("index Stream", IndexTests[Stream[Int], Int, Int])
checkAll("filterIndex Stream", FilterIndexTests[Stream[Int], Int, Int])

checkAll("plated Stream", TraversalTests(plate[Stream[Int]]))
Expand Down
19 changes: 7 additions & 12 deletions test/shared/src/test/scala/monocle/unsafe/UnsafeSelectSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import monocle.MonocleSuite
import monocle.law.discipline.OptionalTests
import monocle.macros.GenLens
import org.scalacheck.Arbitrary

import scalaz.Equal


Expand All @@ -22,17 +21,13 @@ class UnsafeSelectSpec extends MonocleSuite {
prism.getOption(prism.reverseGet(valueBad)) shouldEqual None
}

// TODO commented for 2.13
// test("Predicate should work") {
// val p: Int => Boolean = _ > 10
// val prism = UnsafeSelect.unsafeSelect(p)
//
// val genPass = Arbitrary.arbitrary[Int].retryUntil(p)
// forAll(genPass)(i => prism.getOption(i) shouldEqual Some(i))
//
// val genFail = Arbitrary.arbitrary[Int].retryUntil(!p(_))
// forAll(genFail)(i => prism.getOption(i) shouldEqual None)
// }
test("Predicate should work") {
val p: Int => Boolean = _ > 10
val prism = UnsafeSelect.unsafeSelect(p)

prism.getOption(12) shouldEqual Some(12)
prism.getOption(8) shouldEqual None
}

case class Person(name: String, age: Int)

Expand Down

0 comments on commit 72e5792

Please sign in to comment.