Skip to content

Commit

Permalink
Merge branch 'feature-gen-trav-iterable-refactor' of https://github.c…
Browse files Browse the repository at this point in the history
  • Loading branch information
cheeseng committed Dec 12, 2023
2 parents 9471556 + 2959099 commit 654387a
Show file tree
Hide file tree
Showing 168 changed files with 1,281 additions and 1,380 deletions.
152 changes: 76 additions & 76 deletions dotty/core/src/main/scala/org/scalatest/Inspectors.scala

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import org.scalatest._
import org.scalatest.exceptions._
import org.scalactic.{source, Prettifier}
import scala.annotation.tailrec
import scala.collection.GenTraversable
import org.scalactic.ColCompatHelper.Iterable
import StackDepthExceptionHelper.getStackDepth
import Suite.indentLines
import org.scalatest.FailureMessages.decorateToStringValue
Expand All @@ -40,37 +40,37 @@ trait InspectorAsserting[T, R] {
/**
* Implementation method for <code>Inspectors</code> <code>forAll</code> syntax.
*/
def forAll[E](xs: GenTraversable[E], original: Any, shorthand: Boolean, prettifier: Prettifier, pos: source.Position)(fun: E => T): R
def forAll[E](xs: Iterable[E], original: Any, shorthand: Boolean, prettifier: Prettifier, pos: source.Position)(fun: E => T): R

/**
* Implementation method for <code>Inspectors</code> <code>forAtLeast</code> syntax.
*/
def forAtLeast[E](min: Int, xs: GenTraversable[E], original: Any, shorthand: Boolean, prettifier: Prettifier, pos: source.Position)(fun: E => T): R
def forAtLeast[E](min: Int, xs: Iterable[E], original: Any, shorthand: Boolean, prettifier: Prettifier, pos: source.Position)(fun: E => T): R

/**
* Implementation method for <code>Inspectors</code> <code>forAtMost</code> syntax.
*/
def forAtMost[E](max: Int, xs: GenTraversable[E], original: Any, shorthand: Boolean, prettifier: Prettifier, pos: source.Position)(fun: E => T): R
def forAtMost[E](max: Int, xs: Iterable[E], original: Any, shorthand: Boolean, prettifier: Prettifier, pos: source.Position)(fun: E => T): R

/**
* Implementation method for <code>Inspectors</code> <code>forExactly</code> syntax.
*/
def forExactly[E](succeededCount: Int, xs: GenTraversable[E], original: Any, shorthand: Boolean, prettifier: Prettifier, pos: source.Position)(fun: E => T): R
def forExactly[E](succeededCount: Int, xs: Iterable[E], original: Any, shorthand: Boolean, prettifier: Prettifier, pos: source.Position)(fun: E => T): R

/**
* Implementation method for <code>Inspectors</code> <code>forNo</code> syntax.
*/
def forNo[E](xs: GenTraversable[E], original: Any, shorthand: Boolean, prettifier: Prettifier, pos: source.Position)(fun: E => T): R
def forNo[E](xs: Iterable[E], original: Any, shorthand: Boolean, prettifier: Prettifier, pos: source.Position)(fun: E => T): R

/**
* Implementation method for <code>Inspectors</code> <code>forBetween</code> syntax.
*/
def forBetween[E](from: Int, upTo: Int, xs: GenTraversable[E], original: Any, shorthand: Boolean, prettifier: Prettifier, pos: source.Position)(fun: E => T): R
def forBetween[E](from: Int, upTo: Int, xs: Iterable[E], original: Any, shorthand: Boolean, prettifier: Prettifier, pos: source.Position)(fun: E => T): R

/**
* Implementation method for <code>Inspectors</code> <code>forEvery</code> syntax.
*/
def forEvery[E](xs: GenTraversable[E], original: Any, shorthand: Boolean, prettifier: Prettifier, pos: source.Position)(fun: E => T): R
def forEvery[E](xs: Iterable[E], original: Any, shorthand: Boolean, prettifier: Prettifier, pos: source.Position)(fun: E => T): R
}

/**
Expand All @@ -87,7 +87,7 @@ abstract class UnitInspectorAsserting {
import InspectorAsserting._

// Inherit Scaladoc for now. See later if can just make this implementation class private[scalatest].
def forAll[E](xs: GenTraversable[E], original: Any, shorthand: Boolean, prettifier: Prettifier, pos: source.Position)(fun: E => T): R = {
def forAll[E](xs: Iterable[E], original: Any, shorthand: Boolean, prettifier: Prettifier, pos: source.Position)(fun: E => T): R = {
val xsIsMap = isMap(original)
val result =
runFor(xs.toIterator, xsIsMap, 0, new ForResult[E], fun, _.failedElements.length > 0)
Expand All @@ -104,7 +104,7 @@ abstract class UnitInspectorAsserting {
else indicateSuccess("forAll succeeded")
}

def forAtLeast[E](min: Int, xs: GenTraversable[E], original: Any, shorthand: Boolean, prettifier: Prettifier, pos: source.Position)(fun: E => T): R = {
def forAtLeast[E](min: Int, xs: Iterable[E], original: Any, shorthand: Boolean, prettifier: Prettifier, pos: source.Position)(fun: E => T): R = {
@tailrec
def forAtLeastAcc(itr: Iterator[E], includeIndex: Boolean, index: Int, passedCount: Int, messageAcc: IndexedSeq[String]): (Int, IndexedSeq[String]) = {
if (itr.hasNext) {
Expand Down Expand Up @@ -155,7 +155,7 @@ abstract class UnitInspectorAsserting {
else indicateSuccess("forAtLeast succeeded")
}

def forAtMost[E](max: Int, xs: GenTraversable[E], original: Any, shorthand: Boolean, prettifier: Prettifier, pos: source.Position)(fun: E => T): R = {
def forAtMost[E](max: Int, xs: Iterable[E], original: Any, shorthand: Boolean, prettifier: Prettifier, pos: source.Position)(fun: E => T): R = {
if (max <= 0)
throw new IllegalArgumentException(Resources.forAssertionsMoreThanZero("'max'"))

Expand All @@ -174,7 +174,7 @@ abstract class UnitInspectorAsserting {
else indicateSuccess("forAtMost succeeded")
}

def forExactly[E](succeededCount: Int, xs: GenTraversable[E], original: Any, shorthand: Boolean, prettifier: Prettifier, pos: source.Position)(fun: E => T): R = {
def forExactly[E](succeededCount: Int, xs: Iterable[E], original: Any, shorthand: Boolean, prettifier: Prettifier, pos: source.Position)(fun: E => T): R = {
if (succeededCount <= 0)
throw new IllegalArgumentException(Resources.forAssertionsMoreThanZero("'succeededCount'"))

Expand Down Expand Up @@ -207,7 +207,7 @@ abstract class UnitInspectorAsserting {
else indicateSuccess("forExactly succeeded")
}

def forNo[E](xs: GenTraversable[E], original: Any, shorthand: Boolean, prettifier: Prettifier, pos: source.Position)(fun: E => T): R = {
def forNo[E](xs: Iterable[E], original: Any, shorthand: Boolean, prettifier: Prettifier, pos: source.Position)(fun: E => T): R = {
val xsIsMap = isMap(original)
val result =
runFor(xs.toIterator, xsIsMap, 0, new ForResult[E], fun, _.passedCount != 0)
Expand All @@ -223,7 +223,7 @@ abstract class UnitInspectorAsserting {
else indicateSuccess("forNo succeeded")
}

def forBetween[E](from: Int, upTo: Int, xs: GenTraversable[E], original: Any, shorthand: Boolean, prettifier: Prettifier, pos: source.Position)(fun: E => T): R = {
def forBetween[E](from: Int, upTo: Int, xs: Iterable[E], original: Any, shorthand: Boolean, prettifier: Prettifier, pos: source.Position)(fun: E => T): R = {
if (from < 0)
throw new IllegalArgumentException(Resources.forAssertionsMoreThanEqualZero("'from'"))
if (upTo <= 0)
Expand Down Expand Up @@ -260,7 +260,7 @@ abstract class UnitInspectorAsserting {
else indicateSuccess("forBetween succeeded")
}

def forEvery[E](xs: GenTraversable[E], original: Any, shorthand: Boolean, prettifier: Prettifier, pos: source.Position)(fun: E => T): R = {
def forEvery[E](xs: Iterable[E], original: Any, shorthand: Boolean, prettifier: Prettifier, pos: source.Position)(fun: E => T): R = {
@tailrec
def runAndCollectErrorMessage[E](itr: Iterator[E], messageList: IndexedSeq[String], index: Int)(fun: E => T): IndexedSeq[String] = {
if (itr.hasNext) {
Expand Down Expand Up @@ -393,7 +393,7 @@ object InspectorAsserting extends UnitInspectorAsserting /*ExpectationInspectorA
implicit def executionContext: ExecutionContext

// Inherit Scaladoc for now. See later if can just make this implementation class private[scalatest].
def forAll[E](xs: GenTraversable[E], original: Any, shorthand: Boolean, prettifier: Prettifier, pos: source.Position)(fun: E => Future[T]): Future[T] = {
def forAll[E](xs: Iterable[E], original: Any, shorthand: Boolean, prettifier: Prettifier, pos: source.Position)(fun: E => Future[T]): Future[T] = {
val xsIsMap = isMap(original)
val future = runAsyncSerial(xs.toIterator, xsIsMap, 0, new ForResult[E], fun, _.failedElements.length > 0)
future.map { result =>
Expand All @@ -410,7 +410,7 @@ object InspectorAsserting extends UnitInspectorAsserting /*ExpectationInspectorA
}
}

def forAtLeast[E](min: Int, xs: GenTraversable[E], original: Any, shorthand: Boolean, prettifier: Prettifier, pos: source.Position)(fun: E => Future[T]): Future[T] = {
def forAtLeast[E](min: Int, xs: Iterable[E], original: Any, shorthand: Boolean, prettifier: Prettifier, pos: source.Position)(fun: E => Future[T]): Future[T] = {
def forAtLeastAcc(itr: Iterator[E], includeIndex: Boolean, index: Int, passedCount: Int, messageAcc: IndexedSeq[String]): Future[(Int, IndexedSeq[String])] = {
if (itr.hasNext) {
val head = itr.next
Expand Down Expand Up @@ -483,7 +483,7 @@ object InspectorAsserting extends UnitInspectorAsserting /*ExpectationInspectorA
}
}

def forAtMost[E](max: Int, xs: GenTraversable[E], original: Any, shorthand: Boolean, prettifier: Prettifier, pos: source.Position)(fun: E => Future[T]): Future[T] = {
def forAtMost[E](max: Int, xs: Iterable[E], original: Any, shorthand: Boolean, prettifier: Prettifier, pos: source.Position)(fun: E => Future[T]): Future[T] = {
if (max <= 0)
throw new IllegalArgumentException(Resources.forAssertionsMoreThanZero("'max'"))

Expand All @@ -503,7 +503,7 @@ object InspectorAsserting extends UnitInspectorAsserting /*ExpectationInspectorA
}
}

def forExactly[E](succeededCount: Int, xs: GenTraversable[E], original: Any, shorthand: Boolean, prettifier: Prettifier, pos: source.Position)(fun: E => Future[T]): Future[T] = {
def forExactly[E](succeededCount: Int, xs: Iterable[E], original: Any, shorthand: Boolean, prettifier: Prettifier, pos: source.Position)(fun: E => Future[T]): Future[T] = {
if (succeededCount <= 0)
throw new IllegalArgumentException(Resources.forAssertionsMoreThanZero("'succeededCount'"))

Expand Down Expand Up @@ -537,7 +537,7 @@ object InspectorAsserting extends UnitInspectorAsserting /*ExpectationInspectorA
}
}

def forNo[E](xs: GenTraversable[E], original: Any, shorthand: Boolean, prettifier: Prettifier, pos: source.Position)(fun: E => Future[T]): Future[T] = {
def forNo[E](xs: Iterable[E], original: Any, shorthand: Boolean, prettifier: Prettifier, pos: source.Position)(fun: E => Future[T]): Future[T] = {
val xsIsMap = isMap(original)
val future = runAsyncSerial(xs.toIterator, xsIsMap, 0, new ForResult[E], fun, _.passedCount != 0)
future.map { result =>
Expand All @@ -554,7 +554,7 @@ object InspectorAsserting extends UnitInspectorAsserting /*ExpectationInspectorA
}
}

def forBetween[E](from: Int, upTo: Int, xs: GenTraversable[E], original: Any, shorthand: Boolean, prettifier: Prettifier, pos: source.Position)(fun: E => Future[T]): Future[T] = {
def forBetween[E](from: Int, upTo: Int, xs: Iterable[E], original: Any, shorthand: Boolean, prettifier: Prettifier, pos: source.Position)(fun: E => Future[T]): Future[T] = {
if (from < 0)
throw new IllegalArgumentException(Resources.forAssertionsMoreThanEqualZero("'from'"))
if (upTo <= 0)
Expand Down Expand Up @@ -592,7 +592,7 @@ object InspectorAsserting extends UnitInspectorAsserting /*ExpectationInspectorA
}
}

def forEvery[E](xs: GenTraversable[E], original: Any, shorthand: Boolean, prettifier: Prettifier, pos: source.Position)(fun: E => Future[T]): Future[T] = {
def forEvery[E](xs: Iterable[E], original: Any, shorthand: Boolean, prettifier: Prettifier, pos: source.Position)(fun: E => Future[T]): Future[T] = {
val xsIsMap = isMap(original)
val future = runAsyncParallel(xs, xsIsMap, fun)(executionContext)
future.map { result =>
Expand Down Expand Up @@ -669,18 +669,18 @@ object InspectorAsserting extends UnitInspectorAsserting /*ExpectationInspectorA
if (xsIsMap)
Resources.forAssertionsGenMapMessageWithStackDepth(messageKey, sde.getMessage, failedCodeFileNameAndLineNumber)
else
Resources.forAssertionsGenTraversableMessageWithStackDepth(messageKey, sde.getMessage, failedCodeFileNameAndLineNumber)
Resources.forAssertionsIterableMessageWithStackDepth(messageKey, sde.getMessage, failedCodeFileNameAndLineNumber)
case None =>
if (xsIsMap)
Resources.forAssertionsGenMapMessageWithoutStackDepth(messageKey, sde.getMessage)
else
Resources.forAssertionsGenTraversableMessageWithoutStackDepth(messageKey, sde.getMessage)
Resources.forAssertionsIterableMessageWithoutStackDepth(messageKey, sde.getMessage)
}
case _ =>
if (xsIsMap)
Resources.forAssertionsGenMapMessageWithoutStackDepth(messageKey, if (t.getMessage != null) t.getMessage else "null")
else
Resources.forAssertionsGenTraversableMessageWithoutStackDepth(messageKey, if (t.getMessage != null) t.getMessage else "null")
Resources.forAssertionsIterableMessageWithoutStackDepth(messageKey, if (t.getMessage != null) t.getMessage else "null")
}

private[scalatest] final def elementLabel(count: Int): String =
Expand Down Expand Up @@ -724,7 +724,7 @@ object InspectorAsserting extends UnitInspectorAsserting /*ExpectationInspectorA
result
}

private[scalatest] final def runAsyncParallel[T, ASSERTION](col: scala.collection.GenTraversable[T], xsIsMap: Boolean, fun: T => Future[ASSERTION])(implicit ctx: ExecutionContext): Future[ForResult[T]] = {
private[scalatest] final def runAsyncParallel[T, ASSERTION](col: Iterable[T], xsIsMap: Boolean, fun: T => Future[ASSERTION])(implicit ctx: ExecutionContext): Future[ForResult[T]] = {
val futCol: IndexedSeq[Future[(T, Int, Try[ASSERTION])]] =
col.toIndexedSeq.zipWithIndex map { case (next, idx) =>
try {
Expand Down

0 comments on commit 654387a

Please sign in to comment.