From 4995b16c43f4a6f364a1ad693ef7dc2e842fb28c Mon Sep 17 00:00:00 2001 From: Igor Kravchenko Date: Thu, 1 Oct 2020 19:52:08 +0300 Subject: [PATCH] add test for calling changeState with same name twice --- Tests/FirebladeECSTests/FSMTests.swift | 17 +++++++++++++++-- Tests/FirebladeECSTests/XCTestManifests.swift | 1 + 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Tests/FirebladeECSTests/FSMTests.swift b/Tests/FirebladeECSTests/FSMTests.swift index 5d6fa3a..1d3cc86 100644 --- a/Tests/FirebladeECSTests/FSMTests.swift +++ b/Tests/FirebladeECSTests/FSMTests.swift @@ -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 diff --git a/Tests/FirebladeECSTests/XCTestManifests.swift b/Tests/FirebladeECSTests/XCTestManifests.swift index 2e7526c..1613cc8 100644 --- a/Tests/FirebladeECSTests/XCTestManifests.swift +++ b/Tests/FirebladeECSTests/XCTestManifests.swift @@ -96,6 +96,7 @@ extension EntityStateMachineTests { // `swift test --generate-linuxmain` // to regenerate. static let __allTests__EntityStateMachineTests = [ + ("testCallChangeStateWithSameNameLeavesEntityComponentsIntact", testCallChangeStateWithSameNameLeavesEntityComponentsIntact), ("testCreateStateAddsState", testCreateStateAddsState), ("testCreateStateDoesNotChangeState", testCreateStateDoesNotChangeState), ("testEnterSecondStateAddsSecondStatesComponents", testEnterSecondStateAddsSecondStatesComponents),