Skip to content

Commit e5bc6fb

Browse files
committed
operator invoke
1 parent c565534 commit e5bc6fb

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/main/kotlin/dsl/FsmSpec.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,9 @@ class FsmSpec(
1717
state = State(initialState)
1818
)
1919
}
20+
21+
operator fun invoke(block: FsmSpec.() -> Unit): Fsm {
22+
block()
23+
return build()
24+
}
2025
}

src/test/kotlin/dsl/FsmTest.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,19 @@ class FsmTest : BehaviorSpec({
1818
}
1919
}
2020
}
21+
22+
given("2222") {
23+
`when`("I sit on it") {
24+
val fsmSpec = FsmSpec(initialState = "locked")
25+
val fsm = fsmSpec {
26+
add { this on "coin" from "locked" into "unlocked" }
27+
add { this on "pass" from "unlocked" into "locked" }
28+
}
29+
30+
then("I should be able to fly") {
31+
fsm.initial shouldBe State("locked")
32+
fsm.transitions shouldHave haveSize(2)
33+
}
34+
}
35+
}
2136
})

0 commit comments

Comments
 (0)