diff --git a/Keybinding.Test/ParsePhraseEmptyInputTests.cs b/Keybinding.Test/ParsePhraseEmptyInputTests.cs new file mode 100644 index 0000000..a67fb56 --- /dev/null +++ b/Keybinding.Test/ParsePhraseEmptyInputTests.cs @@ -0,0 +1,21 @@ +// Copyright (c) 2023-2026 ktsu-dev contributors + +namespace ktsu.Keybinding.Test; + +using ktsu.Keybinding.Core.Services; + +[TestClass] +public class ParsePhraseEmptyInputTests +{ + [TestMethod] + [DataRow("")] + [DataRow(" ")] + [DataRow(null)] + public void ParsePhrase_BlankInput_ThrowsNamingPhraseString(string? phraseString) + { + KeybindingService service = new(new CommandRegistry(), new ProfileManager()); + + ArgumentException ex = Assert.ThrowsExactly(() => service.ParsePhrase(phraseString!)); + Assert.AreEqual("phraseString", ex.ParamName, "The exception should name the caller's argument, not the Phrase constructor's."); + } +} diff --git a/Keybinding/Contracts/IKeybindingService.cs b/Keybinding/Contracts/IKeybindingService.cs index a7782e3..4f1431b 100644 --- a/Keybinding/Contracts/IKeybindingService.cs +++ b/Keybinding/Contracts/IKeybindingService.cs @@ -128,6 +128,7 @@ public interface IKeybindingService /// /// The phrase string to parse /// Phrase containing the sequence of chords + /// Thrown when phraseString is null or whitespace public Phrase ParsePhrase(string phraseString); /// diff --git a/Keybinding/Services/KeybindingService.cs b/Keybinding/Services/KeybindingService.cs index d73f78f..fc6c7e9 100644 --- a/Keybinding/Services/KeybindingService.cs +++ b/Keybinding/Services/KeybindingService.cs @@ -179,7 +179,7 @@ public Phrase ParsePhrase(string phraseString) { if (string.IsNullOrWhiteSpace(phraseString)) { - return new Phrase([]); + throw new ArgumentException("Phrase string cannot be null or whitespace", nameof(phraseString)); } // Split by comma to get individual chord strings