-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid repeatedly evaluating the source if it's a complex expression #115
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(0) | ||
.modify(_.b.a2).setTo(0) | ||
.modify(_.b.a3).setTo(0) | ||
.modify(_.b.a4).setTo(0) | ||
.modify(_.b.a5).setTo(0) | ||
""") | ||
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) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While the code currently does not compile, would it really be a bug if it did? It does compile in Scala 2. I think
assertDoesNotCompile
should not be used here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's in Scala3 sources as
assertDoesNotCompile
is a Scala3-only thing as far as I know (in ScalaTest).As for this not compiling... I though that was the point showing the compiler timing issue (which is fixed here), but now I see there are two problems
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've extracted this as a separate issue, #116
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And changed the type here to an unrelated one, which definitely shouldn't work :)