diff --git a/modules/core/src/test/scala/tofu/IOSummonChecks.scala b/modules/core/src/test/scala/tofu/IOSummonChecks.scala index 2470809b0..833228b7e 100644 --- a/modules/core/src/test/scala/tofu/IOSummonChecks.scala +++ b/modules/core/src/test/scala/tofu/IOSummonChecks.scala @@ -1,16 +1,19 @@ package tofu import cats.data.ReaderT -import cats.effect.{ContextShift, IO} +import cats.effect.{Concurrent, ContextShift, IO} -class IOSummonChecks(implicit cs: ContextShift[IO]) { - implicitly[Fire[IO[*]]] - implicitly[Start[IO[*]]] - implicitly[Race[IO[*]]] - implicitly[Errors[IO, Throwable]] +import scala.annotation.nowarn - implicitly[Fire[ReaderT[IO, Unit, *]]] - implicitly[Start[ReaderT[IO, Unit, *]]] - implicitly[Race[ReaderT[IO, Unit, *]]] - implicitly[Errors[ReaderT[IO, Unit, *], Throwable]] +@nowarn("cat=unused-params") +class IOSummonChecks { + def summonForIO(implicit cs: ContextShift[IO]) = { + implicitly[Start[IO[*]]] + implicitly[Start[ReaderT[IO, Unit, *]]] + } + + def summonInstancesForConcurrent[F[_]: Concurrent] = { + implicitly[Start[F]] + implicitly[Start[ReaderT[F, Unit, *]]] + } } diff --git a/modules/core/src/test/scala/tofu/RaiseSuite.scala b/modules/core/src/test/scala/tofu/RaiseSuite.scala deleted file mode 100644 index c71914d9d..000000000 --- a/modules/core/src/test/scala/tofu/RaiseSuite.scala +++ /dev/null @@ -1,87 +0,0 @@ -package tofu - -import cats.MonadError -import Raise.ContravariantRaise -import tofu.syntax.raise._ -import cats.Applicative -import org.scalatest.funsuite.AnyFunSuite -import tofu.compat.unused - -class RaiseSuite extends AnyFunSuite { - import tofu.RaiseSuite._ - val rooster1 = new Rooster1[Either[Throwable, *]] - val rooster2 = new Rooster2[Either[Throwable, *]] - - test("error should be raised") { - assert(rooster1.crow === Left(CrowErr)) - assert(rooster1.crow2 === Left(CrowErr)) - assert(rooster1.crow3 === Left(CrowErr)) - assert(rooster1.crow4 === Left(CrowErr)) - - assert(rooster2.crow === Left(CrowErr)) - assert(rooster2.crow2 === Left(CrowErr)) - assert(rooster2.crow3 === Left(CrowErr)) - assert(rooster2.crow4 === Left(CrowErr)) - } -} - -object RaiseSuite { - trait CommonError - final case class ConcreteError() extends CommonError - final case class AnotherConcreteError() extends CommonError - - object CrowErr extends Exception("Oh no!") - case class LalErr(s: String) extends Exception(s) - - def foo0[F[_]: Raise[*[_], ConcreteError]: Raise[*[_], AnotherConcreteError]]: F[Unit] = { - ConcreteError().raise[F, Unit] - AnotherConcreteError().raise[F, Unit] - } - - def foo1[F[_]: Raise[*[_], CommonError]]: F[Unit] = - ConcreteError().raise[F, Unit] - - def foo2[F[_]: ContravariantRaise[*[_], CommonError]]: F[Unit] = - ConcreteError().raise[F, Unit] - - def foo3[F[_]: ContravariantRaise[*[_], ConcreteError]]: F[Unit] = - ConcreteError().raise[F, Unit] - - @unused - def foo4[F[_]: ContravariantRaise[*[_], ConcreteError]: ContravariantRaise[*[_], AnotherConcreteError]]: F[Unit] = - ConcreteError().raise[F, Unit] - - { - type F[+A] = Either[CommonError, A] - implicitly[MonadError[F, CommonError]] - implicitly[Raise[F, CommonError]] - implicitly[ContravariantRaise[F, CommonError]] - implicitly[Raise[F, ConcreteError]] - implicitly[ContravariantRaise[F, ConcreteError]] - } - - val e: Either[CrowErr.type, Nothing] = Left(CrowErr) - - class Rooster1[G[_]: MonadThrow] { - def crow: G[Unit] = { - CrowErr.raise - } - def crow2: G[Unit] = Option.empty[Unit].orRaise(CrowErr) - def crow3: G[Unit] = { - val err: Throwable = CrowErr - err.raise - } - def crow4: G[Unit] = e.toRaise - } - - class Rooster2[G[_]: Throws: Applicative] { - def crow: G[Unit] = CrowErr.raise - def crow2: G[Unit] = Option.empty[Unit].orRaise(CrowErr) - def crow3: G[Unit] = { - val err: Throwable = CrowErr - err.raise - } - - def crow4: G[Unit] = e.toRaise - } -} diff --git a/modules/core/src/test/scala/tofu/StartSuite.scala b/modules/core/src/test/scala/tofu/StartSuite.scala index 0c2d81151..f47f951f5 100644 --- a/modules/core/src/test/scala/tofu/StartSuite.scala +++ b/modules/core/src/test/scala/tofu/StartSuite.scala @@ -13,13 +13,11 @@ import tofu.syntax.monadic._ object StartSuite { def summonInstancesForConcurrent[F[_]: Concurrent] = { Fire[F] - Start[F] Race[F] } def summonInstancesForIO(implicit cs: ContextShift[IO]) = { Fire[IO] - Start[IO] Race[IO] MakeAgent[IO, IO] MakeSerialAgent[IO, IO] diff --git a/modules/core/src/test/scala/tofu/syntax/UnliftSuite.scala b/modules/core/src/test/scala/tofu/syntax/UnliftSuite.scala index 28b191bbb..46e3e2abf 100644 --- a/modules/core/src/test/scala/tofu/syntax/UnliftSuite.scala +++ b/modules/core/src/test/scala/tofu/syntax/UnliftSuite.scala @@ -1,4 +1,4 @@ -package tofu +package tofu.syntax import cats.effect.{Async, Concurrent, ConcurrentEffect, Effect} import tofu.lift.Unlift diff --git a/modules/core3/src/test/scala/examples/DoMonadExamples.scala b/modules/core3/src/test/scala/examples/DoMonadExamples.scala deleted file mode 100644 index 5f63f133d..000000000 --- a/modules/core3/src/test/scala/examples/DoMonadExamples.scala +++ /dev/null @@ -1,61 +0,0 @@ -package examples - -import cats.data.Chain -import tofu.alias.Do - -class DoMonadExamples { - def bar[F[_]: Do, A, B, C](f: A => F[B], g: B => F[C], h: C => F[Unit], fa: F[A]) = - for { - x <- fa - y <- f(x) - z <- g(y).flatTap(h) - } yield (x, y, z) - - def bar2[F[_]: Do, A, B, C, D](f: F[(A, B) => C], g: F[C => D], fa: F[A], fb: F[B]) = - g <*> f.ap2(fa, fb) - - def covCheck[A, B, C, E, F[_], F1[x] >: F[x], F2[x] >: F1[x]: Do]( - fa: F[A], - f: A => F1[B], - g: B => F2[C], - ) = for { - x <- fa - y <- f(x) - z <- g(y) - } yield (x, y, z) - - def eitherCheck2[A, B <: A, C <: A, E, E1 <: E, E2 <: E, E3 <: E]( - fb: Either[E1, Boolean], - fx: Either[E2, B], - fy: Either[E3, C], - ) = { - val res = fb.ifM(fx, fy) - val resCheck: Either[E, A] = res - resCheck - } - - def doStaticSyntaxCheck[F[_]: Do, A](a: A): F[A] = { - Do[F].unit - Do[F].pure(a) - } - - def doLazySyntaxCheck2[F[_]: Do, A](fa: => F[A], fb: F[Boolean]) = { - Do ~ fa when 1 == 2 - Do ~ fa unlessOpt 1 == 2 - Do ~ fa whenM fb - Do ~ fa unlessOptM fb - } - - def doLoopSyntaxCheck = { - Do loop 1 iterate (x => List(x * 2, x * 3)) whileM (_ < 100) - Do loop 1 iterate (x => List(x * 2, x * 3)) untilM (_ > 100) - Do loop 27 tailRecM (x => - ( - Chain.one(x), - if (x % 2 == 0) Left(x / 2) - else if (x > 1) Left(x * 3 + 1) - else Right(()) - ) - ) - } -} diff --git a/modules/core3/src/test/scala/tofu/ErrorsCompanion.scala b/modules/core3/src/test/scala/tofu/ErrorsCompanion.scala deleted file mode 100644 index 5b4795c20..000000000 --- a/modules/core3/src/test/scala/tofu/ErrorsCompanion.scala +++ /dev/null @@ -1,15 +0,0 @@ -package tofu - -object ErrorsCompanion { - sealed trait Err - object Err1 extends Err - object Err2 extends Err - - object Err extends Errors.Companion[Err] - - def raise[F[_]: Err.Raise]: Err.Raise[F] = Raise[F, Err] - - def handle[F[_]: Err.Handle]: Err.Handle[F] = Handle[F, Err] - - def errors[F[_]: Err.Errors]: Err.Errors[F] = Errors[F, Err] -} diff --git a/modules/core3/src/test/scala/tofu/ErrorsSuite.scala b/modules/core3/src/test/scala/tofu/ErrorsSuite.scala deleted file mode 100644 index 15057b08a..000000000 --- a/modules/core3/src/test/scala/tofu/ErrorsSuite.scala +++ /dev/null @@ -1,28 +0,0 @@ -package tofu - -import cats.instances.either.catsStdInstancesForEither -import cats.syntax.either._ -import org.scalatest.EitherValues -import org.scalatest.flatspec.AnyFlatSpec -import org.scalatest.matchers.should.Matchers -import tofu.syntax.error._ - -class ErrorsSuite extends AnyFlatSpec with Matchers with EitherValues { - - "Raise" should "reRaise" in { - val err: String = "oops" - Raise[ErrorOr, String].reRaise(toErr[ErrorOr[Unit]](err)) shouldBe toErr[Unit](err) - } - - "Errors" should "adoptError" in { - val err: String = "oops" - val pf: PartialFunction[String, String] = { case s if s == err => err + "_" + err } - val fa: ErrorOr[Unit] = Raise[ErrorOr, String].raise(err) - implicit val errors = Errors[ErrorOr, String] - fa.adaptError(pf) shouldBe toErr(pf(err)) - } - - type ErrorOr[A] = Either[String, A] - - private def toErr[A](err: String): ErrorOr[A] = err.asLeft[A] -} diff --git a/modules/core3/src/test/scala/tofu/IOSummonChecks.scala b/modules/core3/src/test/scala/tofu/IOSummonChecks.scala index b11dbc8ab..c59de5ef0 100644 --- a/modules/core3/src/test/scala/tofu/IOSummonChecks.scala +++ b/modules/core3/src/test/scala/tofu/IOSummonChecks.scala @@ -1,16 +1,14 @@ package tofu import cats.data.ReaderT -import cats.effect.{IO} +import cats.effect.{Concurrent, IO} class IOSummonChecks { - implicitly[Fire[IO[*]]] implicitly[Start[IO[*]]] - implicitly[Race[IO[*]]] - implicitly[Errors[IO, Throwable]] - - implicitly[Fire[ReaderT[IO, Unit, *]]] implicitly[Start[ReaderT[IO, Unit, *]]] - implicitly[Race[ReaderT[IO, Unit, *]]] - implicitly[Errors[ReaderT[IO, Unit, *], Throwable]] + + def summonInstancesForConcurrent[F[_]: Concurrent] = { + implicitly[Start[F]] + implicitly[Start[ReaderT[F, Unit, *]]] + } } diff --git a/modules/core3/src/test/scala/tofu/StartSuite.scala b/modules/core3/src/test/scala/tofu/StartSuite.scala index 18f74a82f..7c21fb514 100644 --- a/modules/core3/src/test/scala/tofu/StartSuite.scala +++ b/modules/core3/src/test/scala/tofu/StartSuite.scala @@ -11,14 +11,12 @@ import tofu.concurrent.{MakeAgent, MakeSerialAgent} object StartSuite { def summonInstancesForConcurrent[F[_]: Concurrent] = { Fire[F] - Start[F] Race[F] MakeAgent[IO, IO] } def summonInstancesForIO = { Fire[IO] - Start[IO] Race[IO] MakeAgent[IO, IO] MakeSerialAgent[IO, IO] diff --git a/modules/core3/src/test/scala/tofu/control/SelectiveSummon.scala b/modules/core3/src/test/scala/tofu/control/SelectiveSummon.scala deleted file mode 100644 index b78768fae..000000000 --- a/modules/core3/src/test/scala/tofu/control/SelectiveSummon.scala +++ /dev/null @@ -1,8 +0,0 @@ -package tofu.control - -import cats.data.{Chain, WriterT} -import cats.effect.IO - -object SelectiveSummon { - Selective[WriterT[IO, Chain[Int], *]] -} diff --git a/modules/core3/src/test/scala/tofu/examples/TofuRaiseExamples.scala b/modules/core3/src/test/scala/tofu/examples/TofuRaiseExamples.scala deleted file mode 100644 index cfd571795..000000000 --- a/modules/core3/src/test/scala/tofu/examples/TofuRaiseExamples.scala +++ /dev/null @@ -1,87 +0,0 @@ -package tofu.examples - -import cats.FlatMap -import cats.syntax.flatMap._ -import tofu.compat.unused -import tofu.syntax.handle._ -import tofu.syntax.raise._ -import tofu.{Errors, Handle, Raise} - -final case class User(id: Long, cardId: Long, name: String) -final case class Card(id: Long, balance: Long) - -sealed trait WithdrawalFailed extends Throwable - -final case class CardNotFound(id: Long) extends WithdrawalFailed -final case class UserNotFound(id: Long) extends WithdrawalFailed -final case class LowBalance(actual: Long, required: Long) extends WithdrawalFailed - -trait CardStorage[F[_]] { - def get(cardId: Long): F[Card] - def updateBalance(cardId: Long, newBalance: Long): F[Unit] -} - -object CardStorage { - - def make[F[_]: Raise[*[_], CardNotFound]]: CardStorage[F] = new Impl[F] - - @unused - private final class Impl[F[_]: Raise[*[_], CardNotFound]] extends CardStorage[F] { - override def get(cardId: Long): F[Card] = ??? - override def updateBalance(cardId: Long, newBalance: Long): F[Unit] = ??? - } -} - -trait UserStorage[F[_]] { - def get(userId: Long): F[User] -} - -object UserStorage { - - def make[F[_]: Raise[*[_], UserNotFound]]: UserStorage[F] = new Impl[F] - - @unused - private final class Impl[F[_]: Raise[*[_], UserNotFound]] extends UserStorage[F] { - override def get(userId: Long): F[User] = ??? - } -} - -trait WithdrawalService[F[_]] { - def withdraw(userId: Long, amount: Long): F[Unit] -} - -object WithdrawalService { - - def make[F[_]: Raise[*[_], WithdrawalFailed]: FlatMap]: WithdrawalService[F] = - new Impl[F](UserStorage.make, CardStorage.make) - - private final class Impl[F[_]: Raise[*[_], WithdrawalFailed]: FlatMap]( - userStorage: UserStorage[F], - cardStorage: CardStorage[F] - ) extends WithdrawalService[F] { - override def withdraw(userId: Long, amount: Long): F[Unit] = - userStorage.get(userId) >>= (u => cardStorage.get(u.cardId)) >>= { card => - val newBalance = card.balance - amount - if (newBalance >= 0) cardStorage.updateBalance(card.id, newBalance) - else LowBalance(card.balance, amount).raise[F, Unit] - } - } -} - -trait Payments[F[_]] { - def processPayment(userId: Long, amount: Long): F[Unit] -} - -object Payments { - - def make[F[_]: Errors[*[_], WithdrawalFailed]: FlatMap]: Payments[F] = - new Impl[F](WithdrawalService.make) - - private final class Impl[F[_]: Handle[*[_], WithdrawalFailed]]( - withdrawalService: WithdrawalService[F] - ) extends Payments[F] { - override def processPayment(userId: Long, amount: Long): F[Unit] = - withdrawalService.withdraw(userId, amount).handleWith[LowBalance](_ => denyPayment) - private def denyPayment: F[Unit] = ??? - } -} diff --git a/modules/core3/src/test/scala/tofu/syntax/FEitherSuite.scala b/modules/core3/src/test/scala/tofu/syntax/FEitherSuite.scala deleted file mode 100644 index ba4753bda..000000000 --- a/modules/core3/src/test/scala/tofu/syntax/FEitherSuite.scala +++ /dev/null @@ -1,621 +0,0 @@ -package tofu.syntax - -import cats.instances.list._ -import cats.instances.option._ -import cats.syntax.option.catsSyntaxOptionId -import cats.syntax.option.none -import cats.syntax.either._ -import org.scalatest.matchers.must.Matchers -import org.scalatest.wordspec.AnyWordSpec -import tofu.Raise -import tofu.syntax.feither._ - -class FEitherSuite extends AnyWordSpec with Matchers { - - //--Helpers------------------------------------ - - implicit class SuiteIdOps[A](id: A) { - def asRightS[L]: Option[Either[L, A]] = Some(Right(id)) - - def asLeftS[R]: Option[Either[A, R]] = Some(Left(id)) - } - - def defaultRight: Option[Either[String, Int]] = 4.asRightS[String] - - def defaultLeft: Option[Either[Int, String]] = 4.asLeftS[String] - - def testRight: Option[Either[Int, String]] = "test".asRightS[Int] - - def boomRight[L, R]: Option[Right[L, R]] = Some(Right(sys.error("boom"))) - - def boom[A]: Option[A] = Some(sys.error("boom")) - - def optionRaise[R]: Raise[Option, R] = new Raise[Option, R] { - override def raise[A](err: R): Option[A] = None - } - - //--Helpers end--------------------------------- - - "EitherIdFOps#asRightF" should { - "return Right" in { - 42.asRightF[Option, String] mustBe Some(Right(42)) - } - } - - "EitherIdFOps#asLeftF" should { - "return Left" in { - 42.asLeftF[Option, String] mustBe Some(Left(42)) - } - } - - "EitherFObjectOps#condF" should { - - "return Right and check lazyness" in { - Either.condF(true, 42.some, boom) mustBe Some(Right(42)) - } - - "return Left and check lazyness" in { - Either.condF(false, boom, 43.some) mustBe Some(Left(43)) - } - } - - "EitherFOps#orElseF" should { - - "return self in case of empty second" in { - defaultRight.orElseF(None) mustBe defaultRight - } - - "return self in case of non-empty second" in { - defaultRight.orElseF(5.asRightS[String]) mustBe defaultRight - } - - "return arg in case of empty second" in { - defaultLeft.orElseF(None) mustBe None - } - - "return arg in case non-of empty second" in { - defaultLeft.orElseF(testRight) mustBe testRight - } - - "check lazyness" in { - defaultRight.orElseF(boomRight) mustBe defaultRight - } - } - - "EitherFOps#getOrElseF" should { - - "return self in case of empty second" in { - defaultRight.getOrElseF(None) mustBe Some(4) - } - - "return self in case of non-empty second" in { - defaultRight.getOrElseF(Some(3)) mustBe Some(4) - } - - "return arg" in { - defaultLeft.getOrElseF(Some(5)) mustBe Some(5) - } - - "check lazyness" in { - defaultRight.getOrElseF(boom) mustBe Some(4) - } - } - - "EitherFOps#catchAll" should { - - "return self" in { - defaultRight.catchAll(s => Some(s.length)) mustBe Some(4) - } - - "return arg" in { - defaultLeft.catchAll(i => Some(i.toString)) mustBe Some("4") - } - } - - "EitherFOps#absolve" should { - - "return self in case of Right" in { - implicit def raise[T]: Raise[Option, T] = optionRaise[T] - - defaultRight.absolve mustBe Some(4) - } - - "return None in case of Left" in { - implicit def raise[T]: Raise[Option, T] = optionRaise[T] - - defaultLeft.absolve mustBe None - } - } - - "EitherFOps#reRaise" should { - - "return self in case of Right" in { - implicit def raise[T]: Raise[Option, T] = optionRaise[T] - - defaultRight.reRaise mustBe Some(4) - } - - "return None in case of Left" in { - implicit def raise[T]: Raise[Option, T] = optionRaise[T] - - defaultLeft.reRaise mustBe None - } - } - - "EitherFOps#assocR" should { - - "return valid value in case of Right-Right" in { - defaultRight.map(_.asRight[Char]).assocR mustBe Some(Right(4)) - } - - "return valid value in case of Right-Left" in { - defaultLeft.map(_.asRight[Char]).assocR mustBe Some(Left(Right(4))) - } - - "return valid value in case of Left" in { - 4.asLeft[Either[Char, Char]].some.assocR mustBe Some(Left(Left(4))) - } - } - - "EitherFOps#assocL" should { - - "return valid value in case of Left-Right" in { - defaultRight.map(_.asLeft[Char]).assocL mustBe Some(Right(Left(4))) - } - - "return valid value in case of Left-Left" in { - defaultLeft.map(_.asLeft[Char]).assocL mustBe Some(Left(4)) - } - - "return valid value in case of Right" in { - 4.asRight[Either[Char, Char]].some.assocL mustBe Some(Right(Right(4))) - } - } - - "EitherFOps#mapF" should { - - "return valid value in case of Right" in { - defaultRight.mapF(i => Some(i + 1)) mustBe Some(Right(5)) - } - - "return valid value in case of Left" in { - defaultLeft.mapF(_.some) mustBe Some(Left(4)) - } - - "return valid value in case of base None" in { - none[Either[String, Int]].mapF(_.some) mustBe None - } - - "return valid valid in case map to None" in { - defaultRight.mapF(_ => None) mustBe None - } - } - - "EitherFOps#mapIn" should { - - "return valid value in case of Right" in { - defaultRight.mapIn(_ + 1) mustBe Some(Right(5)) - } - - "return valid value in case of Left" in { - defaultLeft.mapIn(_ + 1) mustBe Some(Left(4)) - } - - "return valid value in case of base None" in { - none[Either[String, Int]].mapIn(_ + 1) mustBe None - } - } - - "EitherFOps#leftMapF" should { - - "return valid value in case of Left" in { - defaultLeft.leftMapF(i => Some(i + 1)) mustBe Some(Left(5)) - } - - "return valid value in case of Right" in { - defaultRight.leftMapF(_.some) mustBe Some(Right(4)) - } - - "return valid value in case of base None" in { - none[Either[String, Int]].leftMapF(_.some) mustBe None - } - - "return valid value in case map to None" in { - defaultLeft.leftMapF(_ => None) mustBe None - } - } - - "EitherFOps#flatMapIn" should { - - "return Right in case of base Right and mapping" in { - defaultRight.flatMapIn(i => Right(i + 1)) mustBe Some(Right(5)) - } - - "return valid value in case of base Right and mapping to Left" in { - defaultRight.flatMapIn(i => Left(i.toString)) mustBe Some(Left("4")) - } - - "return valid value in case of base Left" in { - defaultLeft.flatMapIn(_.asRight) mustBe Some(Left(4)) - } - - "return valid value in case of base None" in { - none[Either[String, Int]].flatMapIn(_.asRight) mustBe None - } - } - - "EitherFOps#leftFlatMapIn" should { - - "return Left in case of base Left and mapping" in { - defaultLeft.leftFlatMapIn(i => Left(i + 1)) mustBe Some(Left(5)) - } - - "return valid value in case of base Left and mapping to Right" in { - defaultLeft.leftFlatMapIn(i => Right(i.toString)) mustBe Some(Right("4")) - } - - "return valid value in case of base Right" in { - defaultRight.leftFlatMapIn(_.asLeft) mustBe Some(Right(4)) - } - - "return valid value in case of base None" in { - none[Either[String, Int]].leftFlatMapIn(_.asRight) mustBe None - none[Either[String, Int]].leftFlatMapIn(_.asLeft) mustBe None - } - } - - "EitherFOps#leftFlatMapF" should { - - "return Left in case of base Left and mapping" in { - defaultLeft.leftFlatMapF(i => Some(Left(i + 1))) mustBe Some(Left(5)) - } - - "return valid value in case of base Left and mapping to Right" in { - defaultLeft.leftFlatMapF(i => Some(Right(i.toString))) mustBe Some(Right("4")) - } - - "return valid value in case of base Right" in { - defaultRight.leftFlatMapF(v => Some(v.asLeft)) mustBe Some(Right(4)) - defaultRight.leftFlatMapF(_ => None) mustBe Some(Right(4)) - } - - "return valid value in case of base None" in { - none[Either[String, Int]].leftFlatMapF(v => Some(v.asRight)) mustBe None - none[Either[String, Int]].leftFlatMapF(v => Some(v.asLeft)) mustBe None - none[Either[String, Int]].leftFlatMapF(_ => None) mustBe None - } - } - - "EitherFOps#swapF" should { - - "return Left" in { - defaultRight.swapF mustBe Some(Left(4)) - } - - "return Right" in { - defaultLeft.swapF mustBe Some(Right(4)) - } - - "return None" in { - none[Either[String, Int]].swapF mustBe None - } - } - - "EitherFOps#doubleFlatMap" should { - - "return None" in { - none[Either[String, Int]].doubleFlatMap(_ => None) mustBe None - defaultRight.doubleFlatMap(_ => None) mustBe None - } - - "return Right" in { - defaultRight.doubleFlatMap(i => Some(Right(i + 1))) mustBe Some(Right(5)) - } - - "return Left" in { - defaultRight.doubleFlatMap(i => Some(Left(i.toString))) mustBe Some(Left("4")) - defaultLeft.doubleFlatMap(i => Some(Left(i.length))) mustBe Some(Left(4)) - defaultLeft.doubleFlatMap(i => Some(Right(i.length))) mustBe Some(Left(4)) - defaultLeft.doubleFlatMap(_ => None) mustBe Some(Left(4)) - } - } - - "EitherFOps#ensure" should { - - "return None" in { - none[Either[String, Int]].ensure(_ => true, "no") mustBe None - } - - "return Left" in { - defaultLeft.ensure(_ => true, "no") mustBe Some(Left(4)) - defaultRight.ensure(_ > 5, "no") mustBe Some(Left("no")) - } - - "return Right" in { - defaultRight.ensure(_ == 4, "no") mustBe Some(Right(4)) - } - } - - "EitherFOps#ensureF" should { - - "return None" in { - none[Either[String, Int]].ensureF(_ => Some(true), Some("no")) mustBe None - defaultRight.ensureF(i => Some(i > 4), None) mustBe None - defaultRight.ensureF(_ => None, None) mustBe None - } - - "return Left" in { - defaultLeft.ensureF(_ => Some(true), Some("no")) mustBe Some(Left(4)) - defaultRight.ensureF(i => Some(i > 5), Some("no")) mustBe Some(Left("no")) - } - - "return Right" in { - defaultRight.ensureF(i => Some(i == 4), Some("no")) mustBe Some(Right(4)) - } - } - - "EitherFOps#traverseF" should { - - "return None" in { - none[Either[String, Int]].traverseF(_.some) mustBe None - } - - "return Some(None)" in { - defaultRight.traverseF(_ => None) mustBe Some(None) - } - - "return Right" in { - defaultRight.traverseF(i => (i + 1).some) mustBe Some(Some(Right(5))) - } - - "return Left" in { - defaultLeft.traverseF(i => (i + 1).some) mustBe Some(Some(Left(4))) - defaultLeft.traverseF(_ => None) mustBe Some(Some(Left(4))) - } - } - - "EitherFOps#traverseAll" should { - - "return List(None)" in { - none[Either[String, Int]].traverseAll(List(_)) mustBe List(None) - } - - "return Nil" in { - defaultRight.traverseAll(_ => Nil) mustBe Nil - } - - "return Right" in { - defaultRight.traverseAll(i => List(i + 1)) mustBe List(Some(Right(5))) - } - - "return Left" in { - defaultLeft.traverseAll(i => List(i + 5)) mustBe List(Some(Left(4))) - defaultLeft.traverseAll(_ => Nil) mustBe List(Some(Left(4))) - } - } - - "EitherFOps#leftTraverseF" should { - - "return None" in { - none[Either[String, Int]].leftTraverseF(_.some) mustBe None - } - - "return Some(None)" in { - defaultLeft.leftTraverseF(_ => None) mustBe Some(None) - } - - "return Right" in { - defaultRight.leftTraverseF(i => (i + 1).some) mustBe Some(Some(Right(4))) - } - - "return Left" in { - defaultLeft.leftTraverseF(i => (i + 1).some) mustBe Some(Some(Left(5))) - defaultLeft.leftTraverseF(_ => None) mustBe Some(None) - } - } - - "EitherFOps#leftTraverseAll" should { - - "return List(None)" in { - none[Either[String, Int]].leftTraverseAll(List(_)) mustBe List(None) - } - - "return Nil" in { - defaultLeft.leftTraverseAll(_ => Nil) mustBe Nil - - } - - "return Right" in { - defaultRight.leftTraverseAll(_ => Nil) mustBe List(Some(Right(4))) - defaultRight.leftTraverseAll(i => List(i + 1)) mustBe List(Some(Right(4))) - } - - "return Left" in { - defaultLeft.leftTraverseAll(i => List(i + 1)) mustBe List(Some(Left(5))) - } - } - - "EitherFOps#productF" should { - "return None" in { - none[Either[String, Int]].productF(none[Either[String, Int]]) mustBe None - none[Either[String, Int]].productF(defaultRight) mustBe None - none[Either[String, Int]].productF(defaultLeft) mustBe None - defaultRight.productF(None) mustBe None - } - - "return Left" in { - defaultLeft.productF(None) mustBe Some(Left(4)) - defaultLeft.productF(defaultRight) mustBe Some(Left(4)) - defaultLeft.productF(defaultLeft.map(_.map(_ + 1))) mustBe Some(Left(4)) - defaultRight.productF(defaultLeft) mustBe Some(Left(4)) - } - - "return Right" in { - defaultRight.productF(defaultRight.map(_.map(_ + 1))) mustBe Some(Right((4, 5))) - } - - "check lazyness" in { - defaultLeft.productF(boomRight) mustBe Some(Left(4)) - } - } - - "EitherFOps#productRF" should { - "return None" in { - none[Either[String, Int]].productRF(none[Either[String, Int]]) mustBe None - none[Either[String, Int]].productRF(defaultRight) mustBe None - none[Either[String, Int]].productRF(defaultLeft) mustBe None - defaultRight.productRF(None) mustBe None - } - - "return Left" in { - defaultLeft.productF(None) mustBe Some(Left(4)) - defaultLeft.productRF(defaultRight) mustBe Some(Left(4)) - defaultLeft.productRF(defaultLeft.map(_.map(_ + 1))) mustBe Some(Left(4)) - defaultRight.productRF(defaultLeft) mustBe Some(Left(4)) - } - - "return Right" in { - defaultRight.productRF(defaultRight.map(_.map(_ + 1))) mustBe Some(Right(5)) - } - - "check lazyness" in { - defaultLeft.productRF(boomRight) mustBe Some(Left(4)) - } - } - - "EitherFOps#productLF" should { - "return None" in { - none[Either[String, Int]].productLF(none[Either[String, Int]]) mustBe None - none[Either[String, Int]].productLF(defaultRight) mustBe None - none[Either[String, Int]].productLF(defaultLeft) mustBe None - defaultRight.productLF(None) mustBe None - } - - "return Left" in { - defaultLeft.productF(None) mustBe Some(Left(4)) - defaultLeft.productLF(defaultRight) mustBe Some(Left(4)) - defaultLeft.productLF(defaultLeft.map(_.map(_ + 1))) mustBe Some(Left(4)) - defaultRight.productLF(defaultLeft) mustBe Some(Left(4)) - } - - "return Right" in { - defaultRight.productLF(defaultRight.map(_.map(_ + 1))) mustBe Some(Right(4)) - } - - "check lazyness" in { - defaultLeft.productLF(boomRight) mustBe Some(Left(4)) - } - } - - "EitherFOps#apF" should { - - def defaultRightFunc = defaultRight.map(_.map(i => (l: Int) => i + l)) - def defaultLeftFunc = defaultLeft.map(_.map(i => (l: Int) => i + l)) - def defaultLeftLFunc = defaultLeft.map(_.map(i => (l: String) => i + l.length)) - - "return None" in { - none[Either[String, Int => Int]].apF(none[Either[String, Int]]) mustBe None - none[Either[String, Int => Int]].apF(defaultRight) mustBe None - none[Either[String, String => Int]].apF(defaultLeft) mustBe None - defaultRightFunc.apF(None) mustBe None - } - - "return Left" in { - defaultLeftFunc.apF(None) mustBe Some(Left(4)) - defaultLeftFunc.apF(defaultRight) mustBe Some(Left(4)) - defaultLeftLFunc.apF(defaultLeft) mustBe Some(Left(4)) - defaultLeftLFunc.apF(defaultLeft) mustBe Some(Left(4)) - } - - "return Right" in { - defaultRightFunc.apF(defaultRight) mustBe Some(Right(8)) - } - - "check lazyness" in { - defaultLeftFunc.apF(boomRight) mustBe Some(Left(4)) - } - } - - "EitherFOps#map2F" should { - - "return None" in { - none[Either[String, Int]].map2F(none[Either[String, Int]])(_ + _) mustBe None - none[Either[String, Int]].map2F(defaultRight)(_ + _) mustBe None - none[Either[Int, String]].map2F(defaultLeft)(_ + _) mustBe None - defaultRight.map2F(none[Either[String, Int]])(_ + _) mustBe None - } - - "return Left" in { - defaultLeft.map2F(None)(_ + _) mustBe Some(Left(4)) - defaultLeft.map2F(defaultRight)(_ + _) mustBe Some(Left(4)) - } - - "return Right" in { - defaultRight.map2F(defaultRight)(_ + _) mustBe Some(Right(8)) - } - - "check lazyness" in { - defaultLeft.map2F(boomRight)(_ + _) mustBe Some(Left(4)) - } - } - - "EitherFOps#flatMap2F" should { - - val sumF: (Int, Int) => Some[Int] = (a, b) => Some(a + b) - - "return None" in { - none[Either[String, Int]].flatMap2F(none[Either[String, Int]])(sumF) mustBe None - none[Either[String, Int]].flatMap2F(defaultRight)(sumF) mustBe None - none[Either[Int, String]].flatMap2F(defaultLeft)((_, _) => Some("")) mustBe None - defaultRight.flatMap2F(none[Either[String, Int]])(sumF) mustBe None - } - - "return Left" in { - defaultLeft.flatMap2F(None)((_, _: Any) => Some("")) mustBe Some(Left(4)) - defaultLeft.flatMap2F(defaultRight)((_, _) => Some("")) mustBe Some(Left(4)) - } - - "return Right" in { - defaultRight.flatMap2F(defaultRight)(sumF) mustBe Some(Right(8)) - } - - "check lazyness" in { - defaultLeft.flatMap2F(boomRight)((_, _: Any) => Some("")) mustBe Some(Left(4)) - } - } - - "EitherFOps#mergeF" should { - "return None" in { - none[Either[Int, Int]].mergeF mustBe None - } - - "return Left" in { - defaultLeft.map(_.leftMap(_.toString)).mergeF mustBe Some("4") - } - - "return Right" in { - defaultRight.map(_.map(_.toString)).mergeF mustBe Some("4") - } - } - - "EitherIdFOps#rightIn" should { - "return None" in { - none[Int].rightIn[String] mustBe None - } - - "return Right" in { - 4.some.rightIn mustBe Some(Right(4)) - } - } - - "EitherIdFOps#leftIn" should { - "return None" in { - none[Int].leftIn mustBe None - } - - "return Left" in { - 4.some.leftIn mustBe Some(Left(4)) - } - } - -} diff --git a/modules/core3/src/test/scala/tofu/syntax/FOptionSuite.scala b/modules/core3/src/test/scala/tofu/syntax/FOptionSuite.scala deleted file mode 100644 index 589e63805..000000000 --- a/modules/core3/src/test/scala/tofu/syntax/FOptionSuite.scala +++ /dev/null @@ -1,723 +0,0 @@ -package tofu.syntax - -import cats.instances.list._ -import cats.instances.either._ -import org.scalatest.flatspec.AnyFlatSpec -import tofu.syntax.foption._ -import tofu.syntax.feither._ -import tofu.syntax.FOptionSuite._ - -import cats.syntax.either.catsSyntaxEitherId -import cats.syntax.option.none - -class FOptionSuite extends AnyFlatSpec { - "getOrElseF" should "return inner value when non empty" in { - assert( - 42.someF[List].getOrElseF(List(1, 1, 1)) === List(42) - ) - } - - "getOrElseF" should "return argument when empty" in { - assert( - noneF[List, Int].getOrElseF(List(1, 1, 1)) === List(1, 1, 1) - ) - } - - "orElseF" should "return self when non empty" in { - assert( - 42.someF[List].orElseF(List[Option[Int]](Some(1), Some(1), Some(1))) === List(Some(42)) - ) - } - - "orElseF" should "return argument when empty" in { - assert( - noneF[List, Int].orElseF(List[Option[Int]](Some(1), Some(1), Some(1))) === List(Some(1), Some(1), Some(1)) - ) - } - - "orThrow" should "return inner value when non empty" in { - assert( - 42.someF[Either[String, *]].orThrow("empty") === Right(42) - ) - } - - "orThrow" should "raise error when empty" in { - assert( - noneF[Either[String, *], Int].orThrow("empty") === Left("empty") - ) - } - - "semiflatMap" should "run when non empty" in { - assert( - 42.someF[List].semiflatMap(x => List(x + 1)) === List(Some(43)) - ) - } - - "semiflatMap" should "keep empty when empty" in { - assert( - noneF[List, Int].semiflatMap(x => List(x + 1)) === List(None) - ) - } - - "mapIn" should "run when non empty" in { - assert( - 42.someF[List].mapIn(_ + 1) === List(Some(43)) - ) - } - - "mapIn" should "keep empty when empty" in { - assert( - noneF[List, Int].mapIn(_ + 1) === List(None) - ) - } - - "flatMapIn" should "run when non empty" in { - assert( - 42.someF[List].flatMapIn(v => Some(v + 1)) === List(Some(43)) - ) - } - - "flatMapIn" should "keep empty when empty" in { - assert( - noneF[List, Int].flatMapIn(v => Some(v + 1)) === List(None) - ) - assert( - List.empty[Option[Int]].flatMapIn(v => Some(v + 1)) === Nil - ) - } - - "flatMapIn" should "return empty when empty is returned from function" in { - assert( - 42.someF[List].flatMapIn(_ => None) === List(None) - ) - } - - "doubleFlatMap" should "run when non empty" in { - assert( - 42.someF[List].flatMapF(x => List(Some(x + 1))) === List(Some(43)) - ) - } - - "doubleFlatMap" should "keep empty when empty" in { - assert( - noneF[List, Int].flatMapF(x => List(Some(x + 1))) === List(None) - ) - } - - "toRightF" should "return non-empty Left" in { - assert( - noneF[List, Int].toRightF(List("test")) === List(Left("test")) - ) - } - - "toRightF" should "return Right" in { - assert( - 42.someF[List].toRightF(List("test")) === List(Right(42)) - ) - } - - "toRightF" should "return empty M when empty M" in { - assert( - List.empty[Option[Int]].toRightF(List("test")) === Nil - ) - } - - "toRightF" should "return empty Left when None" in { - assert( - noneF[List, Int].toRightF(List.empty[String]) === Nil - ) - } - - "toRightF" should "check lazyness" in { - assert( - List.empty[Option[Int]].toRightF(boom) === Nil - ) - assert( - 42.someF[List].toRightF(boom) === List(Right(42)) - ) - } - - "toRightIn" should "return non-empty Left" in { - assert( - noneF[List, Int].toRightIn("test") === List(Left("test")) - ) - } - - "toRightIn" should "return Right" in { - assert( - 42.someF[List].toRightIn("test") === List(Right(42)) - ) - } - - "toRightIn" should "return empty M when empty M" in { - assert( - List.empty[Option[Int]].toRightIn("test") === Nil - ) - } - - "toRightIn" should "check lazyness" in { - assert( - List.empty[Option[Int]].toRightIn(boom) === Nil - ) - assert( - 42.someF[List].toRightIn(boom) === List(Right(42)) - ) - } - - "toLeftF" should "return non-empty Right" in { - assert( - noneF[List, Int].toLeftF(List("test")) === List(Right("test")) - ) - } - - "toLeftF" should "return Left" in { - assert( - 42.someF[List].toLeftF(List("test")) === List(Left(42)) - ) - } - - "toLeftF" should "return Left when empty M" in { - assert( - List.empty[Option[Int]].toLeftF(List("test")) === Nil - ) - } - - "toLeftF" should "return Right when None" in { - assert( - noneF[List, Int].toLeftF(List("test")) === List(Right("test")) - ) - } - - "toLeftF" should "return empty Right when None and function return empty M" in { - assert( - noneF[List, Int].toLeftF(List.empty[String]) === Nil - ) - } - - "toLeftF" should "check lazyness" in { - assert( - List.empty[Option[Int]].toLeftF(boom) === Nil - ) - assert( - 42.someF[List].toLeftF(boom) === List(Left(42)) - ) - } - - "toLeftIn" should "return Left" in { - assert( - 42.someF[List].toLeftIn("test") === List(Left(42)) - ) - } - - "toLeftIn" should "return Left when empty M" in { - assert( - List.empty[Option[Int]].toLeftIn(List("test")) === Nil - ) - } - - "toLeftIn" should "return Right when None" in { - assert( - noneF[List, Int].toLeftIn("test") === List(Right("test")) - ) - } - - "toLeftIn" should "check lazyness" in { - assert( - List.empty[Option[Int]].toLeftIn(boom) === Nil - ) - assert( - 42.someF[List].toLeftIn(boom) === List(Left(42)) - ) - } - - "filterIn" should "return empty M" in { - assert( - List.empty[Option[Int]].filterIn(_ => true) === Nil - ) - } - - "filterIn" should "return None if None" in { - assert( - noneF[List, Int].filterIn(_ => true) === noneF[List, Int] - ) - } - - "filterIn" should "return valid value due the predicate" in { - assert( - 42.someF[List].filterIn(_ == 42) === 42.someF[List] - ) - assert( - 42.someF[List].filterIn(_ < 42) === noneF[List, Int] - ) - } - - "filterF" should "return empty M" in { - assert( - List.empty[Option[Int]].filterF(_ => List(true)) === Nil - ) - assert( - List.empty[Option[Int]].filterF(_ => Nil) === Nil - ) - } - - "filterF" should "return None if None" in { - assert( - noneF[List, Int].filterF(_ => List(true)) === noneF[List, Int] - ) - assert( - noneF[List, Int].filterF(_ => Nil) === noneF[List, Int] - ) - } - - "filterF" should "return valid value due the predicate" in { - assert( - 42.someF[List].filterF(i => List(i == 42)) === 42.someF[List] - ) - assert( - 42.someF[List].filterF(i => List(i < 42)) === noneF[List, Int] - ) - assert( - 42.someF[List].filterF(_ => Nil) === Nil - ) - } - - "ensure" should "return err if None" in { - assert( - noneF[List, Int].ensure(_ => true, "err") === "err".asLeftF[List, Int] - ) - } - - "ensure" should "return empty M" in { - assert( - List.empty[Option[Int]].ensure(_ => true, "err") === Nil - ) - } - - "ensure" should "check lazyness" in { - assert( - List.empty[Option[Int]].ensure[String](_ => true, sys.error("boom")) === Nil - ) - } - - "ensure" should "return valid value due the predicate" in { - assert( - 42.someF[List].ensure(_ == 42, "err") === 42.asRightF[List, String] - ) - assert( - 42.someF[List].ensure(_ < 42, "err") === "err".asLeftF[List, Int] - ) - } - - "ensureF" should "return err if None" in { - assert( - noneF[List, Int].ensureF(_ => List(true), List("err")) === "err".asLeftF[List, Int] - ) - } - - "ensureF" should "return empty M" in { - assert( - List.empty[Option[Int]].ensureF(_ => List(true), List("err")) === Nil - ) - assert( - 42.someF[List].ensureF(_ => Nil, List.empty[String]) === Nil - ) - } - - "ensureF" should "check lazyness" in { - assert( - List.empty[Option[Int]].ensureF[String](_ => List(true), sys.error("boom") :: Nil) === Nil - ) - } - - "ensureF" should "return valid value due the predicate" in { - assert( - 42.someF[List].ensureF(i => List(i == 42), List("err")) === 42.asRightF[List, String] - ) - assert( - 42.someF[List].ensureF(i => List(i < 42), List("err")) === "err".asLeftF[List, Int] - ) - } - - "collectF" should "return successful collected" in { - assert( - 42.someF[List].collectF { case v => List(v + 1) } === List(Some(43)) - ) - } - - "collectF" should "return empty collected when empty M" in { - assert( - 42.someF[List].collectF { case _ => List.empty[Int] } === Nil - ) - } - - "collectF" should "return None collected when matching is failed" in { - assert( - 42.someF[List].collectF { case 1 => List(1) } === List(none[Int]) - ) - } - - "collectF" should "return None collected when base is None" in { - assert( - noneF[List, Int].collectF { case 1 => List(1) } === List(none[Int]) - ) - } - - "collectIn" should "return successful collected" in { - assert( - 42.someF[List].collectIn { case v => v + 1 } === List(Some(43)) - ) - } - - "collectIn" should "return None collected when matching is failed" in { - assert( - 42.someF[List].collectIn { case 1 => 1 } === List(none[Int]) - ) - } - - "collectIn" should "return None collected when base is None" in { - assert( - noneF[List, Int].collectIn { case 1 => 1 } === List(none[Int]) - ) - } - - "traverseF" should "return Left" in { - assert( - 42.someF[List].traverseF(_ => "err".asLeft[Int]) === List(Left("err")) - ) - } - - "traverseF" should "return Right" in { - assert( - 42.someF[List].traverseF(_.asRight[String]) === List(Right(Some(42))) - ) - } - - "traverseF" should "return empty M" in { - assert( - List.empty[Option[Int]].traverseF(_.asRight[String]) === Nil - ) - assert( - List.empty[Option[Int]].traverseF(_.asLeft[String]) === Nil - ) - } - - "traverseF" should "return err" in { - assert( - noneF[List, Int].traverseF(_.asLeft[String]) === List(Right(none[Int])) - ) - } - - "traverseAll" should "return Left" in { - assert( - 42.someF[List].traverseAll(_ => "err".asLeft[Int]) === Left("err") - ) - } - - "traverseAll" should "return Right" in { - assert( - 42.someF[List].traverseAll(_.asRight[String]) === Right(List(Some(42))) - ) - } - - "traverseAll" should "return empty M" in { - assert( - List.empty[Option[Int]].traverseAll(_.asRight[String]) === Right(Nil) - ) - assert( - List.empty[Option[Int]].traverseAll(_.asLeft[String]) === Right(Nil) - ) - } - - "traverseAll" should "return err" in { - assert( - noneF[List, Int].traverseAll(_.asLeft[String]) === Right(List(none[Int])) - ) - } - - "productF" should "return None" in { - assert( - 42.someF[List].productF(noneF[List, String]) === noneF[List, (Int, String)] - ) - assert( - noneF[List, Int].productF("err".someF[List]) === noneF[List, (Int, String)] - ) - assert( - noneF[List, Int].productF(noneF[List, String]) === noneF[List, (Int, String)] - ) - } - - "productF" should "return Some" in { - assert( - 42.someF[List].productF("test".someF[List]) === (42, "test").someF[List] - ) - } - - "productF" should "return empty M" in { - assert( - List.empty[Option[Int]].productF("test".someF[List]) === Nil - ) - assert( - List.empty[Option[Int]].productF(noneF[List, String]) === Nil - ) - assert( - 42.someF[List].productF(List.empty[Option[String]]) === Nil - ) - } - - "productF" should "return M with None" in { - assert( - noneF[List, Int].productF(List.empty[Option[String]]) === List(None) - ) - } - - "productF" should "check lazyness" in { - assert( - noneF[List, Int].productF(boom[String]) === List(None) - ) - assert( - List.empty[Option[Int]].productF(boom[String]) === Nil - ) - } - - "productRF" should "return None" in { - assert( - 42.someF[List].productRF(noneF[List, String]) === noneF[List, String] - ) - assert( - noneF[List, Int].productRF("err".someF[List]) === noneF[List, String] - ) - assert( - noneF[List, Int].productRF(noneF[List, String]) === noneF[List, String] - ) - } - - "productRF" should "return Some" in { - assert( - 42.someF[List].productRF("test".someF[List]) === "test".someF[List] - ) - } - - "productRF" should "return empty M" in { - assert( - List.empty[Option[Int]].productRF("test".someF[List]) === Nil - ) - assert( - List.empty[Option[Int]].productRF(noneF[List, String]) === Nil - ) - assert( - 42.someF[List].productRF(List.empty[Option[String]]) === Nil - ) - } - - "productRF" should "return M with None" in { - assert( - noneF[List, Int].productRF(List.empty[Option[String]]) === List(None) - ) - } - - "productRF" should "check lazyness" in { - assert( - noneF[List, Int].productRF(boom[String]) === List(None) - ) - assert( - List.empty[Option[Int]].productRF(boom[String]) === Nil - ) - } - - "productLF" should "return None" in { - assert( - 42.someF[List].productLF(noneF[List, String]) === noneF[List, Int] - ) - assert( - noneF[List, Int].productLF("err".someF[List]) === noneF[List, Int] - ) - assert( - noneF[List, Int].productLF(noneF[List, String]) === noneF[List, Int] - ) - } - - "productLF" should "return Some" in { - assert( - 42.someF[List].productLF("test".someF[List]) === 42.someF[List] - ) - } - - "productLF" should "return empty M" in { - assert( - List.empty[Option[Int]].productLF("test".someF[List]) === Nil - ) - assert( - List.empty[Option[Int]].productLF(noneF[List, String]) === Nil - ) - assert( - 42.someF[List].productLF(List.empty[Option[String]]) === Nil - ) - } - - "productLF" should "return M with None" in { - assert( - noneF[List, Int].productLF(List.empty[Option[String]]) === List(None) - ) - } - - "productLF" should "check lazyness" in { - assert( - noneF[List, Int].productLF(boom[String]) === List(None) - ) - assert( - List.empty[Option[Int]].productLF(boom[String]) === Nil - ) - } - - "apF" should "return None" in { - assert( - ((_: Int) + 42).someF[List].apF(noneF[List, Int]) === noneF[List, Int] - ) - assert( - noneF[List, Int => Int].apF(42.someF[List]) === noneF[List, Int] - ) - assert( - noneF[List, Int => Int].apF(noneF[List, Int]) === noneF[List, Int] - ) - } - - "apF" should "return Some" in { - assert( - ((_: Int) + 42).someF[List].apF(1.someF[List]) === 43.someF[List] - ) - } - - "apF" should "return empty M" in { - assert( - List.empty[Option[Int => Int]].apF(0.someF[List]) === Nil - ) - assert( - List.empty[Option[Int => Int]].apF(noneF[List, Int]) === Nil - ) - assert( - ((_: Int) + 42).someF[List].apF(List.empty[Option[Int]]) === Nil - ) - } - - "apF" should "return M with None" in { - assert( - noneF[List, Int => Int].apF(List.empty[Option[Int]]) === List(None) - ) - } - - "apF" should "check lazyness" in { - assert( - noneF[List, Int => Int].apF(boom[Int]) === List(None) - ) - assert( - List.empty[Option[Int => Int]].apF(boom[Int]) === Nil - ) - } - - "map2F" should "return None" in { - assert( - 42.someF[List].map2F(noneF[List, Int])(_ + _) === noneF[List, Int] - ) - assert( - noneF[List, Int].map2F(42.someF[List])(_ + _) === noneF[List, Int] - ) - assert( - noneF[List, Int].map2F(noneF[List, Int])(_ + _) === noneF[List, Int] - ) - } - - "map2F" should "return Some" in { - assert( - 42.someF[List].map2F(1.someF[List])(_ + _) === 43.someF[List] - ) - } - - "map2F" should "return empty M" in { - assert( - List.empty[Option[Int]].map2F(0.someF[List])(_ + _) === Nil - ) - assert( - List.empty[Option[Int]].map2F(noneF[List, Int])(_ + _) === Nil - ) - assert( - 42.someF[List].map2F(List.empty[Option[Int]])(_ + _) === Nil - ) - } - - "map2F" should "return M with None" in { - assert( - noneF[List, Int].map2F(List.empty[Option[Int]])(_ + _) === List(None) - ) - } - - "map2F" should "check lazyness" in { - assert( - noneF[List, Int].map2F(boom[Int])(_ + _) === List(None) - ) - assert( - List.empty[Option[Int]].map2F(boom[Int])(_ + _) === Nil - ) - } - - "flatMap2F" should "return None" in { - assert( - 42.someF[List].flatMap2F(noneF[List, Int])((a, b) => List(a + b)) === noneF[List, Int] - ) - assert( - noneF[List, Int].flatMap2F(42.someF[List])((a, b) => List(a + b)) === noneF[List, Int] - ) - assert( - noneF[List, Int].flatMap2F(noneF[List, Int])((a, b) => List(a + b)) === noneF[List, Int] - ) - } - - "flatMap2F" should "return Some" in { - assert( - 42.someF[List].flatMap2F(1.someF[List])((a, b) => List(a + b)) === 43.someF[List] - ) - } - - "flatMap2F" should "return empty M" in { - assert( - List.empty[Option[Int]].flatMap2F(0.someF[List])((a, b) => List(a + b)) === Nil - ) - assert( - List.empty[Option[Int]].flatMap2F(noneF[List, Int])((a, b) => List(a + b)) === Nil - ) - assert( - 42.someF[List].flatMap2F(List.empty[Option[Int]])((a, b) => List(a + b)) === Nil - ) - assert( - List.empty[Option[Int]].flatMap2F(0.someF[List])((_, _) => Nil) === Nil - ) - assert( - List.empty[Option[Int]].flatMap2F(noneF[List, Int])((_, _) => Nil) === Nil - ) - assert( - 42.someF[List].flatMap2F(List.empty[Option[Int]])((_, _) => Nil) === Nil - ) - } - - "flatMap2F" should "return M with None" in { - assert( - noneF[List, Int].flatMap2F(List.empty[Option[Int]])((a, b) => List(a + b)) === List(None) - ) - } - - "flatMap2F" should "check lazyness" in { - assert( - noneF[List, Int].flatMap2F(boom[Int])((_, _) => Nil) === List(None) - ) - assert( - List.empty[Option[Int]].flatMap2F(boom[Int])((_, _) => Nil) === Nil - ) - } - - "someIn" should "return some in M (List)" in { - assert(List(42).someIn === List(Some(42))) - } -} - -object FOptionSuite { - def boom[B]: List[Option[B]] = sys.error("boom") :: Nil -} diff --git a/modules/core3/src/test/scala/tofu/syntax/FindRaiseSuite.scala b/modules/core3/src/test/scala/tofu/syntax/FindRaiseSuite.scala deleted file mode 100644 index 778ff783e..000000000 --- a/modules/core3/src/test/scala/tofu/syntax/FindRaiseSuite.scala +++ /dev/null @@ -1,38 +0,0 @@ -package tofu.syntax - -import cats.Monad -import tofu.compat.unused -import tofu.{Raise, Timeout} -import tofu.syntax.foption._ -import tofu.syntax.raise._ -import tofu.syntax.feither._ -import tofu.syntax.timeout._ - -import scala.concurrent.duration.DurationInt -import scala.language.postfixOps - -@unused -object FindRaiseSuite { - trait CommonError - trait AnotherCommonError - - case object ConcreteError extends CommonError - - def fOptionFindRaise[F[_]: Monad: Raise[*[_], CommonError]: Raise[*[_], AnotherCommonError]]: F[Unit] = { - Monad[F].pure(Option.empty[Unit]).orThrow(ConcreteError) - } - - def verifiedFindRaise[F[_]: Monad: Raise[*[_], CommonError]: Raise[*[_], AnotherCommonError]]: F[Unit] = { - Monad[F].unit.verified(_ => true)(ConcreteError) - } - - def fEitherFindRaise[F[_]: Monad: Raise[*[_], CommonError]: Raise[*[_], AnotherCommonError]]: F[Unit] = { - val x = ConcreteError.asLeftF[F, Unit] - x.reRaise - x.absolve - } - - def timeoutFindRaise[F[_]: Monad: Raise[*[_], CommonError]: Raise[*[_], AnotherCommonError]: Timeout]: F[Unit] = { - Monad[F].unit.timeoutRaise(5 seconds, ConcreteError) - } -} diff --git a/modules/core/src/test/scala/examples/DoMonadExamples.scala b/modules/kernel/src/test/scala/examples/DoMonadExamples.scala similarity index 100% rename from modules/core/src/test/scala/examples/DoMonadExamples.scala rename to modules/kernel/src/test/scala/examples/DoMonadExamples.scala diff --git a/modules/core/src/test/scala/tofu/examples/TofuRaiseExamples.scala b/modules/kernel/src/test/scala/examples/TofuRaiseExamples.scala similarity index 99% rename from modules/core/src/test/scala/tofu/examples/TofuRaiseExamples.scala rename to modules/kernel/src/test/scala/examples/TofuRaiseExamples.scala index cfd571795..a51f31f58 100644 --- a/modules/core/src/test/scala/tofu/examples/TofuRaiseExamples.scala +++ b/modules/kernel/src/test/scala/examples/TofuRaiseExamples.scala @@ -1,4 +1,4 @@ -package tofu.examples +package examples import cats.FlatMap import cats.syntax.flatMap._ diff --git a/modules/core/src/test/scala/tofu/ErrorsCompanion.scala b/modules/kernel/src/test/scala/tofu/ErrorsCompanion.scala similarity index 100% rename from modules/core/src/test/scala/tofu/ErrorsCompanion.scala rename to modules/kernel/src/test/scala/tofu/ErrorsCompanion.scala diff --git a/modules/core/src/test/scala/tofu/ErrorsSuite.scala b/modules/kernel/src/test/scala/tofu/ErrorsSuite.scala similarity index 100% rename from modules/core/src/test/scala/tofu/ErrorsSuite.scala rename to modules/kernel/src/test/scala/tofu/ErrorsSuite.scala diff --git a/modules/core3/src/test/scala/tofu/RaiseSuite.scala b/modules/kernel/src/test/scala/tofu/RaiseSuite.scala similarity index 95% rename from modules/core3/src/test/scala/tofu/RaiseSuite.scala rename to modules/kernel/src/test/scala/tofu/RaiseSuite.scala index c71914d9d..8b9bf5150 100644 --- a/modules/core3/src/test/scala/tofu/RaiseSuite.scala +++ b/modules/kernel/src/test/scala/tofu/RaiseSuite.scala @@ -1,11 +1,11 @@ package tofu -import cats.MonadError -import Raise.ContravariantRaise -import tofu.syntax.raise._ -import cats.Applicative +import cats.{Applicative, MonadError} import org.scalatest.funsuite.AnyFunSuite +import tofu.Raise.ContravariantRaise import tofu.compat.unused +import tofu.kernel.types.{MonadThrow, Throws} +import tofu.syntax.raise._ class RaiseSuite extends AnyFunSuite { import tofu.RaiseSuite._ diff --git a/modules/core/src/test/scala/tofu/control/SelectiveSummon.scala b/modules/kernel/src/test/scala/tofu/control/SelectiveSummon.scala similarity index 57% rename from modules/core/src/test/scala/tofu/control/SelectiveSummon.scala rename to modules/kernel/src/test/scala/tofu/control/SelectiveSummon.scala index b78768fae..df63263cb 100644 --- a/modules/core/src/test/scala/tofu/control/SelectiveSummon.scala +++ b/modules/kernel/src/test/scala/tofu/control/SelectiveSummon.scala @@ -1,8 +1,7 @@ package tofu.control import cats.data.{Chain, WriterT} -import cats.effect.IO object SelectiveSummon { - Selective[WriterT[IO, Chain[Int], *]] + Selective[WriterT[Option, Chain[Int], *]] } diff --git a/modules/core/src/test/scala/tofu/syntax/FEitherSuite.scala b/modules/kernel/src/test/scala/tofu/syntax/FEitherSuite.scala similarity index 99% rename from modules/core/src/test/scala/tofu/syntax/FEitherSuite.scala rename to modules/kernel/src/test/scala/tofu/syntax/FEitherSuite.scala index ba4753bda..3069912c6 100644 --- a/modules/core/src/test/scala/tofu/syntax/FEitherSuite.scala +++ b/modules/kernel/src/test/scala/tofu/syntax/FEitherSuite.scala @@ -2,9 +2,8 @@ package tofu.syntax import cats.instances.list._ import cats.instances.option._ -import cats.syntax.option.catsSyntaxOptionId -import cats.syntax.option.none import cats.syntax.either._ +import cats.syntax.option.{catsSyntaxOptionId, none} import org.scalatest.matchers.must.Matchers import org.scalatest.wordspec.AnyWordSpec import tofu.Raise diff --git a/modules/core/src/test/scala/tofu/syntax/FOptionSuite.scala b/modules/kernel/src/test/scala/tofu/syntax/FOptionSuite.scala similarity index 99% rename from modules/core/src/test/scala/tofu/syntax/FOptionSuite.scala rename to modules/kernel/src/test/scala/tofu/syntax/FOptionSuite.scala index 589e63805..9bfb2d1a0 100644 --- a/modules/core/src/test/scala/tofu/syntax/FOptionSuite.scala +++ b/modules/kernel/src/test/scala/tofu/syntax/FOptionSuite.scala @@ -1,14 +1,13 @@ package tofu.syntax -import cats.instances.list._ import cats.instances.either._ -import org.scalatest.flatspec.AnyFlatSpec -import tofu.syntax.foption._ -import tofu.syntax.feither._ -import tofu.syntax.FOptionSuite._ - +import cats.instances.list._ import cats.syntax.either.catsSyntaxEitherId import cats.syntax.option.none +import org.scalatest.flatspec.AnyFlatSpec +import tofu.syntax.FOptionSuite._ +import tofu.syntax.feither._ +import tofu.syntax.foption._ class FOptionSuite extends AnyFlatSpec { "getOrElseF" should "return inner value when non empty" in { diff --git a/modules/core/src/test/scala/tofu/syntax/FindRaiseSuite.scala b/modules/kernel/src/test/scala/tofu/syntax/FindRaiseSuite.scala similarity index 96% rename from modules/core/src/test/scala/tofu/syntax/FindRaiseSuite.scala rename to modules/kernel/src/test/scala/tofu/syntax/FindRaiseSuite.scala index 778ff783e..c29f0b2f5 100644 --- a/modules/core/src/test/scala/tofu/syntax/FindRaiseSuite.scala +++ b/modules/kernel/src/test/scala/tofu/syntax/FindRaiseSuite.scala @@ -2,11 +2,12 @@ package tofu.syntax import cats.Monad import tofu.compat.unused -import tofu.{Raise, Timeout} +import tofu.Raise import tofu.syntax.foption._ import tofu.syntax.raise._ import tofu.syntax.feither._ import tofu.syntax.timeout._ +import tofu.time.Timeout import scala.concurrent.duration.DurationInt import scala.language.postfixOps diff --git a/modules/core/src/test/scala/tofu/ContextSuite.scala b/modules/kernelCE2Interop/src/test/scala/tofu/ContextSuite.scala similarity index 97% rename from modules/core/src/test/scala/tofu/ContextSuite.scala rename to modules/kernelCE2Interop/src/test/scala/tofu/ContextSuite.scala index 0dcdbf771..f772e701e 100644 --- a/modules/core/src/test/scala/tofu/ContextSuite.scala +++ b/modules/kernelCE2Interop/src/test/scala/tofu/ContextSuite.scala @@ -2,6 +2,7 @@ package tofu import cats.Applicative import cats.data.ReaderT +import tofu.kernel.types._ import tofu.optics.Contains object ContextSuite { diff --git a/modules/core/src/test/scala/tofu/DelaySuite.scala b/modules/kernelCE2Interop/src/test/scala/tofu/DelaySuite.scala similarity index 100% rename from modules/core/src/test/scala/tofu/DelaySuite.scala rename to modules/kernelCE2Interop/src/test/scala/tofu/DelaySuite.scala index 319acbb52..d84399f84 100644 --- a/modules/core/src/test/scala/tofu/DelaySuite.scala +++ b/modules/kernelCE2Interop/src/test/scala/tofu/DelaySuite.scala @@ -1,7 +1,7 @@ package tofu -import org.scalatest.funsuite.AnyFunSuite import cats.effect.IO +import org.scalatest.funsuite.AnyFunSuite class DelaySuite extends AnyFunSuite { test("IO pure delay") { diff --git a/modules/core/src/test/scala/tofu/GuaranteeSuite.scala b/modules/kernelCE2Interop/src/test/scala/tofu/GuaranteeSuite.scala similarity index 96% rename from modules/core/src/test/scala/tofu/GuaranteeSuite.scala rename to modules/kernelCE2Interop/src/test/scala/tofu/GuaranteeSuite.scala index fc9a9cfa5..135b39ec2 100644 --- a/modules/core/src/test/scala/tofu/GuaranteeSuite.scala +++ b/modules/kernelCE2Interop/src/test/scala/tofu/GuaranteeSuite.scala @@ -1,8 +1,10 @@ package tofu -import scala.annotation.nowarn -import tofu.interop.CE2Kernel.CEExit +import cats.effect.BracketThrow import tofu.internal.carriers.FinallyCarrier2 +import tofu.interop.CE2Kernel.CEExit + +import scala.annotation.nowarn object GuaranteeSuite { diff --git a/modules/kernelCE2Interop/src/test/scala/tofu/IOSummonChecks.scala b/modules/kernelCE2Interop/src/test/scala/tofu/IOSummonChecks.scala new file mode 100644 index 000000000..dae7e02f2 --- /dev/null +++ b/modules/kernelCE2Interop/src/test/scala/tofu/IOSummonChecks.scala @@ -0,0 +1,14 @@ +package tofu + +import cats.data.ReaderT +import cats.effect.{ContextShift, IO} + +class IOSummonChecks(implicit cs: ContextShift[IO]) { + implicitly[Fire[IO[*]]] + implicitly[Race[IO[*]]] + implicitly[Errors[IO, Throwable]] + + implicitly[Fire[ReaderT[IO, Unit, *]]] + implicitly[Race[ReaderT[IO, Unit, *]]] + implicitly[Errors[ReaderT[IO, Unit, *], Throwable]] +} diff --git a/modules/core/src/test/scala/tofu/ScopedSuite.scala b/modules/kernelCE2Interop/src/test/scala/tofu/ScopedSuite.scala similarity index 83% rename from modules/core/src/test/scala/tofu/ScopedSuite.scala rename to modules/kernelCE2Interop/src/test/scala/tofu/ScopedSuite.scala index ea3ca5c82..9b40c5bb0 100644 --- a/modules/core/src/test/scala/tofu/ScopedSuite.scala +++ b/modules/kernelCE2Interop/src/test/scala/tofu/ScopedSuite.scala @@ -1,13 +1,12 @@ package tofu -import cats.effect.ContextShift -import cats.effect.Async -import scala.concurrent.ExecutionContext -import cats.effect.Blocker -import tofu.syntax.scoped._ +import cats.effect.{Async, Blocker, ContextShift} +import tofu.kernel.types.CalcExec import tofu.syntax.monadic._ +import tofu.syntax.scopedKernel._ + import scala.annotation.nowarn -import scala.concurrent.Future +import scala.concurrent.{ExecutionContext, Future} class ScopedSuite { @nowarn("msg=parameter value") diff --git a/modules/core/src/test/scala/tofu/TimeoutChecks.scala b/modules/kernelCE2Interop/src/test/scala/tofu/TimeoutChecks.scala similarity index 91% rename from modules/core/src/test/scala/tofu/TimeoutChecks.scala rename to modules/kernelCE2Interop/src/test/scala/tofu/TimeoutChecks.scala index e190cc62b..3666c57c7 100644 --- a/modules/core/src/test/scala/tofu/TimeoutChecks.scala +++ b/modules/kernelCE2Interop/src/test/scala/tofu/TimeoutChecks.scala @@ -2,6 +2,7 @@ package tofu import cats.data.ReaderT import cats.effect.{ContextShift, IO, Timer} +import tofu.time.Timeout object TimeoutChecks { def checks(implicit cs: ContextShift[IO], t: Timer[IO]) = { diff --git a/modules/core/src/test/scala/tofu/common/ConsoleSuite.scala b/modules/kernelCE2Interop/src/test/scala/tofu/common/ConsoleSuite.scala similarity index 94% rename from modules/core/src/test/scala/tofu/common/ConsoleSuite.scala rename to modules/kernelCE2Interop/src/test/scala/tofu/common/ConsoleSuite.scala index 8be0b9bf0..9fbbc7f6c 100644 --- a/modules/core/src/test/scala/tofu/common/ConsoleSuite.scala +++ b/modules/kernelCE2Interop/src/test/scala/tofu/common/ConsoleSuite.scala @@ -1,12 +1,12 @@ package tofu.common -import java.io.ByteArrayInputStream -import java.io.ByteArrayOutputStream -import org.scalatest.funsuite.AnyFunSuite -import cats.effect.IO import cats.Monad +import cats.effect.IO +import org.scalatest.funsuite.AnyFunSuite import tofu.syntax.monadic._ +import java.io.{ByteArrayInputStream, ByteArrayOutputStream} + class ConsoleSuite extends AnyFunSuite { def check[A](inputs: String*)(a: => A): (A, Vector[String]) = { val input = new ByteArrayInputStream( diff --git a/modules/core/src/test/scala/tofu/concurrent/AtomSuite.scala b/modules/kernelCE2Interop/src/test/scala/tofu/concurrent/AtomSuite.scala similarity index 92% rename from modules/core/src/test/scala/tofu/concurrent/AtomSuite.scala rename to modules/kernelCE2Interop/src/test/scala/tofu/concurrent/AtomSuite.scala index 97ca389cb..39cd5f16d 100644 --- a/modules/core/src/test/scala/tofu/concurrent/AtomSuite.scala +++ b/modules/kernelCE2Interop/src/test/scala/tofu/concurrent/AtomSuite.scala @@ -1,13 +1,13 @@ package tofu.concurrent -import cats.effect.Sync -import cats.effect.IO +import cats.Monad import cats.data.ReaderT -import scala.annotation.nowarn +import cats.effect.{IO, Sync} import org.scalatest.funsuite.AnyFunSuite -import cats.Monad import tofu.syntax.monadic._ +import scala.annotation.nowarn + @nowarn class AtomSuite extends AnyFunSuite { def summonInstance[I[_]: Sync, F[_]: Sync] = { diff --git a/modules/core/src/test/scala/tofu/concurrent/QVarSuite.scala b/modules/kernelCE2Interop/src/test/scala/tofu/concurrent/QVarSuite.scala similarity index 90% rename from modules/core/src/test/scala/tofu/concurrent/QVarSuite.scala rename to modules/kernelCE2Interop/src/test/scala/tofu/concurrent/QVarSuite.scala index cce323115..2f3a1622d 100644 --- a/modules/core/src/test/scala/tofu/concurrent/QVarSuite.scala +++ b/modules/kernelCE2Interop/src/test/scala/tofu/concurrent/QVarSuite.scala @@ -1,14 +1,12 @@ package tofu.concurrent -import cats.effect.Sync -import cats.effect.IO +import cats.Monad import cats.data.ReaderT -import scala.annotation.nowarn - +import cats.effect.{Concurrent, IO, Sync} import org.scalatest.funsuite.AnyFunSuite -import cats.effect.Concurrent -import cats.Monad import tofu.syntax.monadic._ + +import scala.annotation.nowarn import scala.concurrent.ExecutionContext @nowarn diff --git a/modules/core/src/test/scala/tofu/lift/UnliftSubcontext.scala b/modules/kernelCE2Interop/src/test/scala/tofu/lift/UnliftSubcontext.scala similarity index 85% rename from modules/core/src/test/scala/tofu/lift/UnliftSubcontext.scala rename to modules/kernelCE2Interop/src/test/scala/tofu/lift/UnliftSubcontext.scala index 6ae842e98..2e1da0069 100644 --- a/modules/core/src/test/scala/tofu/lift/UnliftSubcontext.scala +++ b/modules/kernelCE2Interop/src/test/scala/tofu/lift/UnliftSubcontext.scala @@ -1,19 +1,18 @@ package tofu.lift +import cats.Monad import cats.data.ReaderT import cats.effect.IO import org.scalatest.flatspec.AnyFlatSpec -import tofu.lift.UnliftSubcontext.FatApp -import tofu.optics.Contains -import UnliftSubcontext._ -import cats.Monad import org.scalatest.matchers.should.Matchers -import tofu.HasContext +import tofu.WithContext import tofu.compat.unused +import tofu.lift.UnliftSubcontext._ +import tofu.optics.Contains class UnliftSubcontext extends AnyFlatSpec with Matchers { - def context[F[_]: HasContext[*[_], Big]]: F[Big] = HasContext[F, Big].context - def smallCtx[F[_]: HasContext[*[_], Small]]: F[Small] = HasContext[F, Small].context + def context[F[_]: WithContext[*[_], Big]]: F[Big] = WithContext[F, Big].context + def smallCtx[F[_]: WithContext[*[_], Small]]: F[Small] = WithContext[F, Small].context implicit val ul: Unlift[App, FatApp] = Unlift.subContextUnlift val init: Big = Big(0, Small(1)) diff --git a/modules/core/src/test/scala/tofu/lift/UnliftSuite.scala b/modules/kernelCE2Interop/src/test/scala/tofu/lift/UnliftSuite.scala similarity index 95% rename from modules/core/src/test/scala/tofu/lift/UnliftSuite.scala rename to modules/kernelCE2Interop/src/test/scala/tofu/lift/UnliftSuite.scala index fad8ed24a..b63172f01 100644 --- a/modules/core/src/test/scala/tofu/lift/UnliftSuite.scala +++ b/modules/kernelCE2Interop/src/test/scala/tofu/lift/UnliftSuite.scala @@ -1,12 +1,11 @@ package tofu.lift -import cats.Applicative +import cats.{Applicative, Monad} import cats.data.ReaderT import cats.effect.{Effect, IO} import cats.syntax.option._ import org.scalatest.flatspec.AnyFlatSpec import tofu.compat.unused -import cats.Monad class UnliftSuite extends AnyFlatSpec { "Lift implicit def implementations" should "cast instances properly" in { @@ -21,6 +20,8 @@ class UnliftSuite extends AnyFlatSpec { object UnliftSuite { + type UnliftIO[F[_]] = Unlift[IO, F] + def summonLiftInstances[F[_], R](): Unit = { implicitly[Lift[F, F]] implicitly[Lift[F, ReaderT[F, R, *]]] diff --git a/modules/core/src/test/scala/tofu/syntax/RetrySuite.scala b/modules/kernelCE2Interop/src/test/scala/tofu/syntax/RetrySuite.scala similarity index 94% rename from modules/core/src/test/scala/tofu/syntax/RetrySuite.scala rename to modules/kernelCE2Interop/src/test/scala/tofu/syntax/RetrySuite.scala index 5a4decd6b..3b6e30eb2 100644 --- a/modules/core/src/test/scala/tofu/syntax/RetrySuite.scala +++ b/modules/kernelCE2Interop/src/test/scala/tofu/syntax/RetrySuite.scala @@ -3,12 +3,13 @@ package tofu.syntax import cats.Applicative import cats.effect.IO import cats.effect.concurrent.Ref +import cats.syntax.all._ import org.scalatest.flatspec.AnyFlatSpec -import tofu.{ApplicativeThrow, Errors, Handle, Raise} +import tofu.kernel.types.ApplicativeThrow +import tofu.optics.Downcast import tofu.syntax.handle._ import tofu.syntax.raise._ -import cats.syntax.all._ -import tofu.optics.Downcast +import tofu.{Errors, Handle, Raise} class RetrySuite extends AnyFlatSpec { diff --git a/modules/core/src/test/scala/tofu/time/TimeSuite.scala b/modules/kernelCE2Interop/src/test/scala/tofu/time/TimeSuite.scala similarity index 100% rename from modules/core/src/test/scala/tofu/time/TimeSuite.scala rename to modules/kernelCE2Interop/src/test/scala/tofu/time/TimeSuite.scala diff --git a/modules/core3/src/test/scala/tofu/ContextSuite.scala b/modules/kernelCE3Interop/src/test/scala/tofu/ContextSuite.scala similarity index 97% rename from modules/core3/src/test/scala/tofu/ContextSuite.scala rename to modules/kernelCE3Interop/src/test/scala/tofu/ContextSuite.scala index 0dcdbf771..f772e701e 100644 --- a/modules/core3/src/test/scala/tofu/ContextSuite.scala +++ b/modules/kernelCE3Interop/src/test/scala/tofu/ContextSuite.scala @@ -2,6 +2,7 @@ package tofu import cats.Applicative import cats.data.ReaderT +import tofu.kernel.types._ import tofu.optics.Contains object ContextSuite { diff --git a/modules/core3/src/test/scala/tofu/DelaySuite.scala b/modules/kernelCE3Interop/src/test/scala/tofu/DelaySuite.scala similarity index 100% rename from modules/core3/src/test/scala/tofu/DelaySuite.scala rename to modules/kernelCE3Interop/src/test/scala/tofu/DelaySuite.scala index 5e133e113..a0d9ec859 100644 --- a/modules/core3/src/test/scala/tofu/DelaySuite.scala +++ b/modules/kernelCE3Interop/src/test/scala/tofu/DelaySuite.scala @@ -1,8 +1,8 @@ package tofu -import org.scalatest.funsuite.AnyFunSuite import cats.effect.IO import cats.effect.unsafe.IORuntime +import org.scalatest.funsuite.AnyFunSuite class DelaySuite extends AnyFunSuite { implicit val rt = IORuntime.global diff --git a/modules/core3/src/test/scala/tofu/GuaranteeSuite.scala b/modules/kernelCE3Interop/src/test/scala/tofu/GuaranteeSuite.scala similarity index 91% rename from modules/core3/src/test/scala/tofu/GuaranteeSuite.scala rename to modules/kernelCE3Interop/src/test/scala/tofu/GuaranteeSuite.scala index 8668bc327..542dc751b 100644 --- a/modules/core3/src/test/scala/tofu/GuaranteeSuite.scala +++ b/modules/kernelCE3Interop/src/test/scala/tofu/GuaranteeSuite.scala @@ -1,9 +1,9 @@ package tofu -import scala.annotation.nowarn -import cats.effect.kernel.MonadCancelThrow +import cats.effect.kernel.{MonadCancelThrow, Outcome} import tofu.internal.carriers.FinallyCarrier3 -import cats.effect.kernel.Outcome + +import scala.annotation.nowarn object GuaranteeSuite { diff --git a/modules/kernelCE3Interop/src/test/scala/tofu/IOSummonChecks.scala b/modules/kernelCE3Interop/src/test/scala/tofu/IOSummonChecks.scala new file mode 100644 index 000000000..78b1fc2ef --- /dev/null +++ b/modules/kernelCE3Interop/src/test/scala/tofu/IOSummonChecks.scala @@ -0,0 +1,14 @@ +package tofu + +import cats.data.ReaderT +import cats.effect.IO + +class IOSummonChecks { + implicitly[Fire[IO[*]]] + implicitly[Race[IO[*]]] + implicitly[Errors[IO, Throwable]] + + implicitly[Fire[ReaderT[IO, Unit, *]]] + implicitly[Race[ReaderT[IO, Unit, *]]] + implicitly[Errors[ReaderT[IO, Unit, *], Throwable]] +} diff --git a/modules/core3/src/test/scala/tofu/ScopedSuite.scala b/modules/kernelCE3Interop/src/test/scala/tofu/ScopedSuite.scala similarity index 88% rename from modules/core3/src/test/scala/tofu/ScopedSuite.scala rename to modules/kernelCE3Interop/src/test/scala/tofu/ScopedSuite.scala index 78f843760..75ad3ff29 100644 --- a/modules/core3/src/test/scala/tofu/ScopedSuite.scala +++ b/modules/kernelCE3Interop/src/test/scala/tofu/ScopedSuite.scala @@ -1,12 +1,13 @@ package tofu import cats.effect.Async -import scala.concurrent.ExecutionContext -import tofu.syntax.scoped._ +import tofu.interop.Blocker +import tofu.kernel.types.CalcExec import tofu.syntax.monadic._ +import tofu.syntax.scopedKernel._ + import scala.annotation.nowarn -import scala.concurrent.Future -import tofu.interop.Blocker +import scala.concurrent.{ExecutionContext, Future} class ScopedSuite { @nowarn("msg=parameter value") diff --git a/modules/core3/src/test/scala/tofu/TimeoutChecks.scala b/modules/kernelCE3Interop/src/test/scala/tofu/TimeoutChecks.scala similarity index 100% rename from modules/core3/src/test/scala/tofu/TimeoutChecks.scala rename to modules/kernelCE3Interop/src/test/scala/tofu/TimeoutChecks.scala diff --git a/modules/core3/src/test/scala/tofu/concurrent/AtomSuite.scala b/modules/kernelCE3Interop/src/test/scala/tofu/concurrent/AtomSuite.scala similarity index 100% rename from modules/core3/src/test/scala/tofu/concurrent/AtomSuite.scala rename to modules/kernelCE3Interop/src/test/scala/tofu/concurrent/AtomSuite.scala diff --git a/modules/core3/src/test/scala/tofu/concurrent/QVarSuite.scala b/modules/kernelCE3Interop/src/test/scala/tofu/concurrent/QVarSuite.scala similarity index 100% rename from modules/core3/src/test/scala/tofu/concurrent/QVarSuite.scala rename to modules/kernelCE3Interop/src/test/scala/tofu/concurrent/QVarSuite.scala diff --git a/modules/core3/src/test/scala/tofu/common/ConsoleSuite.scala b/modules/kernelCE3Interop/src/test/scala/tofu/console/ConsoleSuite.scala similarity index 92% rename from modules/core3/src/test/scala/tofu/common/ConsoleSuite.scala rename to modules/kernelCE3Interop/src/test/scala/tofu/console/ConsoleSuite.scala index 04037c1e3..9afb02808 100644 --- a/modules/core3/src/test/scala/tofu/common/ConsoleSuite.scala +++ b/modules/kernelCE3Interop/src/test/scala/tofu/console/ConsoleSuite.scala @@ -1,12 +1,13 @@ -package tofu.common +package tofu.console -import java.io.ByteArrayInputStream -import java.io.ByteArrayOutputStream -import org.scalatest.funsuite.AnyFunSuite -import cats.effect.IO import cats.Monad -import tofu.syntax.monadic._ +import cats.effect.IO import cats.effect.unsafe.IORuntime +import org.scalatest.funsuite.AnyFunSuite +import tofu.common.Console +import tofu.syntax.monadic._ + +import java.io.{ByteArrayInputStream, ByteArrayOutputStream} class ConsoleSuite extends AnyFunSuite { implicit val iort = IORuntime.global diff --git a/modules/core3/src/test/scala/tofu/lift/UnliftSubcontext.scala b/modules/kernelCE3Interop/src/test/scala/tofu/lift/UnliftSubcontext.scala similarity index 85% rename from modules/core3/src/test/scala/tofu/lift/UnliftSubcontext.scala rename to modules/kernelCE3Interop/src/test/scala/tofu/lift/UnliftSubcontext.scala index bf1e4eb08..86829b586 100644 --- a/modules/core3/src/test/scala/tofu/lift/UnliftSubcontext.scala +++ b/modules/kernelCE3Interop/src/test/scala/tofu/lift/UnliftSubcontext.scala @@ -1,22 +1,21 @@ package tofu.lift +import cats.Monad import cats.data.ReaderT import cats.effect.IO +import cats.effect.unsafe.IORuntime import org.scalatest.flatspec.AnyFlatSpec -import tofu.lift.UnliftSubcontext.FatApp -import tofu.optics.Contains -import UnliftSubcontext._ -import cats.Monad import org.scalatest.matchers.should.Matchers -import tofu.HasContext +import tofu.WithContext import tofu.compat.unused -import cats.effect.unsafe.IORuntime +import tofu.lift.UnliftSubcontext.{FatApp, _} +import tofu.optics.Contains class UnliftSubcontext extends AnyFlatSpec with Matchers { implicit val iort = IORuntime.global - def context[F[_]: HasContext[*[_], Big]]: F[Big] = HasContext[F, Big].context - def smallCtx[F[_]: HasContext[*[_], Small]]: F[Small] = HasContext[F, Small].context + def context[F[_]: WithContext[*[_], Big]]: F[Big] = WithContext[F, Big].context + def smallCtx[F[_]: WithContext[*[_], Small]]: F[Small] = WithContext[F, Small].context implicit val ul: Unlift[App, FatApp] = Unlift.subContextUnlift val init: Big = Big(0, Small(1)) diff --git a/modules/core3/src/test/scala/tofu/lift/UnliftSuite.scala b/modules/kernelCE3Interop/src/test/scala/tofu/lift/UnliftSuite.scala similarity index 94% rename from modules/core3/src/test/scala/tofu/lift/UnliftSuite.scala rename to modules/kernelCE3Interop/src/test/scala/tofu/lift/UnliftSuite.scala index 4709435b1..3b4b2c6bb 100644 --- a/modules/core3/src/test/scala/tofu/lift/UnliftSuite.scala +++ b/modules/kernelCE3Interop/src/test/scala/tofu/lift/UnliftSuite.scala @@ -1,16 +1,14 @@ package tofu.lift -import cats.Applicative +import cats.{Applicative, Monad} import cats.data.ReaderT -import cats.effect.{IO} +import cats.effect.{Async, IO} +import cats.effect.std.Dispatcher +import cats.effect.unsafe.IORuntime import cats.syntax.option._ import org.scalatest.flatspec.AnyFlatSpec -import tofu.compat.unused -import cats.Monad import tofu.WithContext -import cats.effect.std.Dispatcher -import cats.effect.Async -import cats.effect.unsafe.IORuntime +import tofu.compat.unused class UnliftSuite extends AnyFlatSpec { "Lift implicit def implementations" should "cast instances properly" in { @@ -25,6 +23,8 @@ class UnliftSuite extends AnyFlatSpec { object UnliftSuite { + type UnliftIO[F[_]] = Unlift[IO, F] + def summonLiftInstances[F[_], R](): Unit = { implicitly[Lift[F, F]] implicitly[Lift[F, ReaderT[F, R, *]]] diff --git a/modules/core3/src/test/scala/tofu/syntax/RetrySuite.scala b/modules/kernelCE3Interop/src/test/scala/tofu/syntax/RetrySuite.scala similarity index 95% rename from modules/core3/src/test/scala/tofu/syntax/RetrySuite.scala rename to modules/kernelCE3Interop/src/test/scala/tofu/syntax/RetrySuite.scala index dfc85d115..12c4bd688 100644 --- a/modules/core3/src/test/scala/tofu/syntax/RetrySuite.scala +++ b/modules/kernelCE3Interop/src/test/scala/tofu/syntax/RetrySuite.scala @@ -3,13 +3,14 @@ package tofu.syntax import cats.Applicative import cats.effect.IO import cats.effect.kernel.Ref +import cats.effect.unsafe.IORuntime +import cats.syntax.all._ import org.scalatest.flatspec.AnyFlatSpec -import tofu.{ApplicativeThrow, Errors, Handle, Raise} +import tofu.kernel.types.ApplicativeThrow +import tofu.optics.Downcast import tofu.syntax.handle._ import tofu.syntax.raise._ -import cats.syntax.all._ -import tofu.optics.Downcast -import cats.effect.unsafe.IORuntime +import tofu.{Errors, Handle, Raise} class RetrySuite extends AnyFlatSpec { implicit val iort = IORuntime.global diff --git a/modules/core3/src/test/scala/tofu/time/TimeSuite.scala b/modules/kernelCE3Interop/src/test/scala/tofu/time/TimeSuite.scala similarity index 100% rename from modules/core3/src/test/scala/tofu/time/TimeSuite.scala rename to modules/kernelCE3Interop/src/test/scala/tofu/time/TimeSuite.scala