Skip to content

Commit

Permalink
Tweak: clarity to TransitionerTest (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
Synesso authored May 7, 2024
1 parent 9f40882 commit e5f529c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
22 changes: 11 additions & 11 deletions lib-arrow/src/test/kotlin/app/cash/kfsm/TransitionerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class TransitionerTest : StringSpec({
}

"effects valid transition" {
val transition = transition()
val transition = transition(from = A, to = B)
val transitioner = transitioner()

transitioner.transition(Letter(A), transition) shouldBeRight Letter(B)
Expand All @@ -47,7 +47,7 @@ class TransitionerTest : StringSpec({
}

"ignores completed transition" {
val transition = transition()
val transition = transition(from = A, to = B)
val transitioner = transitioner()

transitioner.transition(Letter(B), transition) shouldBeRight Letter(B)
Expand All @@ -58,7 +58,7 @@ class TransitionerTest : StringSpec({
}

"returns error on invalid transition" {
val transition = transition()
val transition = transition(from = A, to = B)
val transitioner = transitioner()

transitioner.transition(Letter(C), transition).shouldBeLeft()
Expand All @@ -72,7 +72,7 @@ class TransitionerTest : StringSpec({
"returns error when preHook errors" {
val error = RuntimeException("preHook error")

val transition = transition()
val transition = transition(from = A, to = B)
val transitioner = transitioner(pre = { _, _ -> error.left() })

transitioner.transition(Letter(A), transition) shouldBeLeft error
Expand All @@ -99,7 +99,7 @@ class TransitionerTest : StringSpec({
"returns error when postHook errors" {
val error = RuntimeException("postHook error")

val transition = transition()
val transition = transition(from = A, to = B)
val transitioner = transitioner(post = { _, _, _ -> error.left() })

transitioner.transition(Letter(A), transition) shouldBeLeft error
Expand All @@ -112,7 +112,7 @@ class TransitionerTest : StringSpec({
"returns error when preHook throws" {
val error = RuntimeException("preHook error")

val transition = transition()
val transition = transition(from = A, to = B)
val transitioner = transitioner(pre = { _, _ -> throw error })

transitioner.transition(Letter(A), transition) shouldBeLeft error
Expand All @@ -138,7 +138,7 @@ class TransitionerTest : StringSpec({
"returns error when postHook throws" {
val error = RuntimeException("postHook error")

val transition = transition()
val transition = transition(from = A, to = B)
val transitioner = transitioner(post = { _, _, _ -> throw error })

transitioner.transition(Letter(A), transition) shouldBeLeft error
Expand All @@ -150,7 +150,7 @@ class TransitionerTest : StringSpec({
"returns error when persist fails" {
val error = RuntimeException("persist error")

val transition = transition()
val transition = transition(from = A, to = B)
val transitioner = transitioner(persist = { error.left() })

transitioner.transition(Letter(A), transition) shouldBeLeft error
Expand All @@ -163,7 +163,7 @@ class TransitionerTest : StringSpec({
"returns error when persist throws" {
val error = RuntimeException("persist error")

val transition = transition()
val transition = transition(from = A, to = B)
val transitioner = transitioner(persist = { throw error })

transitioner.transition(Letter(A), transition) shouldBeLeft error
Expand Down Expand Up @@ -259,7 +259,7 @@ class TransitionerTest : StringSpec({
}

"pre hook contains the correct from value and transition" {
val transition = transition()
val transition = transition(from = A, to = B)
val transitioner = transitioner(
pre = { value, t ->
value shouldBe Letter(A)
Expand All @@ -275,7 +275,7 @@ class TransitionerTest : StringSpec({
"post hook contains the correct from state, post value and transition" {
val transition = transition(from = B, to = C)
val transitioner = transitioner(
post = { from, value, t->
post = { from, value, t ->
from shouldBe B
value shouldBe Letter(C)
t shouldBe transition
Expand Down
22 changes: 11 additions & 11 deletions lib/src/test/kotlin/app/cash/kfsm/TransitionerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class TransitionerTest : StringSpec({
}

"effects valid transition" {
val transition = transition()
val transition = transition(from = A, to = B)
val transitioner = transitioner()

transitioner.transition(Letter(A), transition) shouldBeSuccess Letter(B)
Expand All @@ -43,7 +43,7 @@ class TransitionerTest : StringSpec({
}

"ignores completed transition" {
val transition = transition()
val transition = transition(from = A, to = B)
val transitioner = transitioner()

transitioner.transition(Letter(B), transition) shouldBeSuccess Letter(B)
Expand All @@ -54,7 +54,7 @@ class TransitionerTest : StringSpec({
}

"returns error on invalid transition" {
val transition = transition()
val transition = transition(from = A, to = B)
val transitioner = transitioner()

transitioner.transition(Letter(C), transition).shouldBeFailure()
Expand All @@ -68,7 +68,7 @@ class TransitionerTest : StringSpec({
"returns error when preHook errors" {
val error = RuntimeException("preHook error")

val transition = transition()
val transition = transition(from = A, to = B)
val transitioner = transitioner(pre = { _, _ -> Result.failure(error) })

transitioner.transition(Letter(A), transition) shouldBeFailure error
Expand All @@ -95,7 +95,7 @@ class TransitionerTest : StringSpec({
"returns error when postHook errors" {
val error = RuntimeException("postHook error")

val transition = transition()
val transition = transition(from = A, to = B)
val transitioner = transitioner(post = { _, _, _ -> Result.failure(error) })

transitioner.transition(Letter(A), transition) shouldBeFailure error
Expand All @@ -108,7 +108,7 @@ class TransitionerTest : StringSpec({
"returns error when preHook throws" {
val error = RuntimeException("preHook error")

val transition = transition()
val transition = transition(from = A, to = B)
val transitioner = transitioner(pre = { _, _ -> throw error })

transitioner.transition(Letter(A), transition) shouldBeFailure error
Expand All @@ -134,7 +134,7 @@ class TransitionerTest : StringSpec({
"returns error when postHook throws" {
val error = RuntimeException("postHook error")

val transition = transition()
val transition = transition(from = A, to = B)
val transitioner = transitioner(post = { _, _, _ -> throw error })

transitioner.transition(Letter(A), transition) shouldBeFailure error
Expand All @@ -146,7 +146,7 @@ class TransitionerTest : StringSpec({
"returns error when persist fails" {
val error = RuntimeException("persist error")

val transition = transition()
val transition = transition(from = A, to = B)
val transitioner = transitioner(persist = { Result.failure(error) })

transitioner.transition(Letter(A), transition) shouldBeFailure error
Expand All @@ -159,7 +159,7 @@ class TransitionerTest : StringSpec({
"returns error when persist throws" {
val error = RuntimeException("persist error")

val transition = transition()
val transition = transition(from = A, to = B)
val transitioner = transitioner(persist = { throw error })

transitioner.transition(Letter(A), transition) shouldBeFailure error
Expand Down Expand Up @@ -255,7 +255,7 @@ class TransitionerTest : StringSpec({
}

"pre hook contains the correct from value and transition" {
val transition = transition()
val transition = transition(from = A, to = B)
val transitioner = transitioner(
pre = { value, t ->
value shouldBe Letter(A)
Expand All @@ -271,7 +271,7 @@ class TransitionerTest : StringSpec({
"post hook contains the correct from state, post value and transition" {
val transition = transition(from = B, to = C)
val transitioner = transitioner(
post = { from, value, t->
post = { from, value, t ->
from shouldBe B
value shouldBe Letter(C)
t shouldBe transition
Expand Down

0 comments on commit e5f529c

Please sign in to comment.