feat: 初始提交——一键运行快捷轮盘工具(WPF + C#)
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
using OneClickRun.Helpers;
|
||||
using OneClickRun.Models;
|
||||
using Xunit;
|
||||
|
||||
namespace OneClickRun.Tests;
|
||||
|
||||
public class HotkeyFormatTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("Ctrl+Alt+Space")]
|
||||
[InlineData("Ctrl+Shift+F8")]
|
||||
[InlineData("Win+D")]
|
||||
[InlineData("F8")]
|
||||
[InlineData("Alt+F4")]
|
||||
public void FormatAndParseRoundTrip(string text)
|
||||
{
|
||||
var binding = HotkeyFormat.TryParse(text);
|
||||
Assert.NotNull(binding);
|
||||
Assert.Equal(text, HotkeyFormat.Format(binding));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ModifierOrderIsCanonical()
|
||||
{
|
||||
var binding = new HotkeyBinding { Modifiers = { "Alt", "Ctrl", "Shift" }, Key = "Space" };
|
||||
Assert.Equal("Ctrl+Alt+Shift+Space", HotkeyFormat.Format(binding));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseRejectsInvalidInput()
|
||||
{
|
||||
Assert.Null(HotkeyFormat.TryParse("Ctrl")); // 缺少主键
|
||||
Assert.Null(HotkeyFormat.TryParse("Ctrl+Xxx")); // 非法键名
|
||||
Assert.Null(HotkeyFormat.TryParse("Bla+Space")); // 非法修饰键
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EmptyInputReturnsInvalidBinding()
|
||||
{
|
||||
var binding = HotkeyFormat.TryParse(" ");
|
||||
Assert.NotNull(binding);
|
||||
Assert.False(binding.IsValid);
|
||||
Assert.Equal(string.Empty, HotkeyFormat.Format(binding));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VirtualKeyMapping()
|
||||
{
|
||||
Assert.Equal(0x20, HotkeyFormat.VirtualKeyOf("Space")); // VK_SPACE
|
||||
Assert.Equal(0x74, HotkeyFormat.VirtualKeyOf("F5")); // VK_F5
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user