Skip to content

Commit

Permalink
source position
Browse files Browse the repository at this point in the history
  • Loading branch information
bowenliang123 committed Sep 21, 2023
1 parent bf7d523 commit 7541c97
Showing 1 changed file with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ import scala.collection.Traversable
import scala.io.Source
import scala.reflect.ClassTag

import org.scalactic.{source, Prettifier}
import org.scalactic.Prettifier
import org.scalactic.source.Position
import org.scalatest.Assertions._

object AssertionUtils {

def assertEqualsIgnoreCase(expected: AnyRef)(actual: AnyRef)(
implicit pos: source.Position): Unit = {
implicit pos: Position): Unit = {
val isEqualsIgnoreCase = (Option(expected), Option(actual)) match {
case (Some(expectedStr: String), Some(actualStr: String)) =>
expectedStr.equalsIgnoreCase(actualStr)
Expand All @@ -44,15 +45,15 @@ object AssertionUtils {
}
}

def assertStartsWithIgnoreCase(expectedPrefix: String)(actual: String)(
implicit pos: source.Position): Unit = {
def assertStartsWithIgnoreCase(expectedPrefix: String)(actual: String)(implicit
pos: Position): Unit = {
if (!actual.toLowerCase(Locale.ROOT).startsWith(expectedPrefix.toLowerCase(Locale.ROOT))) {
fail(s"Expected starting with '$expectedPrefix' ignoring case, but got [$actual]")(pos)
}
}

def assertExistsIgnoreCase(expected: String)(actual: Iterable[String])(
implicit pos: source.Position): Unit = {
def assertExistsIgnoreCase(expected: String)(actual: Iterable[String])(implicit
pos: Position): Unit = {
if (!actual.exists(_.equalsIgnoreCase(expected))) {
fail(s"Expected containing '$expected' ignoring case, but got [$actual]")(pos)
}
Expand All @@ -73,7 +74,7 @@ object AssertionUtils {
regenScript: String,
splitFirstExpectedLine: Boolean = false)(implicit
prettifier: Prettifier,
pos: source.Position): Unit = {
pos: Position): Unit = {
val fileSource = Source.fromFile(path.toUri, StandardCharsets.UTF_8.name())
try {
def expectedLinesIter = if (splitFirstExpectedLine) {
Expand Down Expand Up @@ -109,7 +110,7 @@ object AssertionUtils {
*/
def assertContains(iter: TraversableOnce[AnyRef], elems: AnyRef*)(implicit
prettifier: Prettifier,
pos: source.Position): Unit = {
pos: Position): Unit = {
val iterableSeq = iter.toSeq
elems.foreach { elem =>
assert(iterableSeq.contains(elem), s", expected containing [${elems.mkString(", ")}]")(
Expand All @@ -124,7 +125,7 @@ object AssertionUtils {
*/
def interceptEquals[T <: Exception](f: => Any)(expected: String)(implicit
classTag: ClassTag[T],
pos: source.Position): Unit = {
pos: Position): Unit = {
assert(expected != null)
val exception = intercept[T](f)(classTag, pos)
assertResult(expected)(exception.getMessage)
Expand All @@ -136,7 +137,7 @@ object AssertionUtils {
*/
def interceptContains[T <: Exception](f: => Any)(contained: String)(implicit
classTag: ClassTag[T],
pos: source.Position): Unit = {
pos: Position): Unit = {
assert(contained != null)
val exception = intercept[T](f)(classTag, pos)
assert(exception.getMessage.contains(contained))
Expand Down

0 comments on commit 7541c97

Please sign in to comment.