diff --git a/kyo-core/shared/src/test/scala/kyoTest/KyoTest.scala b/kyo-core/shared/src/test/scala/kyoTest/KyoTest.scala index 0c3c0da55..b868e7356 100644 --- a/kyo-core/shared/src/test/scala/kyoTest/KyoTest.scala +++ b/kyo-core/shared/src/test/scala/kyoTest/KyoTest.scala @@ -79,26 +79,4 @@ class KyoTest extends AsyncFreeSpec with Assertions { IOs.run(App.runFiber(timeout)(v).toFuture).map(_.get) } - class Check[T, S](equals: Boolean) { - def apply[T2, S2](value: T2 > S2, expected: Any)(implicit - t: Tag[T], - s: Tag[S], - eq: Eq[T], - t2: Tag[T2], - s2: Tag[S2] - ): Assertion = { - assert(t.tag =:= t2.tag, "value tag doesn't match") - assert( - s2.tag =:= Tag[Any].tag || s.tag =:= Tag[Any].tag || s.tag =:= s2.tag, - "effects tag doesn't match" - ) - if (equals) - assert(eq(value.asInstanceOf[T], expected.asInstanceOf[T])) - else - assert(!eq(value.asInstanceOf[T], expected.asInstanceOf[T])) - } - } - - def checkEquals[T, S] = new Check[T, S](true) - def checkNotEquals[T, S] = new Check[T, S](false) } diff --git a/kyo-core/shared/src/test/scala/kyoTest/abortsTest.scala b/kyo-core/shared/src/test/scala/kyoTest/abortsTest.scala index 64b8e87b5..f2e6db44e 100644 --- a/kyo-core/shared/src/test/scala/kyoTest/abortsTest.scala +++ b/kyo-core/shared/src/test/scala/kyoTest/abortsTest.scala @@ -20,40 +20,40 @@ class abortsTest extends KyoTest { "pure" - { "handle" in { - checkEquals[Either[Ex1, Int], Any]( - Aborts[Ex1].run(Aborts[Ex1].get(Right(1))), - Right(1) + assert( + Aborts[Ex1].run(Aborts[Ex1].get(Right(1))) == + Right(1) ) } "handle + transform" in { - checkEquals[Either[Ex1, Int], Any]( - Aborts[Ex1].run(Aborts[Ex1].get(Right(1)).map(_ + 1)), - Right(2) + assert( + Aborts[Ex1].run(Aborts[Ex1].get(Right(1)).map(_ + 1)) == + Right(2) ) } "handle + effectful transform" in { - checkEquals[Either[Ex1, Int], Any]( + assert( Aborts[Ex1].run(Aborts[Ex1].get(Right(1)).map(i => Aborts[Ex1].get(Right(i + 1)) - )), - Right(2) + )) == + Right(2) ) } "handle + transform + effectful transform" in { - checkEquals[Either[Ex1, Int], Any]( + assert( Aborts[Ex1].run(Aborts[Ex1].get(Right(1)).map(_ + 1).map(i => Aborts[Ex1].get(Right(i + 1)) - )), - Right(3) + )) == + Right(3) ) } "handle + transform + failed effectful transform" in { val fail = Left[Ex1, Int](ex1) - checkEquals[Either[Ex1, Int], Any]( + assert( Aborts[Ex1].run(Aborts[Ex1].get(Right(1)).map(_ + 1).map(_ => Aborts[Ex1].get(fail) - )), - fail + )) == + fail ) } } @@ -62,68 +62,68 @@ class abortsTest extends KyoTest { "success" - { val v = Aborts[Ex1].get(Right(1)) "handle" in { - checkEquals[Either[Ex1, Int], Any]( - Aborts[Ex1].run(v), - Right(1) + assert( + Aborts[Ex1].run(v) == + Right(1) ) } "handle + transform" in { - checkEquals[Either[Ex1, Int], Any]( - Aborts[Ex1].run(v.map(_ + 1)), - Right(2) + assert( + Aborts[Ex1].run(v.map(_ + 1)) == + Right(2) ) } "handle + effectful transform" in { - checkEquals[Either[Ex1, Int], Any]( - Aborts[Ex1].run(v.map(i => Aborts[Ex1].get(Right(i + 1)))), - Right(2) + assert( + Aborts[Ex1].run(v.map(i => Aborts[Ex1].get(Right(i + 1)))) == + Right(2) ) } "handle + transform + effectful transform" in { - checkEquals[Either[Ex1, Int], Any]( - Aborts[Ex1].run(v.map(_ + 1).map(i => Aborts[Ex1].get(Right(i + 1)))), - Right(3) + assert( + Aborts[Ex1].run(v.map(_ + 1).map(i => Aborts[Ex1].get(Right(i + 1)))) == + Right(3) ) } "handle + transform + failed effectful transform" in { val fail = Left[Ex1, Int](ex1) - checkEquals[Either[Ex1, Int], Any]( - Aborts[Ex1].run(v.map(_ + 1).map(_ => Aborts[Ex1].get(fail))), - fail + assert( + Aborts[Ex1].run(v.map(_ + 1).map(_ => Aborts[Ex1].get(fail))) == + fail ) } } "failure" - { val v: Int > Aborts[Ex1] = Aborts[Ex1].get(Left(ex1)) "handle" in { - checkEquals[Either[Ex1, Int], Any]( - Aborts[Ex1].run(v), - Left(ex1) + assert( + Aborts[Ex1].run(v) == + Left(ex1) ) } "handle + transform" in { - checkEquals[Either[Ex1, Int], Any]( - Aborts[Ex1].run(v.map(_ + 1)), - Left(ex1) + assert( + Aborts[Ex1].run(v.map(_ + 1)) == + Left(ex1) ) } "handle + effectful transform" in { - checkEquals[Either[Ex1, Int], Any]( - Aborts[Ex1].run(v.map(i => Aborts[Ex1].get(Right(i + 1)))), - Left(ex1) + assert( + Aborts[Ex1].run(v.map(i => Aborts[Ex1].get(Right(i + 1)))) == + Left(ex1) ) } "handle + transform + effectful transform" in { - checkEquals[Either[Ex1, Int], Any]( - Aborts[Ex1].run(v.map(_ + 1).map(i => Aborts[Ex1].get(Right(i + 1)))), - Left(ex1) + assert( + Aborts[Ex1].run(v.map(_ + 1).map(i => Aborts[Ex1].get(Right(i + 1)))) == + Left(ex1) ) } "handle + transform + failed effectful transform" in { val fail = Left[Ex1, Int](ex1) - checkEquals[Either[Ex1, Int], Any]( - Aborts[Ex1].run(v.map(_ + 1).map(_ => Aborts[Ex1].get(fail))), - fail + assert( + Aborts[Ex1].run(v.map(_ + 1).map(_ => Aborts[Ex1].get(fail))) == + fail ) } } @@ -137,15 +137,15 @@ class abortsTest extends KyoTest { } "run" - { "success" in { - checkEquals[Either[Ex1, Int], Any]( - Aborts[Ex1].run(test(2)), - Right(5) + assert( + Aborts[Ex1].run(test(2)) == + Right(5) ) } "failure" in { - checkEquals[Either[Ex1, Int], Any]( - Aborts[Ex1].run(test(0)), - Left(ex1) + assert( + Aborts[Ex1].run(test(0)) == + Left(ex1) ) } } @@ -157,21 +157,21 @@ class abortsTest extends KyoTest { case i => 10 / i } "success" in { - checkEquals[Either[Ex1, Int], Any]( - Aborts[Ex1].run(Aborts[Ex1].catching(test(2))), - Right(5) + assert( + Aborts[Ex1].run(Aborts[Ex1].catching(test(2))) == + Right(5) ) } "failure" in { - checkEquals[Either[Ex1, Int], Any]( - Aborts[Ex1].run(Aborts[Ex1].catching(test(0))), - Left(ex1) + assert( + Aborts[Ex1].run(Aborts[Ex1].catching(test(0))) == + Left(ex1) ) } "subclass" in { - checkEquals[Either[RuntimeException, Int], Any]( - Aborts[RuntimeException].run(Aborts[RuntimeException].catching(test(0))), - Left(ex1) + assert( + Aborts[RuntimeException].run(Aborts[RuntimeException].catching(test(0))) == + Left(ex1) ) } } @@ -182,15 +182,15 @@ class abortsTest extends KyoTest { case i => 10 / i } "success" in { - checkEquals[Either[Ex1, Int], Any]( - Envs[Int].run(2)(Aborts[Ex1].run(Aborts[Ex1].catching(test(Envs[Int].get)))), - Right(5) + assert( + Envs[Int].run(2)(Aborts[Ex1].run(Aborts[Ex1].catching(test(Envs[Int].get)))) == + Right(5) ) } "failure" in { - checkEquals[Either[Ex1, Int], Any]( - Envs[Int].run(0)(Aborts[Ex1].run(Aborts[Ex1].catching(test(Envs[Int].get)))), - Left(ex1) + assert( + Envs[Int].run(0)(Aborts[Ex1].run(Aborts[Ex1].catching(test(Envs[Int].get)))) == + Left(ex1) ) } } diff --git a/kyo-core/shared/src/test/scala/kyoTest/envsTest.scala b/kyo-core/shared/src/test/scala/kyoTest/envsTest.scala index 02d9d412f..ccb79b717 100644 --- a/kyo-core/shared/src/test/scala/kyoTest/envsTest.scala +++ b/kyo-core/shared/src/test/scala/kyoTest/envsTest.scala @@ -10,9 +10,9 @@ class envsTest extends KyoTest { val v1 = Envs[Int].get.map(_ + 1) val v2: Int > Envs[Int] = v1 - checkEquals[Int, Any]( - Envs[Int].run(1)(v2), - 2 + assert( + Envs[Int].run(1)(v2) == + 2 ) } @@ -36,9 +36,9 @@ class envsTest extends KyoTest { val a = Envs[Service1].get.map(_(1)) val b: Int > Envs[Service1] = a - checkEquals[Int, Any]( - Envs[Service1].run(service1)(a), - 2 + assert( + Envs[Service1].run(service1)(a) == + 2 ) } "two services" - { @@ -48,15 +48,15 @@ class envsTest extends KyoTest { } val v: Int > (Envs[Service1] with Envs[Service2]) = a "same handling order" in { - checkEquals[Int, Any]( - Envs[Service1].run[Int, Any](service1)(Envs[Service2].run(service2)(v)), - 4 + assert( + Envs[Service1].run[Int, Any](service1)(Envs[Service2].run(service2)(v)) == + 4 ) } "reverse handling order" in { - checkEquals[Int, Any]( - Envs[Service2].run[Int, Any](service2)(Envs[Service1].run(service1)(v)), - 4 + assert( + Envs[Service2].run[Int, Any](service2)(Envs[Service1].run(service1)(v)) == + 4 ) } "dependent services" in { @@ -69,9 +69,9 @@ class envsTest extends KyoTest { val v2 = Envs[Service1].run[Int, Envs[Service2]](service1)(v) val v3: Int > Envs[Service2] = v2 - checkEquals[Int, Any]( - Envs[Service2].run(service2)(v3), - 4 + assert( + Envs[Service2].run(service2)(v3) == + 4 ) } } @@ -104,18 +104,18 @@ class envsTest extends KyoTest { val a = Envs[Service1].get.map(_(1)) val b: Int > (Envs[Service1] with Options) = a - checkEquals[Option[Int], Any]( - Options.run(Envs[Service1].run(service1)(a)), - Some(2) + assert( + Options.run(Envs[Service1].run(service1)(a)) == + Some(2) ) } "short circuit" in { val a = Envs[Service1].get.map(_(0)) val b: Int > (Envs[Service1] with Options) = a - checkEquals[Option[Int], Any]( - Options.run(Envs[Service1].run(service1)(a)), - None + assert( + Options.run(Envs[Service1].run(service1)(a)) == + None ) } } @@ -127,19 +127,19 @@ class envsTest extends KyoTest { } val v: Int > (Envs[Service1] with Envs[Service2] with Options) = a "same handling order" in { - checkEquals[Option[Int], Any]( + assert( Options.run(Envs[Service1].run(service1)( Envs[Service2].run(service2)(v) - ): Int > Options), - Option(3) + ): Int > Options) == + Option(3) ) } "reverse handling order" in { - checkEquals[Option[Int], Any]( + assert( Options.run(Envs[Service2].run(service2)( Envs[Service1].run(service1)(v) - ): Int > Options), - Option(3) + ): Int > Options) == + Option(3) ) } "dependent services" in { @@ -150,9 +150,9 @@ class envsTest extends KyoTest { ) val v1: Service1 > Envs[Service2] = s1 val v2: Int > (Envs[Service2] with Options) = Envs[Service1].run(service1)(v) - checkEquals[Option[Int], Any]( - Options.run(Envs[Service2].run(service2)(v2)), - Some(3) + assert( + Options.run(Envs[Service2].run(service2)(v2)) == + Some(3) ) } } diff --git a/kyo-core/shared/src/test/scala/kyoTest/iosTest.scala b/kyo-core/shared/src/test/scala/kyoTest/iosTest.scala index 8f68aad51..8511a02b6 100644 --- a/kyo-core/shared/src/test/scala/kyoTest/iosTest.scala +++ b/kyo-core/shared/src/test/scala/kyoTest/iosTest.scala @@ -26,10 +26,7 @@ class iosTest extends KyoTest { 1 } assert(!called) - checkEquals[Int, Nothing]( - IOs.runLazy(v), - 1 - ) + assert(IOs.runLazy(v) == 1) assert(called) } "next handled effects can execute" in run { @@ -44,9 +41,9 @@ class iosTest extends KyoTest { assert(!called) val v2 = IOs.runLazy(v) assert(!called) - checkEquals[Int, Nothing]( - Envs[Int].run(1)(v2), - 1 + assert( + Envs[Int].run(1)(v2) == + 1 ) assert(called) } @@ -74,9 +71,9 @@ class iosTest extends KyoTest { else i } - checkEquals[Int, Nothing]( - IOs.runLazy(loop(0)), - frames + assert( + IOs.runLazy(loop(0)) == + frames ) } } @@ -89,9 +86,9 @@ class iosTest extends KyoTest { 1 } assert(!called) - checkEquals[Int, Nothing]( - IOs.run[Int](v), - 1 + assert( + IOs.run[Int](v) == + 1 ) assert(called) } @@ -129,20 +126,20 @@ class iosTest extends KyoTest { "ensure" - { "success" in { var called = false - checkEquals[Try[Int], Any]( - Tries.run(IOs.run(IOs.ensure[Int, Any] { called = true }(1))), - Try(1) + assert( + Tries.run(IOs.run(IOs.ensure[Int, Any] { called = true }(1))) == + Try(1) ) assert(called) } "failure" in { val ex = new Exception var called = false - checkEquals[Try[Int], Any]( + assert( Tries.run(IOs.run(IOs.ensure { called = true } { IOs[Int, Any](throw ex) - })), - Failure(ex) + })) == + Failure(ex) ) assert(called) } diff --git a/kyo-core/shared/src/test/scala/kyoTest/listsTest.scala b/kyo-core/shared/src/test/scala/kyoTest/listsTest.scala index 5ce47b4a1..9a164b496 100644 --- a/kyo-core/shared/src/test/scala/kyoTest/listsTest.scala +++ b/kyo-core/shared/src/test/scala/kyoTest/listsTest.scala @@ -8,72 +8,69 @@ import kyo.lists._ class listsTest extends KyoTest { "one" in { - checkEquals[List[Int], Nothing]( - Lists.run(Lists.foreach(List(1)).map(_ + 1)), - List(2) + assert( + Lists.run(Lists.foreach(List(1)).map(_ + 1)) == + List(2) ) } "multiple" in { - checkEquals[List[Int], Nothing]( - Lists.run(Lists.foreach(List(1, 2, 3)).map(_ + 1)), - List(2, 3, 4) + assert( + Lists.run(Lists.foreach(List(1, 2, 3)).map(_ + 1)) == + List(2, 3, 4) ) } "nested" in { - checkEquals[List[Int], Nothing]( + assert( Lists.run(Lists.foreach(List(1, 2, 3)).map(i => Lists.foreach(List(i * 10, i * 100)) - )), - List(10, 100, 20, 200, 30, 300) + )) === + List(10, 100, 20, 200, 30, 300) ) } "drop" in { - checkEquals[List[Int], Nothing]( + assert( Lists.run(Lists.foreach(List(1, 2, 3)).map(i => if (i < 2) Lists.drop else Lists.foreach(List(i * 10, i * 100)) - )), - List(20, 200, 30, 300) + )) == + List(20, 200, 30, 300) ) } "filter" in { - checkEquals[List[Int], Nothing]( + assert( Lists.run(Lists.foreach(List(1, 2, 3)).map(i => Lists.dropIf(i >= 2).map(_ => Lists.foreach(List(i * 10, i * 100))) - )), - List(20, 200, 30, 300) + )) == + List(20, 200, 30, 300) ) } "collect" in { - checkEquals[List[Int], Nothing]( - Lists.collect(List(1, 2)).pure, - List(1, 2) + assert( + Lists.collect(List(1, 2)).pure == + List(1, 2) ) } "repeat" in { - checkEquals[List[Int], Nothing]( - Lists.run(Lists.repeat(3).andThen(42)), - List(42, 42, 42) + assert( + Lists.run(Lists.repeat(3).andThen(42)) == + List(42, 42, 42) ) } "traverse" in { - checkEquals[List[Int], Nothing]( - Lists.traverse(List(1, 2))(_ + 1).pure, - List(2, 3) + assert( + Lists.traverse(List(1, 2))(_ + 1).pure == + List(2, 3) ) } "traverseUnit" in { var acc = List.empty[Int] - checkEquals[Unit, Nothing]( - Lists.traverseUnit(List(1, 2))(acc :+= _).pure, - () - ) + Lists.traverseUnit(List(1, 2))(acc :+= _).pure assert(acc == List(1, 2)) } "fill" in { - checkEquals[List[Int], Nothing]( - IOs.run(Lists.fill(100)(IOs(1))), - List.fill(100)(1) + assert( + IOs.run(Lists.fill(100)(IOs(1))) == + List.fill(100)(1) ) } } diff --git a/kyo-core/shared/src/test/scala/kyoTest/localsTest.scala b/kyo-core/shared/src/test/scala/kyoTest/localsTest.scala index 267f22dd1..2288f0aeb 100644 --- a/kyo-core/shared/src/test/scala/kyoTest/localsTest.scala +++ b/kyo-core/shared/src/test/scala/kyoTest/localsTest.scala @@ -14,31 +14,31 @@ class localsTest extends KyoTest { } "get" in { val l = Locals.init(10) - checkEquals[Int, Nothing]( - IOs.run[Int](l.get), - 10 + assert( + IOs.run[Int](l.get) == + 10 ) } "effect + get" in { val l = Locals.init(10) - checkEquals[Option[Int], Nothing]( - IOs.run[Option[Int]](Options.run(Options(1).map(_ => l.get))), - Some(10) + assert( + IOs.run[Option[Int]](Options.run(Options(1).map(_ => l.get))) == + Some(10) ) } "effect + get + effect" in { val l = Locals.init(10) - checkEquals[Option[Int], Nothing]( - IOs.run[Option[Int]](Options.run(Options(1).map(_ => l.get).map(Options(_)))), - Some(10) + assert( + IOs.run[Option[Int]](Options.run(Options(1).map(_ => l.get).map(Options(_)))) == + Some(10) ) } "multiple" in { val l1 = Locals.init(10) val l2 = Locals.init(20) - checkEquals[(Int, Int), Nothing]( - IOs.run[(Int, Int)](zip(l1.get, l2.get)), - (10, 20) + assert( + IOs.run[(Int, Int)](zip(l1.get, l2.get)) == + (10, 20) ) } } @@ -46,31 +46,33 @@ class localsTest extends KyoTest { "let" - { "get" in { val l = Locals.init(10) - checkEquals[Int, Nothing]( - IOs.run[Int](l.let(20)(l.get)), - 20 + assert( + IOs.run[Int](l.let(20)(l.get)) == + 20 ) } "effect + get" in { val l = Locals.init(10) - checkEquals[Option[Int], Nothing]( - IOs.run[Option[Int]](Options.run(Options(1).map(_ => l.let(20)(l.get)))), - Some(20) + assert( + IOs.run[Option[Int]](Options.run(Options(1).map(_ => l.let(20)(l.get)))) == + Some(20) ) } "effect + get + effect" in { val l = Locals.init(10) - checkEquals[Option[Int], Nothing]( - IOs.run[Option[Int]](Options.run(Options(1).map(_ => l.let(20)(l.get).map(Options(_))))), - Some(20) + assert( + IOs.run[Option[Int]]( + Options.run(Options(1).map(_ => l.let(20)(l.get).map(Options(_)))) + ) == + Some(20) ) } "multiple" in { val l1 = Locals.init(10) val l2 = Locals.init(20) - checkEquals[(Int, Int), Nothing]( - IOs.run[(Int, Int)](zip(l1.let(30)(l1.get), l2.let(40)(l2.get))), - (30, 40) + assert( + IOs.run[(Int, Int)](zip(l1.let(30)(l1.get), l2.let(40)(l2.get))) == + (30, 40) ) } } @@ -78,52 +80,52 @@ class localsTest extends KyoTest { "save" - { "let + save" in { val l = Locals.init(10) - checkEquals[Locals.State, Nothing]( - IOs.run[Locals.State](l.let(20)(Locals.save)), - Map(l -> 20) + assert( + IOs.run[Locals.State](l.let(20)(Locals.save)) == + Map(l -> 20) ) } "let + effect + save" in { val l = Locals.init(10) - checkEquals[Option[Locals.State], Nothing]( - IOs.run[Option[Locals.State]](Options.run(l.let(20)(Options(1).map(_ => Locals.save)))), - Some(Map(l -> 20)) + assert( + IOs.run[Option[Locals.State]](Options.run(l.let(20)(Options(1).map(_ => Locals.save)))) == + Some(Map(l -> 20)) ) } "effect + let + save" in { val l = Locals.init(10) - checkEquals[Option[Locals.State], Nothing]( - IOs.run[Option[Locals.State]](Options.run(Options(1).map(_ => l.let(20)(Locals.save)))), - Some(Map(l -> 20)) + assert( + IOs.run[Option[Locals.State]](Options.run(Options(1).map(_ => l.let(20)(Locals.save)))) == + Some(Map(l -> 20)) ) } "effect + let + save + effect" in { val l = Locals.init(10) - checkEquals[Option[Locals.State], Nothing]( + assert( IOs.run[Option[Locals.State]](Options.run(Options(1).map(_ => l.let(20)(Locals.save).map(Options(_)) - ))), - Some(Map(l -> 20)) + ))) == + Some(Map(l -> 20)) ) } "nested" in { val l1 = Locals.init(10) val l2 = Locals.init(20) - checkEquals[Locals.State, Nothing]( + assert( IOs.run[Locals.State]( l1.let(30)( l2.let(40)( Locals.save ) ) - ), - Map(l1 -> 30, l2 -> 40) + ) == + Map(l1 -> 30, l2 -> 40) ) } "nested + effect" in { val l1 = Locals.init(10) val l2 = Locals.init(20) - checkEquals[Option[Locals.State], Nothing]( + assert( IOs.run[Option[Locals.State]]( Options.run( l1.let(30)( @@ -132,14 +134,14 @@ class localsTest extends KyoTest { ) ) ) - ), - Some(Map(l1 -> 30, l2 -> 40)) + ) == + Some(Map(l1 -> 30, l2 -> 40)) ) } "nested + effects" in { val l1 = Locals.init(10) val l2 = Locals.init(20) - checkEquals[Option[Locals.State], Nothing]( + assert( IOs.run[Option[Locals.State]]( Options.run( l1.let(30)( @@ -148,15 +150,15 @@ class localsTest extends KyoTest { ).map(Options(_)) ).map(Options(_)) ) - ), - Some(Map(l1 -> 30, l2 -> 40)) + ) == + Some(Map(l1 -> 30, l2 -> 40)) ) } "multiple" in { val l1 = Locals.init(0) val l2 = Locals.init(0) val l3 = Locals.init(0) - checkEquals[(Locals.State, Locals.State), Nothing]( + assert( IOs.run[(Locals.State, Locals.State)]( l3.let(20) { zip( @@ -164,15 +166,15 @@ class localsTest extends KyoTest { l2.let(40)(Locals.save) ) } - ), - (Map(l3 -> 20, l1 -> 30), Map(l3 -> 20, l2 -> 40)) + ) == + (Map(l3 -> 20, l1 -> 30), Map(l3 -> 20, l2 -> 40)) ) } "multiple + effect" in { val l1 = Locals.init(0) val l2 = Locals.init(0) val l3 = Locals.init(0) - checkEquals[Option[(Locals.State, Locals.State)], Nothing]( + assert( IOs.run[Option[(Locals.State, Locals.State)]]( Options.run( l3.let(20) { @@ -184,8 +186,8 @@ class localsTest extends KyoTest { ) } ) - ), - Some((Map(l3 -> 20, l1 -> 30), Map(l3 -> 20, l2 -> 40))) + ) == + Some((Map(l3 -> 20, l1 -> 30), Map(l3 -> 20, l2 -> 40))) ) } } @@ -205,53 +207,53 @@ class localsTest extends KyoTest { } } "get" in { - checkEquals[Int, Nothing]( - IOs.run[Int](Locals.restore(state)(l1.get)), - 10 + assert( + IOs.run[Int](Locals.restore(state)(l1.get)) == + 10 ) } "effect + get" in { - checkEquals[Option[Int], Nothing]( + assert( IOs.run[Option[Int]]( Options.run(Locals.restore[Int, Options with IOs](state)(Options(1).map(_ => l1.get))) - ), - Some(10) + ) == + Some(10) ) } "effect + get + effect" in { - checkEquals[Option[Int], Nothing]( + assert( IOs.run[Option[Int]]( Options.run(Locals.restore[Int, Options with IOs](state)( Options(1).map(_ => l1.get).map(Options(_)) )) - ), - Some(10) + ) == + Some(10) ) } "multiple" in { - checkEquals[(Int, Int), Nothing]( - IOs.run[(Int, Int)](Locals.restore(state)(zip(l1.get, l2.get))), - (10, 20) + assert( + IOs.run[(Int, Int)](Locals.restore(state)(zip(l1.get, l2.get))) == + (10, 20) ) } "multiple + effect" in { - checkEquals[Option[(Int, Int)], Nothing]( + assert( IOs.run[Option[(Int, Int)]]( Options.run(Locals.restore[(Int, Int), Options with IOs](state)(Options(1).map(_ => zip(l1.get, l2.get) ))) - ), - Some((10, 20)) + ) == + Some((10, 20)) ) } "nested" in { - checkEquals[(Int, Int), Nothing]( + assert( IOs.run[(Int, Int)]( l1.let(30) { Locals.restore(state)(zip(l1.get, l2.get)) } - ), - (10, 20) + ) == + (10, 20) ) } } diff --git a/kyo-core/shared/src/test/scala/kyoTest/optionsTest.scala b/kyo-core/shared/src/test/scala/kyoTest/optionsTest.scala index 2981d562e..3fb5c8b45 100644 --- a/kyo-core/shared/src/test/scala/kyoTest/optionsTest.scala +++ b/kyo-core/shared/src/test/scala/kyoTest/optionsTest.scala @@ -15,146 +15,146 @@ class optionsTest extends KyoTest { "apply" - { "null" in { assert((Options.run(Options(null: String))).pure == None) - checkEquals[Option[String], Any]( - Options.run(Options(null: String)), - None + assert( + Options.run(Options(null: String)) == + None ) } "value" in { - checkEquals[Option[String], Any]( - Options.run(Options("hi")), - Option("hi") + assert( + Options.run(Options("hi")) == + Option("hi") ) } } "pure" - { "handle" in { - checkEquals[Option[Int], Any]( - Options.run(1: Int > Options), - Option(1) + assert( + Options.run(1: Int > Options) == + Option(1) ) } "handle + transform" in { - checkEquals[Option[Int], Any]( - Options.run((1: Int > Options).map(_ + 1)), - Option(2) + assert( + Options.run((1: Int > Options).map(_ + 1)) == + Option(2) ) } "handle + effectful transform" in { - checkEquals[Option[Int], Any]( - Options.run((1: Int > Options).map(i => Options.get(Option(i + 1)))), - Option(2) + assert( + Options.run((1: Int > Options).map(i => Options.get(Option(i + 1)))) == + Option(2) ) } "handle + transform + effectful transform" in { - checkEquals[Option[Int], Any]( - Options.run((1: Int > Options).map(_ + 1).map(i => Options.get(Option(i + 1)))), - Option(3) + assert( + Options.run((1: Int > Options).map(_ + 1).map(i => Options.get(Option(i + 1)))) == + Option(3) ) } } "effectful" - { "handle" in { - checkEquals[Option[Int], Any]( - Options.run(Options.get(Option(1))), - Option(1) + assert( + Options.run(Options.get(Option(1))) == + Option(1) ) } "handle + transform" in { - checkEquals[Option[Int], Any]( - Options.run(Options.get(Option(1)).map(_ + 1)), - Option(2) + assert( + Options.run(Options.get(Option(1)).map(_ + 1)) == + Option(2) ) } "handle + effectful transform" in { - checkEquals[Option[Int], Any]( - Options.run(Options.get(Option(1)).map(i => Options.get(Option(i + 1)))), - Option(2) + assert( + Options.run(Options.get(Option(1)).map(i => Options.get(Option(i + 1)))) == + Option(2) ) } "handle + transform + effectful transform" in { - checkEquals[Option[Int], Any]( - Options.run(Options.get(Option(1)).map(_ + 1).map(i => Options.get(Option(i + 1)))), - Option(3) + assert( + Options.run(Options.get(Option(1)).map(_ + 1).map(i => Options.get(Option(i + 1)))) == + Option(3) ) } } "Options.run" - { "pure" in { - checkEquals[Option[Int], Any]( - Options.run(1: Int > Options), - Option(1) + assert( + Options.run(1: Int > Options) == + Option(1) ) } "not empty" in { - checkEquals[Option[Int], Any]( - Options.run(Options.get(Option(1))), - Option(1) + assert( + Options.run(Options.get(Option(1))) == + Option(1) ) } "empty" in { - checkEquals[Option[Int], Any]( - Options.run(Options.get(Option.empty[Int])), - None + assert( + Options.run(Options.get(Option.empty[Int])) == + None ) } } "orElse" - { "empty" in { - checkEquals[Option[Int], Any]( - Options.run(Options.orElse[Int, Any]()), - None + assert( + Options.run(Options.orElse[Int, Any]()) == + None ) } "not empty" in { - checkEquals[Option[Int], Any]( - Options.run(Options.orElse(Options.get(Option(1)))), - Option(1) + assert( + Options.run(Options.orElse(Options.get(Option(1)))) == + Option(1) ) } "not empty + empty" in { - checkEquals[Option[Int], Any]( - Options.run(Options.orElse(Options.get(Option(1)), Options.get(Option.empty[Int]))), - Option(1) + assert( + Options.run(Options.orElse(Options.get(Option(1)), Options.get(Option.empty[Int]))) == + Option(1) ) } "empty + not empty" in { - checkEquals[Option[Int], Any]( - Options.run(Options.orElse(Options.get(Option.empty[Int]), Options.get(Option(1)))), - Option(1) + assert( + Options.run(Options.orElse(Options.get(Option.empty[Int]), Options.get(Option(1)))) == + Option(1) ) } "empty + empty" in { - checkEquals[Option[Int], Any]( + assert( Options.run(Options.orElse( Options.get(Option.empty[Int]), Options.get(Option.empty[Int]) - )), - None + )) == + None ) } "not empty + not empty" in { - checkEquals[Option[Int], Any]( - Options.run(Options.orElse(Options.get(Option(1)), Options.get(Option(2)))), - Option(1) + assert( + Options.run(Options.orElse(Options.get(Option(1)), Options.get(Option(2)))) == + Option(1) ) } "not empty + not empty + not empty" in { - checkEquals[Option[Int], Any]( + assert( Options.run(Options.orElse( Options.get(Option(1)), Options.get(Option(2)), Options.get(Option(3)) - )), - Option(1) + )) == + Option(1) ) } "not empty + not empty + not empty + not empty" in { - checkEquals[Option[Int], Any]( + assert( Options.run( Options.orElse( Options.get(Option(1)), @@ -162,12 +162,12 @@ class optionsTest extends KyoTest { Options.get(Option(3)), Options.get(Option(4)) ) - ), - Option(1) + ) == + Option(1) ) } "not empty + not empty + not empty + not empty + not empty" in { - checkEquals[Option[Int], Any]( + assert( Options.run( Options.orElse( Options.get(Option(1)), @@ -176,35 +176,35 @@ class optionsTest extends KyoTest { Options.get(Option(4)), Options.get(Option(5)) ) - ), - Option(1) + ) == + Option(1) ) } } "getOrElse" - { "empty" in { - checkEquals[Int, Any]( - Options.getOrElse(Option.empty[Int], 1), - 1 + assert( + Options.getOrElse(Option.empty[Int], 1) == + 1 ) } "not empty" in { - checkEquals[Int, Any]( - Options.getOrElse(Some(2), 1), - 2 + assert( + Options.getOrElse(Some(2), 1) == + 2 ) } "or fail" in { val e = new Exception() val a: Int > Tries = Options.getOrElse(Option.empty[Int], Tries.fail("fail")) - checkEquals[Try[Int], Any]( - Tries.run(Options.getOrElse(Option.empty[Int], Tries.fail(e))), - Failure(e) + assert( + Tries.run(Options.getOrElse(Option.empty[Int], Tries.fail(e))) == + Failure(e) ) - checkEquals[Try[Int], Any]( - Tries.run(Options.getOrElse(Some(1), Tries.fail(e))), - Success(1) + assert( + Tries.run(Options.getOrElse(Some(1), Tries.fail(e))) == + Success(1) ) } } diff --git a/kyo-core/shared/src/test/scala/kyoTest/triesTest.scala b/kyo-core/shared/src/test/scala/kyoTest/triesTest.scala index 3a325dabd..3ad481ffd 100644 --- a/kyo-core/shared/src/test/scala/kyoTest/triesTest.scala +++ b/kyo-core/shared/src/test/scala/kyoTest/triesTest.scala @@ -17,146 +17,146 @@ class triesTest extends KyoTest { "apply" - { "failure" in { - checkEquals[Try[Int], Nothing]( - Tries.run(Tries((throw e): Int)), - Failure(e) + assert( + Tries.run(Tries((throw e): Int)) == + Failure(e) ) } "success" in { - checkEquals[Try[Int], Nothing]( - Tries.run(Tries(1)), - Success(1) + assert( + Tries.run(Tries(1)) == + Success(1) ) } } "run" - { "failure" in { - checkEquals[Try[Int], Nothing]( - Tries.run(Tries((throw e): Int)), - Failure(e) + assert( + Tries.run(Tries((throw e): Int)) == + Failure(e) ) } "success" in { - checkEquals[Try[Int], Nothing]( - Tries.run(Tries(1)), - Success(1) + assert( + Tries.run(Tries(1)) == + Success(1) ) } } "get" - { "failure" in { - checkEquals[Try[Int], Nothing]( - Tries.run(Tries.get(Failure[Int](e))), - Failure(e) + assert( + Tries.run(Tries.get(Failure[Int](e))) == + Failure(e) ) } "success" in { - checkEquals[Try[Int], Nothing]( - Tries.run(Tries.get(Success(1))), - Success(1) + assert( + Tries.run(Tries.get(Success(1))) == + Success(1) ) } } "fail" in { - checkEquals[Try[Int], Nothing]( - Tries.run(Tries.fail[Int](e)), - Failure(e) + assert( + Tries.run(Tries.fail[Int](e)) == + Failure(e) ) } "pure" - { "handle" in { - checkEquals[Try[Int], Nothing]( - Tries.run(1: Int > Tries), - Try(1) + assert( + Tries.run(1: Int > Tries) == + Try(1) ) } "handle + transform" in { - checkEquals[Try[Int], Nothing]( - Tries.run((1: Int > Tries).map(_ + 1)), - Try(2) + assert( + Tries.run((1: Int > Tries).map(_ + 1)) == + Try(2) ) } "handle + effectful transform" in { - checkEquals[Try[Int], Nothing]( - Tries.run((1: Int > Tries).map(i => Tries.get(Try(i + 1)))), - Try(2) + assert( + Tries.run((1: Int > Tries).map(i => Tries.get(Try(i + 1)))) == + Try(2) ) } "handle + transform + effectful transform" in { - checkEquals[Try[Int], Nothing]( - Tries.run((1: Int > Tries).map(_ + 1).map(i => Tries.get(Try(i + 1)))), - Try(3) + assert( + Tries.run((1: Int > Tries).map(_ + 1).map(i => Tries.get(Try(i + 1)))) == + Try(3) ) } "handle + transform + failed effectful transform" in { val e = new Exception - checkEquals[Try[Int], Nothing]( - Tries.run((1: Int > Tries).map(_ + 1).map(i => Tries.get(Try[Int](throw e)))), - Failure(e) + assert( + Tries.run((1: Int > Tries).map(_ + 1).map(i => Tries.get(Try[Int](throw e)))) == + Failure(e) ) } } "effectful" - { "handle" in { - checkEquals[Try[Int], Nothing]( - Tries.run(Tries.get(Try(1))), - Try(1) + assert( + Tries.run(Tries.get(Try(1))) == + Try(1) ) } "handle + transform" in { - checkEquals[Try[Int], Nothing]( - Tries.run(Tries.get(Try(1)).map(_ + 1)), - Try(2) + assert( + Tries.run(Tries.get(Try(1)).map(_ + 1)) == + Try(2) ) } "handle + effectful transform" in { - checkEquals[Try[Int], Nothing]( - Tries.run(Tries.get(Try(1)).map(i => Tries.get(Try(i + 1)))), - Try(2) + assert( + Tries.run(Tries.get(Try(1)).map(i => Tries.get(Try(i + 1)))) == + Try(2) ) } "handle + transform + effectful transform" in { - checkEquals[Try[Int], Nothing]( - Tries.run((Tries.get(Try(1))).map(_ + 1).map(i => Tries.get(Try(i + 1)))), - Try(3) + assert( + Tries.run((Tries.get(Try(1))).map(_ + 1).map(i => Tries.get(Try(i + 1)))) == + Try(3) ) } "handle + failed transform" in { - checkEquals[Try[Int], Nothing]( - Tries.run((Tries.get(Try(1))).map(_ => (throw e): Int)), - Failure(e) + assert( + Tries.run((Tries.get(Try(1))).map(_ => (throw e): Int)) == + Failure(e) ) } "handle + transform + effectful transform + failed transform" in { - checkEquals[Try[Int], Nothing]( + assert( Tries.run((Tries.get(Try(1))).map(_ + 1).map(i => Tries.get(Try(i + 1))).map(_ => (throw e): Int - )), - Failure(e) + )) == + Failure(e) ) } "handle + transform + failed effectful transform" in { - checkEquals[Try[Int], Nothing]( - Tries.run((Tries.get(Try(1))).map(_ + 1).map(i => Tries.get(Try((throw e): Int)))), - Failure(e) + assert( + Tries.run((Tries.get(Try(1))).map(_ + 1).map(i => Tries.get(Try((throw e): Int)))) == + Failure(e) ) } "nested effect + failure" in { - checkEquals[Option[Try[Int]], Nothing]( + assert( Options.run( Tries.run[Int, Options]( Tries.get(Try(Option(1))).map(opt => Options.get(opt: Option[Int] > Tries).map(_ => (throw e): Int) ) ) - ), - Some(Failure(e)) + ) == + Some(Failure(e)) ) } }