All Downloads are FREE. Search and download functionalities are using the official Maven repository.

harness.zio.test.AssertionHelpers.scala Maven / Gradle / Ivy

There is a newer version: 5.1.3
Show newest version
package harness.zio.test

import cats.data.NonEmptyList
import zio.test.*
import zio.test.Assertion.*

object AssertionHelpers {

  extension [A](self: Assertion[A]) {

    def imap[B](name: String)(f: PartialFunction[B, A]): Assertion[B] =
      assertionRec[B, A](name)(self)(f.lift(_))

  }

  extension [A](self: Assertion[Seq[A]]) {

    def toNelAssertion: Assertion[NonEmptyList[A]] =
      self.imap("NonEmptyList")(_.toList)

  }

  def assertSeq[A](assertions: Assertion[A]*): Assertion[Seq[A]] =
    assertions.toList.zipWithIndex.foldLeft[Assertion[Seq[A]]](
      hasSize(equalTo(assertions.size)),
    ) { case (accum, (a, i)) =>
      accum && hasAt(i)(a)
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy