Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
renetik committed Jun 13, 2024
1 parent 46950e4 commit 4c2d418
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ interface CSRegistration : CSHasCancel, Closeable {
override fun cancel()

companion object {
val EmptyRegistration = CSRegistration(isActive = false) {}

fun paused(registration: CSRegistration?, function: Func) {
registration?.pause()
function()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,39 @@
package renetik.android.event.registration

import org.junit.Test
import renetik.android.core.lang.variable.increment
import renetik.android.event.CSEvent.Companion.event
import renetik.android.event.invoke
import renetik.android.event.property.CSProperty.Companion.property
import renetik.android.testing.CSAssert.assert

class ListCSHasChangeTest {

@Test
fun listOnChange() {
val property1 = property(1)
val list: List<CSHasChange<*>> = listOf(property1, property(2))
var onChangeFired = 0
val registration = list.onChange { onChangeFired++ }
property1.increment()
assert(expected = 2, actual = property1.value)
assert(expected = 1, actual = onChangeFired)
registration.pause()
property1.increment()
assert(expected = 3, actual = property1.value)
assert(expected = 1, actual = onChangeFired)
registration.resume()
assert(expected = 3, actual = property1.value)
assert(expected = 1, actual = onChangeFired)
}

@Test
fun delegateChild() {
fun listOnChange2() {
val event1 = event()
val event2 = event()
val list: List<CSHasChange<Unit>> = listOf(event1, event2)
var onChangeFired = 0
val registration = list.onChange {
onChangeFired++
}
val registration = list.onChange { onChangeFired++ }
event1()
assert(expected = 1, actual = onChangeFired)
event2()
Expand Down

0 comments on commit 4c2d418

Please sign in to comment.