-
Notifications
You must be signed in to change notification settings - Fork 408
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* ScalaCheck | ||
* Copyright (c) 2007-2021 Rickard Nilsson. All rights reserved. | ||
* http://www.scalacheck.org | ||
* | ||
* This software is released under the terms of the Revised BSD License. | ||
* There is NO WARRANTY. See the file LICENSE for the full text. | ||
*/ | ||
|
||
package org.scalacheck | ||
|
||
object `package` { | ||
implicit class `by-name label :|`(private val prop: Prop) extends AnyVal { | ||
|
||
/** Label this property. | ||
* | ||
* 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 commentThe 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
}) |
||
} | ||
// chained implicit for true =|= label | ||
implicit class `by-name label bool :| label`(private val bool: Boolean) extends AnyVal { | ||
def =|=(label: => String): Prop = (bool: Prop).=|=(label) | ||
} | ||
implicit class `by-name label |: prop`(label: => String) { | ||
def =|=(prop: Prop): Prop = prop.=|=(label) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* ScalaCheck | ||
* Copyright (c) 2007-2021 Rickard Nilsson. All rights reserved. | ||
* http://www.scalacheck.org | ||
* | ||
* This software is released under the terms of the Revised BSD License. | ||
* There is NO WARRANTY. See the file LICENSE for the full text. | ||
*/ | ||
|
||
package org.scalacheck | ||
|
||
object `package` { | ||
|
||
/** Label this property. The label is evaluated lazily. | ||
* | ||
* 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 commentThe reason will be displayed to describe this comment to others. Learn more. Does Scala 3 not need an |
||
|
||
extension (label: => String) def =|=(prop: Prop): 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.
just to exercise the idioms in the absence of tests