-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
71 additions
and
65 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
Modules/Reactives/shared/src/test/scala/tests/rescala/misc/CreationTicketTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
|
||
} |
65 changes: 0 additions & 65 deletions
65
...les/Reactives/shared/src/test/scala/tests/rescala/misc/CreationTicketTest.scala.nocompile
This file was deleted.
Oops, something went wrong.