Skip to content
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

Remaining Scala 3 Infix #2315

Merged
merged 14 commits into from Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion jvm/core/src/main/scala/org/scalatest/Doc.scala
Expand Up @@ -109,7 +109,10 @@ private[scalatest] trait Doc extends Suite { thisDoc =>
* Returns a list containing the suites mentioned in the body XML element,
* in the order they were mentioned.
*/
final override lazy val nestedSuites: collection.immutable.IndexedSeq[Suite] = for (IncludedSuite(suite) <- snippets) yield suite
final override lazy val nestedSuites: collection.immutable.IndexedSeq[Suite] =
snippets.collect {
case IncludedSuite(suite) => suite
}
/*
println("^^^^^^^^^^^")
println(body.text)
Expand Down
Expand Up @@ -1111,7 +1111,7 @@ trait Conductors extends PatienceConfiguration {
private def detectDeadlock(): Unit = {
// Should never get to >= before ==, but just playing it safe
if (deadlockCount >= MaxDeadlockDetectionsBeforeDeadlock) {
val errorMessage = Resources.suspectedDeadlock(MaxDeadlockDetectionsBeforeDeadlock.toString, (clockInterval scaledBy MaxDeadlockDetectionsBeforeDeadlock).prettyString)
val errorMessage = Resources.suspectedDeadlock(MaxDeadlockDetectionsBeforeDeadlock.toString, (clockInterval.scaledBy(MaxDeadlockDetectionsBeforeDeadlock)).prettyString)
firstExceptionThrown offer new RuntimeException(errorMessage)

// The mainThread is likely joined to some test thread, so wake it up. It will look and
Expand Down
Expand Up @@ -182,7 +182,7 @@ trait ScaledTimeSpans {
* @throws IllegalArgumentException if the value returned from <code>spanScaleFactor</code>
* is less than zero
*/
final def scaled(span: Span): Span = span scaledBy spanScaleFactor
final def scaled(span: Span): Span = span.scaledBy(spanScaleFactor)

/**
* The factor by which the <code>scaled</code> method will scale <code>Span</code>s.
Expand Down
10 changes: 5 additions & 5 deletions jvm/core/src/main/scala/org/scalatest/enablers/Retrying.scala
Expand Up @@ -78,7 +78,7 @@ object Retrying {
def retry(timeout: Span, interval: Span, pos: source.Position)(fun: => Future[T]): Future[T] = {
val startNanos = System.nanoTime

val initialInterval = Span(interval.totalNanos * 0.1, Nanoseconds) // config.interval scaledBy 0.1
val initialInterval = Span(interval.totalNanos * 0.1, Nanoseconds)

// Can't make this tail recursive. TODO: Document that fact.
def tryTryAgain(attempt: Int): Future[T] = {
Expand Down Expand Up @@ -120,7 +120,7 @@ object Retrying {
promise.future
}
else { // Timed out so return a failed Future
val durationSpan = Span(1, Nanosecond) scaledBy duration // Use scaledBy to get pretty units
val durationSpan = Span(1, Nanosecond).scaledBy(duration) // Use scaledBy to get pretty units
Future.failed(
new TestFailedDueToTimeoutException(
(_: StackDepthException) =>
Expand Down Expand Up @@ -150,7 +150,7 @@ object Retrying {
Thread.sleep(interval.millisPart, interval.nanosPart)
}
else {
val durationSpan = Span(1, Nanosecond) scaledBy duration // Use scaledBy to get pretty units
val durationSpan = Span(1, Nanosecond).scaledBy(duration) // Use scaledBy to get pretty units
throw new TestFailedDueToTimeoutException(
(_: StackDepthException) =>
Some(
Expand Down Expand Up @@ -189,7 +189,7 @@ object Retrying {
}
}

val initialInterval = Span(interval.totalNanos * 0.1, Nanoseconds) // config.interval scaledBy 0.1
val initialInterval = Span(interval.totalNanos * 0.1, Nanoseconds)

@tailrec
def tryTryAgain(attempt: Int): T = {
Expand All @@ -204,7 +204,7 @@ object Retrying {
Thread.sleep(interval.millisPart, interval.nanosPart)
}
else {
val durationSpan = Span(1, Nanosecond) scaledBy duration // Use scaledBy to get pretty units
val durationSpan = Span(1, Nanosecond).scaledBy(duration) // Use scaledBy to get pretty units
throw new TestFailedDueToTimeoutException(
(_: StackDepthException) =>
Some(
Expand Down
Expand Up @@ -273,17 +273,8 @@ private[scalatest] object SuiteDiscoveryHelper {
//
private def processFileNames(fileNames: Iterator[String], fileSeparator: Char, loader: ClassLoader,
suffixes: Option[Pattern]): Set[String] =
{
val classNameOptions = // elements are Some(<class name>) if processed, else None
for (className <- extractClassNames(fileNames, fileSeparator))
yield processClassName(className, loader, suffixes)

val classNames =
for (Some(className) <- classNameOptions)
yield className

Set[String]() ++ classNames.toIterable
}
Set[String]() ++
extractClassNames(fileNames, fileSeparator).flatMap(processClassName(_, loader, suffixes)).toIterable

private def getFileNamesSetFromFile(file: File, fileSeparator: Char): Set[String] = {

Expand Down Expand Up @@ -328,12 +319,6 @@ private[scalatest] object SuiteDiscoveryHelper {
// Given a fileNames iterator, returns an iterator of class names
// corresponding to .class files found.
//
private def extractClassNames(fileNames: Iterator[String], fileSeparator: Char): Iterator[String] = {
val options =
for (fileName <- fileNames) yield
transformToClassName(fileName, fileSeparator)

for (Some(className) <- options) yield
className
}
private def extractClassNames(fileNames: Iterator[String], fileSeparator: Char): Iterator[String] =
fileNames.flatMap(transformToClassName(_, fileSeparator))
}
Expand Up @@ -80,6 +80,7 @@ final class BehaveWord {
* <a href="../FlatSpec.html#SharedTests"><code>FlatSpec</code></a>, or <a href="../WordSpec.html#SharedTests"><code>WordSpec</code></a>.
* </p>
*/
//DOTTY-ONLY infix
def like(unit: Unit): Unit = ()

/**
Expand Down
4 changes: 4 additions & 0 deletions jvm/core/src/main/scala/org/scalatest/verbs/CanVerb.scala
Expand Up @@ -116,6 +116,7 @@ trait CanVerb {
* <code>"can"</code>, and right, and returns the result.
* </p>
*/
//DOTTY-ONLY infix
def can(right: String)(implicit svsi: StringVerbStringInvocation): ResultOfStringPassedToVerb = {
svsi(leftSideString, "can", right, pos)
}
Expand All @@ -139,6 +140,7 @@ trait CanVerb {
* simply invokes this function, passing in leftSideString, and returns the result.
* </p>
*/
//DOTTY-ONLY infix
def can(right: BehaveWord)(implicit svbli: StringVerbBehaveLikeInvocation): BehaveWord = {
svbli(leftSideString, pos)
}
Expand All @@ -165,6 +167,7 @@ trait CanVerb {
* no-arg function.
* </p>
*/
//DOTTY-ONLY infix
def can(right: => Unit)(implicit fun: StringVerbBlockRegistration): Unit = {
fun(leftSideString, "can", pos, () => right)
}
Expand Down Expand Up @@ -192,6 +195,7 @@ trait CanVerb {
* <code>"can"</code>, and the <code>ResultOfAfterWordApplication</code> passed to <code>can</code>.
* </p>
*/
//DOTTY-ONLY infix
def can(resultOfAfterWordApplication: ResultOfAfterWordApplication)(implicit swawr: SubjectWithAfterWordRegistration): Unit = {
swawr(leftSideString, "can", resultOfAfterWordApplication, pos)
}
Expand Down
4 changes: 4 additions & 0 deletions jvm/core/src/main/scala/org/scalatest/verbs/MustVerb.scala
Expand Up @@ -138,6 +138,7 @@ trait MustVerb {
* <code>"must"</code>, and right, and returns the result.
* </p>
*/
//DOTTY-ONLY infix
def must(right: String)(implicit svsi: StringVerbStringInvocation): ResultOfStringPassedToVerb = {
svsi(leftSideString, "must", right, pos)
}
Expand All @@ -161,6 +162,7 @@ trait MustVerb {
* simply invokes this function, passing in leftSideString, and returns the result.
* </p>
*/
//DOTTY-ONLY infix
def must(right: BehaveWord)(implicit svbli: StringVerbBehaveLikeInvocation): BehaveWord = {
svbli(leftSideString, pos)
}
Expand All @@ -187,6 +189,7 @@ trait MustVerb {
* no-arg function.
* </p>
*/
//DOTTY-ONLY infix
def must(right: => Unit)(implicit fun: StringVerbBlockRegistration): Unit = {
fun(leftSideString, "must", pos, () => right)
}
Expand Down Expand Up @@ -214,6 +217,7 @@ trait MustVerb {
* <code>"must"</code>, and the <code>ResultOfAfterWordApplication</code> passed to <code>must</code>.
* </p>
*/
//DOTTY-ONLY infix
def must(resultOfAfterWordApplication: ResultOfAfterWordApplication)(implicit swawr: SubjectWithAfterWordRegistration): Unit = {
swawr(leftSideString, "must", resultOfAfterWordApplication, pos)
}
Expand Down
Expand Up @@ -86,6 +86,7 @@ abstract class ResultOfStringPassedToVerb(val verb: String, val rest: String) {
* for trait <code>FlatSpec</code>.
* </p>
*/
//DOTTY-ONLY infix
def is(fun: => PendingStatement): Unit

/**
Expand All @@ -105,5 +106,6 @@ abstract class ResultOfStringPassedToVerb(val verb: String, val rest: String) {
* for trait <code>FlatSpec</code>.
* </p>
*/
//DOTTY-ONLY infix
def taggedAs(firstTestTag: Tag, otherTestTags: Tag*): ResultOfTaggedAsInvocation
}
Expand Up @@ -79,5 +79,6 @@ abstract class ResultOfTaggedAsInvocation(val verb: String, val rest: String, va
* in the main documentation for trait <code>FlatSpec</code>.
* </p>
*/
//DOTTY-ONLY infix
def is(testFun: => PendingStatement): Unit
}
4 changes: 4 additions & 0 deletions jvm/core/src/main/scala/org/scalatest/verbs/ShouldVerb.scala
Expand Up @@ -141,6 +141,7 @@ trait ShouldVerb {
* <code>"should"</code>, and right, and returns the result.
* </p>
*/
//DOTTY-ONLY infix
def should(right: String)(implicit svsi: StringVerbStringInvocation): ResultOfStringPassedToVerb = {
svsi(leftSideString, "should", right, pos)
}
Expand All @@ -164,6 +165,7 @@ trait ShouldVerb {
* simply invokes this function, passing in leftSideString, and returns the result.
* </p>
*/
//DOTTY-ONLY infix
def should(right: BehaveWord)(implicit svbli: StringVerbBehaveLikeInvocation): BehaveWord = {
svbli(leftSideString, pos)
}
Expand All @@ -190,6 +192,7 @@ trait ShouldVerb {
* no-arg function.
* </p>
*/
//DOTTY-ONLY infix
def should(right: => Unit)(implicit fun: StringVerbBlockRegistration): Unit = {
fun(leftSideString, "should", pos, () => right)
}
Expand Down Expand Up @@ -217,6 +220,7 @@ trait ShouldVerb {
* <code>"should"</code>, and the <code>ResultOfAfterWordApplication</code> passed to <code>should</code>.
* </p>
*/
//DOTTY-ONLY infix
def should(resultOfAfterWordApplication: ResultOfAfterWordApplication)(implicit swawr: SubjectWithAfterWordRegistration): Unit = {
swawr(leftSideString, "should", resultOfAfterWordApplication, pos)
}
Expand Down
4 changes: 4 additions & 0 deletions jvm/core/src/main/scala/org/scalatest/verbs/WillVerb.scala
Expand Up @@ -141,6 +141,7 @@ private[scalatest] trait WillVerb {
* <code>"will"</code>, and right, and returns the result.
* </p>
*/
//DOTTY-ONLY infix
def will(right: String)(implicit svsi: StringVerbStringInvocation): ResultOfStringPassedToVerb = {
svsi(leftSideString, "will", right, pos)
}
Expand All @@ -164,6 +165,7 @@ private[scalatest] trait WillVerb {
* simply invokes this function, passing in leftSideString, and returns the result.
* </p>
*/
//DOTTY-ONLY infix
def will(right: BehaveWord)(implicit svbli: StringVerbBehaveLikeInvocation): BehaveWord = {
svbli(leftSideString, pos)
}
Expand All @@ -190,6 +192,7 @@ private[scalatest] trait WillVerb {
* no-arg function.
* </p>
*/
//DOTTY-ONLY infix
def will(right: => Unit)(implicit fun: StringVerbBlockRegistration): Unit = {
fun(leftSideString, "will", pos, () => right)
}
Expand Down Expand Up @@ -217,6 +220,7 @@ private[scalatest] trait WillVerb {
* <code>"will"</code>, and the <code>ResultOfAfterWordApplication</code> passed to <code>will</code>.
* </p>
*/
//DOTTY-ONLY infix
def will(resultOfAfterWordApplication: ResultOfAfterWordApplication)(implicit swawr: SubjectWithAfterWordRegistration): Unit = {
swawr(leftSideString, "will", resultOfAfterWordApplication, pos)
}
Expand Down
1 change: 1 addition & 0 deletions jvm/scalactic-macro/src/main/scala/org/scalactic/Or.scala
Expand Up @@ -578,6 +578,7 @@ import scala.collection.mutable.Builder
* <a href="https://github.com/vpatryshev/ScalaKittens">ScalaKittens</a>.</em>
* </p>
*/
//DOTTY-ONLY infix
sealed abstract class Or[+G,+B] extends Product with Serializable {

/**
Expand Down
1 change: 1 addition & 0 deletions jvm/scalactic/src/main/scala/org/scalactic/CanEqual.scala
Expand Up @@ -25,6 +25,7 @@ import annotation.implicitNotFound
* </p>
*/
@implicitNotFound(msg = "types ${A} and ${B} do not adhere to the type constraint selected for the === and !== operators; the missing implicit parameter is of type org.scalactic.CanEqual[${A},${B}]")
//DOTTY-ONLY infix
abstract class CanEqual[A, B] {

/**
Expand Down
6 changes: 6 additions & 0 deletions jvm/scalactic/src/main/scala/org/scalactic/Explicitly.scala
Expand Up @@ -98,6 +98,7 @@ trait Explicitly {
* ^
* </pre>
*/
//DOTTY-ONLY infix
def by[A](equality: Equality[A]): DecidedByEquality[A] = new DecidedByEquality[A](equality)
}

Expand Down Expand Up @@ -130,6 +131,7 @@ trait Explicitly {
* </pre>
*
*/
//DOTTY-ONLY infix
def by[A](equivalence: Equivalence[A]): DeterminedByEquivalence[A] = new DeterminedByEquivalence[A](equivalence)
}

Expand Down Expand Up @@ -187,6 +189,7 @@ trait Explicitly {
* before comparing them for equality using the <code>Equality[A]</code> passed to this object's
* constructor.
*/
//DOTTY-ONLY infix
def afterBeing(uniformity: Uniformity[A]): NormalizingEquality[A] =
new ComposedNormalizingEquality[A](equality, uniformity)
}
Expand Down Expand Up @@ -234,6 +237,7 @@ trait Explicitly {
* before comparing them for equality using the <code>Equivalence[T]</code> passed to this object's
* constructor.
*/
//DOTTY-ONLY infix
def afterBeing(normalization: Normalization[T]): NormalizingEquivalence[T] =
new ComposedNormalizingEquivalence[T](equivalence, normalization)
}
Expand All @@ -259,6 +263,7 @@ trait Explicitly {
* before comparing it for equality with another <code>N</code> using the implicitly
* passed <code>Equality[N]</code>.
*/
//DOTTY-ONLY infix
def being[N](uniformity: Uniformity[N])(implicit equality: Equality[N]): NormalizingEquality[N] =
new ComposedNormalizingEquality[N](equality, uniformity)

Expand All @@ -277,6 +282,7 @@ trait Explicitly {
* before comparing it for equality with another <code>N</code> using the implicitly
* passed <code>Equivalence[N]</code>.
*/
//DOTTY-ONLY infix
def being[N](normalization: Normalization[N])(implicit equivalence: Equivalence[N]): NormalizingEquivalence[N] =
new ComposedNormalizingEquivalence[N](equivalence, normalization)
}
Expand Down
Expand Up @@ -98,6 +98,7 @@ trait Normalization[A] { thisNormalization =>
* @param other a <code>Normalization</code> to 'and' with this one
* @return a <code>Normalization</code> representing the composition of this and the passed <code>Normalization</code>
*/
//DOTTY-ONLY infix
final def and(other: Normalization[A]): Normalization[A] =
new Normalization[A] {
def normalized(a: A): A = other.normalized(thisNormalization.normalized(a))
Expand Down
Expand Up @@ -142,6 +142,7 @@ trait NormalizingEquality[A] extends Equality[A] { thisNormEq =>
* @param other a <code>Uniformity</code> to 'and' with this one
* @return a <code>NormalizingEquality</code> representing the composition of this and the passed <code>Uniformity</code>
*/
//DOTTY-ONLY infix
final def and(other: Uniformity[A]): NormalizingEquality[A] =
new ComposedNormalizingEquality[A](afterNormalizationEquality, this.toUniformity and other)

Expand Down
Expand Up @@ -79,6 +79,7 @@ trait NormalizingEquivalence[A] extends Equivalence[A] { thisNormEq =>
* @param a the object to normalize
* @return the normalized form of the passed object
*/
//DOTTY-ONLY infix
def normalized(a: A): A

/**
Expand All @@ -98,6 +99,7 @@ trait NormalizingEquivalence[A] extends Equivalence[A] { thisNormEq =>
* @param other a <code>Normalization</code> to 'and' with this one
* @return a <code>NormalizingEquivalence</code> representing the composition of this and the passed <code>Normalization</code>
*/
//DOTTY-ONLY infix
final def and(other: Normalization[A]): NormalizingEquivalence[A] =
new ComposedNormalizingEquivalence[A](afterNormalizationEquivalence, this.toNormalization and other)

Expand Down
3 changes: 2 additions & 1 deletion jvm/scalactic/src/main/scala/org/scalactic/Uniformity.scala
Expand Up @@ -73,7 +73,7 @@ package org.scalactic
* </p>
*
* @tparam A the type whose uniformity is being defined
*/
*/
trait Uniformity[A] extends Normalization[A] { thisUniformity =>

/**
Expand Down Expand Up @@ -214,6 +214,7 @@ trait Uniformity[A] extends Normalization[A] { thisUniformity =>
* @param other a <code>Uniformity</code> to 'and' with this one
* @return a <code>Uniformity</code> representing the composition of this and the passed <code>Uniformity</code>
*/
//DOTTY-ONLY infix
final def and(other: Uniformity[A]): Uniformity[A] =
new Uniformity[A] {
// Note in Scaladoc what order, and recommend people don't do side effects anyway.
Expand Down