-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #96 from OndrejSpanel/pr-modify-tuple
Tuple modification fails with Scala 3
- Loading branch information
Showing
2 changed files
with
43 additions
and
8 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
29 changes: 29 additions & 0 deletions
29
quicklens/src/test/scala/com/softwaremill/quicklens/TupleModifyTest.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,29 @@ | ||
package com.softwaremill.quicklens | ||
|
||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
class TupleModifyTest extends AnyFlatSpec with Matchers { | ||
it should "modify case classes using setTo" in { | ||
case class Pair(a: Int, b: Int) | ||
val p = Pair(0, 1) | ||
val modified = p.modify(_.b).setTo(2) | ||
modified shouldBe Pair(0, 2) | ||
} | ||
it should "modify tuples using setTo" in { | ||
val tuple = (0, 1) | ||
val modified = tuple.modify(_._2).setTo(2) | ||
modified shouldBe ((0, 2)) | ||
} | ||
it should "modify tuples using using" in { | ||
val tuple4 = (0, 1, 2, 3) | ||
val modified = tuple4.modify(_._3).using(_ + 1) | ||
modified shouldBe ((0, 1, 3, 3)) | ||
} | ||
|
||
it should "modify tuples using multiple modify" in { | ||
val tuple4 = (0, 1, 2, 3) | ||
val modified = tuple4.modify(_._3).using(_ + 1).modify(_._4).using(_ + 1) | ||
modified shouldBe ((0, 1, 3, 4)) | ||
} | ||
} |