From 3aae07d1caa8242efd4a0318c6e705ebfc5c99ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Mon, 16 Oct 2023 21:28:11 +0200 Subject: [PATCH] Add failing case for two bindings of single action bound to same key --- .../Input/RealmKeyBindingStoreTest.cs | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/osu.Game.Tests/Input/RealmKeyBindingStoreTest.cs b/osu.Game.Tests/Input/RealmKeyBindingStoreTest.cs index a0c1b20cd7..ce31a9ea9d 100644 --- a/osu.Game.Tests/Input/RealmKeyBindingStoreTest.cs +++ b/osu.Game.Tests/Input/RealmKeyBindingStoreTest.cs @@ -86,5 +86,32 @@ namespace osu.Game.Tests.Input Assert.That(bindings[6].KeyCombination, Is.EqualTo(new KeyCombination(InputKey.PrintScreen))); }); } + + [Test] + public void TestDuplicateBindingsAllowedIfBoundToSameAction() + { + var bindings = new List + { + new RealmKeyBinding(GlobalAction.Back, KeyCombination.FromKey(Key.Escape)), + new RealmKeyBinding(GlobalAction.Back, KeyCombination.FromKey(Key.Escape)), + new RealmKeyBinding(GlobalAction.MusicPrev, KeyCombination.FromKey(Key.F1)), + }; + + int countCleared = RealmKeyBindingStore.ClearDuplicateBindings(bindings); + + Assert.Multiple(() => + { + Assert.That(countCleared, Is.EqualTo(0)); + + Assert.That(bindings[0].Action, Is.EqualTo((int)GlobalAction.Back)); + Assert.That(bindings[0].KeyCombination, Is.EqualTo(new KeyCombination(InputKey.Escape))); + + Assert.That(bindings[1].Action, Is.EqualTo((int)GlobalAction.Back)); + Assert.That(bindings[1].KeyCombination, Is.EqualTo(new KeyCombination(InputKey.Escape))); + + Assert.That(bindings[2].Action, Is.EqualTo((int)GlobalAction.MusicPrev)); + Assert.That(bindings[2].KeyCombination, Is.EqualTo(new KeyCombination(InputKey.F1))); + }); + } } }