Skip to content

Commit

Permalink
reenable creation ticket tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rmgk committed Mar 8, 2024
1 parent 81e36b1 commit d7eab5a
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 65 deletions.
Original file line number Diff line number Diff line change
@@ -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)
}
}

}

This file was deleted.

0 comments on commit d7eab5a

Please sign in to comment.