Forge
csharpdeeb25a2
1using Avalonia.Input;
2using CascadeIDE.Services;
3using Xunit;
4
5namespace CascadeIDE.Tests;
6
7public sealed class KeyGestureChordMatchingTests
8{
9 [Fact]
10 public void Matches_CtrlQ_WrongVirtualKey_UsesPhysicalQwertyPosition()
11 {
12 var gesture = KeyGesture.Parse("Ctrl+Q");
13 var e = new KeyEventArgs
14 {
15 RoutedEvent = InputElement.KeyDownEvent,
16 Key = Key.W,
17 KeyModifiers = KeyModifiers.Control,
18 PhysicalKey = PhysicalKey.Q
19 };
20 Assert.True(KeyGestureChordMatching.Matches(gesture, e));
21 }
22
23 [Fact]
24 public void Matches_CtrlK_WrongVirtualKey_UsesPhysicalQwertyPosition()
25 {
26 var gesture = KeyGesture.Parse("Ctrl+K");
27 var e = new KeyEventArgs
28 {
29 RoutedEvent = InputElement.KeyDownEvent,
30 Key = Key.A,
31 KeyModifiers = KeyModifiers.Control,
32 PhysicalKey = PhysicalKey.K
33 };
34 Assert.True(KeyGestureChordMatching.Matches(gesture, e));
35 }
36
37 [Fact]
38 public void Matches_StrictFirst_PassesThrough()
39 {
40 var gesture = KeyGesture.Parse("Ctrl+Q");
41 var e = new KeyEventArgs
42 {
43 RoutedEvent = InputElement.KeyDownEvent,
44 Key = Key.Q,
45 KeyModifiers = KeyModifiers.Control,
46 PhysicalKey = PhysicalKey.Q
47 };
48 Assert.True(KeyGestureChordMatching.Matches(gesture, e));
49 }
50
51 /// <summary>Регрессия: Ctrl+Shift+буква в TOML — жест должен матчиться с реальным KeyDown (mods включают Shift).</summary>
52 [Fact]
53 public void Matches_CtrlShiftO_SyntheticEvent_Matches()
54 {
55 var gesture = KeyGesture.Parse("Ctrl+Shift+O");
56 var e = new KeyEventArgs
57 {
58 RoutedEvent = InputElement.KeyDownEvent,
59 Key = Key.O,
60 KeyModifiers = KeyModifiers.Control | KeyModifiers.Shift,
61 PhysicalKey = PhysicalKey.O
62 };
63 Assert.True(KeyGestureChordMatching.Matches(gesture, e));
64 }
65
66}
67
View only · write via MCP/CIDE