Skip to content

Commit

Permalink
remove kyotest.checkEquals
Browse files Browse the repository at this point in the history
  • Loading branch information
fwbrasil committed Dec 4, 2023
1 parent 01407b3 commit 102ac4b
Show file tree
Hide file tree
Showing 8 changed files with 349 additions and 375 deletions.
22 changes: 0 additions & 22 deletions kyo-core/shared/src/test/scala/kyoTest/KyoTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
132 changes: 66 additions & 66 deletions kyo-core/shared/src/test/scala/kyoTest/abortsTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
}
Expand All @@ -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
)
}
}
Expand All @@ -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)
)
}
}
Expand All @@ -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)
)
}
}
Expand All @@ -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)
)
}
}
Expand Down
60 changes: 30 additions & 30 deletions kyo-core/shared/src/test/scala/kyoTest/envsTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}

Expand All @@ -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" - {
Expand All @@ -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 {
Expand All @@ -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
)
}
}
Expand Down Expand Up @@ -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
)
}
}
Expand All @@ -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 {
Expand All @@ -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)
)
}
}
Expand Down
Loading

0 comments on commit 102ac4b

Please sign in to comment.