mirror of
https://github.com/DaanVandenBosch/phantasmal-world.git
synced 2025-04-03 13:58:28 +08:00
Moved dependency test to CellTests.
This commit is contained in:
parent
82524f1f2d
commit
e6ca3b9871
@ -1,18 +1,44 @@
|
||||
package world.phantasmal.cell
|
||||
|
||||
import world.phantasmal.cell.test.CellTestSuite
|
||||
import world.phantasmal.core.disposable.use
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertNotEquals
|
||||
import kotlin.test.assertNotNull
|
||||
import kotlin.test.assertNull
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
/**
|
||||
* Test suite for all [Cell] implementations. There is a subclass of this suite for every [Cell]
|
||||
* implementation.
|
||||
*/
|
||||
interface CellTests : DependencyTests {
|
||||
override fun createProvider(): Provider
|
||||
interface CellTests : CellTestSuite {
|
||||
fun createProvider(): Provider
|
||||
|
||||
/**
|
||||
* Tests low level [Dependency] implementation.
|
||||
*/
|
||||
@Test
|
||||
fun correctly_emits_invalidation_notifications_to_its_dependents() = test {
|
||||
val p = createProvider()
|
||||
var dependencyInvalidatedCalled: Boolean
|
||||
|
||||
p.cell.addDependent(object : Dependent {
|
||||
override fun dependencyInvalidated(dependency: Dependency<*>) {
|
||||
assertEquals(p.cell, dependency)
|
||||
dependencyInvalidatedCalled = true
|
||||
}
|
||||
})
|
||||
|
||||
repeat(5) { index ->
|
||||
dependencyInvalidatedCalled = false
|
||||
|
||||
p.emit()
|
||||
|
||||
assertTrue(dependencyInvalidatedCalled, "repetition $index")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun value_is_accessible_without_observers() = test {
|
||||
@ -202,10 +228,13 @@ interface CellTests : DependencyTests {
|
||||
assertEquals(mapped.value, observedValue)
|
||||
}
|
||||
|
||||
interface Provider : DependencyTests.Provider {
|
||||
interface Provider {
|
||||
val cell: Cell<Any>
|
||||
|
||||
override val dependency: Dependency<*> get() = cell
|
||||
/**
|
||||
* Makes [cell] emit a change.
|
||||
*/
|
||||
fun emit()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,38 +0,0 @@
|
||||
package world.phantasmal.cell
|
||||
|
||||
import world.phantasmal.cell.test.CellTestSuite
|
||||
import kotlin.test.*
|
||||
|
||||
interface DependencyTests : CellTestSuite {
|
||||
fun createProvider(): Provider
|
||||
|
||||
@Test
|
||||
fun correctly_emits_invalidation_notifications_to_its_dependents() = test {
|
||||
val p = createProvider()
|
||||
var dependencyInvalidatedCalled: Boolean
|
||||
|
||||
p.dependency.addDependent(object : Dependent {
|
||||
override fun dependencyInvalidated(dependency: Dependency<*>) {
|
||||
assertEquals(p.dependency, dependency)
|
||||
dependencyInvalidatedCalled = true
|
||||
}
|
||||
})
|
||||
|
||||
repeat(5) { index ->
|
||||
dependencyInvalidatedCalled = false
|
||||
|
||||
p.emit()
|
||||
|
||||
assertTrue(dependencyInvalidatedCalled, "repetition $index")
|
||||
}
|
||||
}
|
||||
|
||||
interface Provider {
|
||||
val dependency: Dependency<*>
|
||||
|
||||
/**
|
||||
* Makes [dependency] call [Dependent.dependencyInvalidated] on its dependents.
|
||||
*/
|
||||
fun emit()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user