-
Notifications
You must be signed in to change notification settings - Fork 407
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
Enable lazy construction of label strings #1041
base: main
Are you sure you want to change the base?
Conversation
97e168c
to
818097a
Compare
818097a
to
728710e
Compare
@@ -583,6 +583,8 @@ object GenSpecification extends Properties("Gen") with GenSpecificationVersionSp | |||
} | |||
val avg = sum / n | |||
s"average = $avg" |: avg >= 0.49 && avg <= 0.51 | |||
s"average = $avg".ensuring(false, "eager evaluation") =|= avg >= 0.49 && avg <= 0.51 | |||
avg >= 0.49 && avg <= 0.51 =|= s"average = $avg" |
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.
just to exercise the idioms in the absence of tests
On precedence, the trade-off is the |
* The label is evaluated lazily. The operator name is chosen for its precedence btween boolean operators and | ||
* others. | ||
*/ | ||
def =|=(label: => String): Prop = prop.map(_.label(label)) |
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.
Another part of my PR (#979) was to avoid evaluating the label if it will never be displayed to the user. What do you think about doing the same here?
def =|=(label: => String): Prop =
prop.map(r =>
r.status match {
case Prop.False | Prop.Exception(_) => r.label(l)
case Prop.Proof | Prop.True | Prop.Undecided => r
})
* | ||
* The operator name is chosen for its precedence between boolean operators and others. | ||
*/ | ||
extension (prop: Prop) def =|=(label: => String): Prop = prop.map(_.label(label)) |
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.
Does Scala 3 not need an extension
for Boolean
like the Scala 2 version?
@satorg @som-snytt do you have any thoughts on moving this or #979 forward? |
A different take on #979
Instead of recycling
|:
for labeling, use=|=
for improved symmetry and operator precedence.A second commit follows up scalafmt config by "fixing" star alignment in doc comments. Edit: That hassle is reserved for another effort.