Skip to content

Commit

Permalink
[Test] Reproduce to-AnyState transition bug when event is triggered a…
Browse files Browse the repository at this point in the history
…nd '.AnyState => .AnyState' event-route is registered.
  • Loading branch information
inamiy committed Jul 7, 2015
1 parent f94ff76 commit 5dda47e
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions SwiftStateTests/StateMachineEventTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,31 @@ class StateMachineEventTests: _TestCase
XCTAssertEqual(machine.state, MyState.State0)
}

/// https://github.com/ReactKit/SwiftState/issues/28
func testTryEvent_issue28()
{
var eventCount = 0
let machine = StateMachine<MyState, MyEvent>(state: .State0) { machine in
machine.addRoute(.State0 => .State1)
machine.addRouteEvent(.Event0, transitions: [nil => nil]) { _ in
eventCount++
}
}

XCTAssertEqual(eventCount, 0)

machine <-! .Event0
XCTAssertEqual(eventCount, 1)
XCTAssertEqual(machine.state, MyState.State0, "State should NOT be changed")

machine <- .State1
XCTAssertEqual(machine.state, MyState.State1, "State should be changed")

machine <-! .Event0
XCTAssertEqual(eventCount, 2)
XCTAssertEqual(machine.state, MyState.State1, "State should NOT be changed")
}

func testTryEvent_string()
{
let machine = StateMachine<MyState, String>(state: .State0)
Expand Down

0 comments on commit 5dda47e

Please sign in to comment.