Skip to content

Commit ca4c908

Browse files
Add new test case that passes even though I wouldn't expect it to.
1 parent 7836085 commit ca4c908

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

Assets/Tests/InputSystem/CoreTests_ActionsPriority.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,44 @@ public void Actions_Priority_OnlyOneActionIsPerformed_WhenOnePriorityIsHigherTha
176176
Assert.That(action2.WasPerformedThisFrame(), Is.False);
177177
}
178178

179+
[Test]
180+
[Category("Actions Priority")]
181+
[TestCaseSource(nameof(TwoInputActionTestCases))] // TODO: Darren, Should both actions be performed this frame here??
182+
public void Actions_Priority_BothActionsArePerformed_DueToKeyPressOrderForShortcut(TwoInputActionDataWrapper<InputAction, InputAction> twoInputActions)
183+
{
184+
InputSystem.settings.shortcutKeysConsumeInput = true;
185+
var keyboard = InputSystem.AddDevice<Keyboard>();
186+
187+
// We swap the order here of Action1 & Action2 so key presses are done backwards, binding before modifiers.
188+
// This causes the opposite keys foreach test case inside TwoInputActionTestCases to be pressed first.
189+
var action1 = twoInputActions.Action2;
190+
var action2 = twoInputActions.Action1;
191+
192+
// Event though the priority is higher for action2 here, due to the order of the keys being pressed only Action1 will be fired.
193+
action1.Priority = 1;
194+
action2.Priority = 2;
195+
196+
action1.m_ActionMap.Enable();
197+
198+
Assert.That(action1.WasPerformedThisFrame(), Is.False);
199+
Assert.That(action2.WasPerformedThisFrame(), Is.False);
200+
201+
PressBindingsForInputActions(keyboard, action1, action2);
202+
203+
// action1 is performed because action1 has a higher priority than action2.
204+
Assert.That(action1.WasPerformedThisFrame(), Is.True);
205+
Assert.That(action2.WasPerformedThisFrame(), Is.True);
206+
207+
// Cleanup key presses
208+
ReleaseBindingsForActions(keyboard, action1, action2);
209+
210+
// Update again to be sure released is true.
211+
InputSystem.Update();
212+
213+
Assert.That(action1.WasPerformedThisFrame(), Is.False);
214+
Assert.That(action2.WasPerformedThisFrame(), Is.False);
215+
}
216+
179217
[Test]
180218
[Category("Actions Priority")]
181219
[TestCaseSource(nameof(TwoInputActionTestCases))]

0 commit comments

Comments
 (0)