add test for calling changeState with same name twice

This commit is contained in:
Igor Kravchenko 2020-10-01 19:52:08 +03:00
parent 7bd1b3cc82
commit 4995b16c43
2 changed files with 16 additions and 2 deletions

View File

@ -270,8 +270,6 @@ class EntityStateTests: XCTestCase {
XCTAssertTrue(state.has(MockComponent.self))
}
// TODO: continue here
class MockComponent: ComponentInitializable {
let value: Int
@ -401,6 +399,21 @@ class EntityStateMachineTests: XCTestCase {
XCTAssertNil(entity.get(component: MockComponent.self))
}
func testCallChangeStateWithSameNameLeavesEntityComponentsIntact() {
let state = fsm.createState(name: "test")
let component1 = MockComponent()
let component2 = MockComponent2()
state.add(MockComponent.self).withInstance(component1)
state.add(MockComponent2.self).withInstance(component2)
let name = "test"
fsm.changeState(name: name)
XCTAssertTrue(entity.get(component: MockComponent.self) === component1)
XCTAssertTrue(entity.get(component: MockComponent2.self) === component2)
fsm.changeState(name: name)
XCTAssertTrue(entity.get(component: MockComponent.self) === component1)
XCTAssertTrue(entity.get(component: MockComponent2.self) === component2)
}
class MockComponent: ComponentInitializable {
let value: Int

View File

@ -96,6 +96,7 @@ extension EntityStateMachineTests {
// `swift test --generate-linuxmain`
// to regenerate.
static let __allTests__EntityStateMachineTests = [
("testCallChangeStateWithSameNameLeavesEntityComponentsIntact", testCallChangeStateWithSameNameLeavesEntityComponentsIntact),
("testCreateStateAddsState", testCreateStateAddsState),
("testCreateStateDoesNotChangeState", testCreateStateDoesNotChangeState),
("testEnterSecondStateAddsSecondStatesComponents", testEnterSecondStateAddsSecondStatesComponents),