-
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 #115 from softwaremill/cache-obj
Avoid repeatedly evaluating the source if it's a complex expression
- Loading branch information
Showing
3 changed files
with
73 additions
and
1 deletion.
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
27 changes: 27 additions & 0 deletions
27
quicklens/src/test/scala-3/com/softwaremill/quicklens/test/CompileTimeTest.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,27 @@ | ||
package com.softwaremill.quicklens.test | ||
|
||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
class CompileTimeTest extends AnyFlatSpec with Matchers { | ||
// #114 | ||
it should "not compile for too long in case of chained modify invocations" in { | ||
val start = System.currentTimeMillis() | ||
assertDoesNotCompile(""" | ||
case class B(a1: Double, a2: Double, a3: Double, a4: Double, a5: Double) | ||
case class C(b: B) | ||
import com.softwaremill.quicklens.* | ||
val c = C(B(1, 1, 1, 1, 1)) | ||
c | ||
.modify(_.b.a1).setTo("") | ||
.modify(_.b.a2).setTo("") | ||
.modify(_.b.a3).setTo("") | ||
.modify(_.b.a4).setTo("") | ||
.modify(_.b.a5).setTo("") | ||
""") | ||
val end = System.currentTimeMillis() | ||
(end - start) shouldBe <=(5000L) // that's a lot anyway | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
quicklens/src/test/scala/com/softwaremill/quicklens/RepeatedModifyTest.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,43 @@ | ||
package com.softwaremill.quicklens | ||
|
||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
class RepeatedModifyTest extends AnyFlatSpec with Matchers { | ||
import RepeatedModifyTest._ | ||
|
||
it should "properly handle repeated modify invocations for different fields" in { | ||
val c = C(B(1, 1, 1, 1, 1)) | ||
c | ||
.modify(_.b.a1) | ||
.setTo(0.0d) | ||
.modify(_.b.a2) | ||
.setTo(0.0d) | ||
.modify(_.b.a3) | ||
.setTo(0.0d) | ||
.modify(_.b.a4) | ||
.setTo(0.0d) | ||
.modify(_.b.a5) | ||
.setTo(0.0d) shouldBe C(B(0, 0, 0, 0, 0)) | ||
} | ||
|
||
it should "properly handle repeated modify invocations for the same field" in { | ||
val c = C(B(1, 1, 1, 1, 1)) | ||
c | ||
.modify(_.b.a1) | ||
.setTo(0.0d) | ||
.modify(_.b.a1) | ||
.setTo(1.0d) | ||
.modify(_.b.a1) | ||
.setTo(2.0d) | ||
.modify(_.b.a1) | ||
.setTo(3.0d) | ||
.modify(_.b.a1) | ||
.setTo(4.0d) shouldBe C(B(4, 1, 1, 1, 1)) | ||
} | ||
} | ||
|
||
object RepeatedModifyTest { | ||
case class B(a1: Double, a2: Double, a3: Double, a4: Double, a5: Double) | ||
case class C(b: B) | ||
} |