-
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 #236 from softwaremill/i234
Allow for using explicit copy methods in classes
- Loading branch information
Showing
3 changed files
with
91 additions
and
55 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
2 changes: 1 addition & 1 deletion
2
quicklens/src/main/scala-3/com/softwaremill/quicklens/package.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
25 changes: 25 additions & 0 deletions
25
quicklens/src/test/scala-3/com/softwaremill/quicklens/test/ExplicitCopyTest.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,25 @@ | ||
package com.softwaremill.quicklens | ||
|
||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
class ExplicitCopyTest extends AnyFlatSpec with Matchers { | ||
it should "modify a class with an explicit copy method" in { | ||
case class V(x: Double, y: Double) | ||
class Vec(val v: V) { | ||
def x: Double = v.x | ||
def y: Double = v.y | ||
def copy(x: Double = v.x, y: Double = v.y): Vec = new Vec(V(x, y)) {} | ||
def show: String = s"Vec(${v.x}, ${v.y})" | ||
} | ||
object Vec { | ||
def apply(x: Double, y: Double): Vec = new Vec(V(x, y)) {} | ||
} | ||
|
||
val vec = Vec(1, 2) | ||
val modified = vec.modify(_.x).using(_ + 1) | ||
val expected = Vec(2, 2) | ||
modified.show shouldEqual expected.show | ||
} | ||
|
||
} |