Skip to content

Commit

Permalink
Merge pull request #59 from ldrygala/tests-for-modify-polymorphic-field
Browse files Browse the repository at this point in the history
add tests for modify polymorphic field
  • Loading branch information
adamw authored May 17, 2020
2 parents 4c5defa + d0a52f5 commit 84fd34d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ class ModifyPimpTest extends AnyFlatSpec with Matchers {
it should "modify several fields" in {
b1.modifyAll(_.b2, _.b3.each).using(duplicate) should be(b1dupdup)
}

it should "modify polymorphic case class field" in {
aPoly.modify(_.poly).using(duplicate) should be(aPolyDup)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,22 @@ class ModifySimpleTest extends AnyFlatSpec with Matchers {
modify(a5)(_.name).usingIf(true)(duplicate) should be(a5dup)
}

it should "leave a case class unchanged if the condition is flase" in {
it should "leave a case class unchanged if the condition is false" in {
modify(a5)(_.name).usingIf(false)(duplicate) should be(a5)
}

it should "modify polymorphic case class field" in {
modify(aPoly)(_.poly).using(duplicate) should be(aPolyDup)
}

it should "modify polymorphic case class field using apply" in {
modify(aPoly)(_.poly)(duplicate) should be(aPolyDup)
}

it should "modify polymorphic case class field if condition is true" in {
modify(aPoly)(_.poly).usingIf(true)(duplicate) should be(aPolyDup)
}
it should "leave a polymorphic case class field if condition is false" in {
modify(aPoly)(_.poly).usingIf(false)(duplicate) should be(aPoly)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ object TestData {
val a1dupdup = A1(A2(A3(A4(A5("datadatadatadata")))))
val a1mod = A1(A2(A3(A4(A5("mod")))))

case class APoly[T](poly: T, i: Int)
val aPoly = APoly("data", 1)
val aPolyDup = APoly("datadata", 1)

case class B1(b2: String, b3: Option[String])

val b1 = B1("data", Some("data"))
Expand Down

0 comments on commit 84fd34d

Please sign in to comment.