Skip to content

Commit

Permalink
fix: add test for adding errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jolexxa committed Mar 20, 2024
1 parent 677e733 commit 6ddcfd8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Chickensoft.LogicBlocks.Tests/test/fixtures/FakeLogicBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ public OnExitState(Action<State?> onExit) {
this.OnExit(onExit);
}
}

public record AddErrorOnEnterState : State {
public AddErrorOnEnterState(Exception e) {
this.OnEnter(() => AddError(e));
}
}
}

public static class Output {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ state "FakeLogicBlock State" as Chickensoft_LogicBlocks_Tests_Fixtures_FakeLogic
state "Custom" as Chickensoft_LogicBlocks_Tests_Fixtures_FakeLogicBlock_State_Custom
state "OnEnterState" as Chickensoft_LogicBlocks_Tests_Fixtures_FakeLogicBlock_State_OnEnterState
state "OnExitState" as Chickensoft_LogicBlocks_Tests_Fixtures_FakeLogicBlock_State_OnExitState
state "AddErrorOnEnterState" as Chickensoft_LogicBlocks_Tests_Fixtures_FakeLogicBlock_State_AddErrorOnEnterState
Chickensoft_LogicBlocks_Tests_Fixtures_FakeLogicBlock_State : OnInputOneOutputOne
Chickensoft_LogicBlocks_Tests_Fixtures_FakeLogicBlock_State : OnInputTwoOutputTwo
Chickensoft_LogicBlocks_Tests_Fixtures_FakeLogicBlock_State : OnNoNewStateOutputOne
Expand Down
11 changes: 11 additions & 0 deletions Chickensoft.LogicBlocks.Tests/test/src/LogicBlockTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -511,4 +511,15 @@ public void ForceResetChangesStateAndProcessesInputs() {

state.ShouldBeOfType<FakeLogicBlock.State.StateB>();
}

[Fact]
public void AddsErrorToItself() {
var e = new InvalidOperationException();
var state = new FakeLogicBlock.State.AddErrorOnEnterState(e);

var context = state.CreateFakeContext();
state.Enter();

context.Errors.ShouldBe([e]);
}
}

0 comments on commit 6ddcfd8

Please sign in to comment.