diff --git a/Modules/Reactives/shared/src/test/scala/tests/rescala/misc/CreationTicketTest.scala b/Modules/Reactives/shared/src/test/scala/tests/rescala/misc/CreationTicketTest.scala new file mode 100644 index 000000000..77381e0d2 --- /dev/null +++ b/Modules/Reactives/shared/src/test/scala/tests/rescala/misc/CreationTicketTest.scala @@ -0,0 +1,71 @@ +package tests.rescala.misc + +import reactives.core.CreationScope.{DynamicCreationScope, StaticCreationScope} +import reactives.core.{AdmissionTicket, CreationScope, CreationTicket, DynamicScopeImpl, Scheduler, Transaction} +import tests.rescala.testtools.RETests +import reactives.operator.Interface.State +import reactives.default.transaction + +class CreationTicketTest extends RETests { + + // if (engine != reactives.interfaces.toposort) { + /* this test uses some shady planned()(identity) to get the turn object out of the transaction + * you should not do this. */ + def getTurn(implicit engine: Scheduler[State]): Transaction[State] = + engine.forceNewTransaction()(_.tx) + + test("none Dynamic No Implicit") { + assert(implicitly[CreationTicket[State]].scope.isInstanceOf[DynamicCreationScope[State]]) + } + + test("some Dynamic No Implicit") { + transaction() { (dynamicTurn: AdmissionTicket[State]) => + assert(implicitly[CreationTicket[State]].scope.isInstanceOf[DynamicCreationScope[State]]) + assertEquals(CreationScope.search, summon[CreationTicket[State]].scope) + assertEquals(implicitly[CreationTicket[State]].scope.embedCreation(x ?=> x), dynamicTurn.tx) + } + } + + test("none Dynamic Some Implicit") { + implicit val implicitTurn: Transaction[State] = getTurn + implicitly[CreationTicket[State]].scope match + case StaticCreationScope(tx) => assertEquals(tx, implicitTurn) + case other => assert(false) + assertEquals(implicitly[CreationTicket[State]].scope.embedCreation(x ?=> x), implicitTurn) + } + + test("some Dynamic Some Implicit") { + transaction() { (_: AdmissionTicket[State]) => + implicit val implicitTurn: Transaction[State] = getTurn + implicitly[CreationTicket[State]].scope match + case StaticCreationScope(tx) => assertEquals(tx, implicitTurn) + case other => assert(false) + assertEquals(implicitly[CreationTicket[State]].scope.embedCreation(x ?=> x), implicitTurn) + } + } + + test("implicit In Closures") { + val closureDefinition: Transaction[State] = getTurn(reactives.default.global.scheduler) + val closure = { + implicit def it: Transaction[State] = closureDefinition + () => implicitly[CreationTicket[State]] + } + transaction() { _ => + closure().scope match + case StaticCreationScope(tx) => assertEquals(tx, closureDefinition) + case other => assert(false) + assertEquals(closure().scope.embedCreation(x ?=> x), closureDefinition) + } + } + + test("dynamic In Closures") { + val closure: () => CreationTicket[State] = { + transaction() { _ => () => implicitly[CreationTicket[State]] } + } + transaction() { dynamic => + assert(closure().scope.isInstanceOf[DynamicCreationScope[State]]) + assertEquals(closure().scope.embedCreation(x ?=> x), dynamic.tx) + } + } + +} diff --git a/Modules/Reactives/shared/src/test/scala/tests/rescala/misc/CreationTicketTest.scala.nocompile b/Modules/Reactives/shared/src/test/scala/tests/rescala/misc/CreationTicketTest.scala.nocompile deleted file mode 100644 index 7f34569ba..000000000 --- a/Modules/Reactives/shared/src/test/scala/tests/rescala/misc/CreationTicketTest.scala.nocompile +++ /dev/null @@ -1,65 +0,0 @@ -package tests.rescala.misc - -import reactives.core.{AdmissionTicket, CreationTicket, Scheduler, Transaction} -import tests.rescala.testtools.RETests - -class CreationTicketTest extends RETests { - multiEngined { engine => - import engine._ - - //if (engine != reactives.interfaces.toposort) { - /* this test uses some shady planned()(identity) to get the turn object out of the transaction - * you should not do this. */ - def getTurn(implicit engine: Scheduler[BundleState]): Transaction[BundleState] = - engine.forceNewTransaction()(_.tx) - - test("none Dynamic No Implicit") { - assertEquals(implicitly[CreationTicket[BundleState]].scope.self, Right(engine.scheduler)) - } - - test("some Dynamic No Implicit") { - engine.transaction() { (dynamicTurn: AdmissionTicket[BundleState]) => - assertEquals(implicitly[CreationTicket[BundleState]].scope.self, Right(engine.scheduler)) - assertEquals(implicitly[CreationTicket[BundleState]].scope.embedTransaction(identity), dynamicTurn.tx) - } - } - - test("none Dynamic Some Implicit") { - implicit val implicitTurn: Transaction[engine.BundleState] = getTurn - assertEquals(implicitly[CreationTicket[BundleState]].scope.self, Left(implicitTurn)) - assertEquals(implicitly[CreationTicket[BundleState]].scope.embedTransaction(identity), implicitTurn) - } - - test("some Dynamic Some Implicit") { - engine.transaction() { (_: AdmissionTicket[BundleState]) => - implicit val implicitTurn: Transaction[engine.BundleState] = getTurn - assertEquals(implicitly[CreationTicket[BundleState]].scope.self, Left(implicitTurn)) - assertEquals(implicitly[CreationTicket[BundleState]].scope.embedTransaction(identity), implicitTurn) - } - } - - test("implicit In Closures") { - val closureDefinition: Transaction[BundleState] = getTurn(engine.scheduler) - val closure = { - implicit def it: Transaction[BundleState] = closureDefinition - () => implicitly[CreationTicket[BundleState]] - } - engine.transaction() { _ => - assertEquals(closure().scope.self, Left(closureDefinition)) - assertEquals(closure().scope.embedTransaction(identity), closureDefinition) - } - } - - test("dynamic In Closures") { - val closure: () => CreationTicket[BundleState] = { - engine.transaction() { _ => () => implicitly[CreationTicket[BundleState]] } - } - engine.transaction() { dynamic => - assertEquals(closure().scope.self, Right(engine.scheduler)) - assertEquals(closure().scope.embedTransaction(identity), dynamic.tx) - } - } - - //} - } -}