| 1 | using CascadeIDE.Services.ChordNotation; |
| 2 | using Xunit; |
| 3 | |
| 4 | namespace CascadeIDE.Tests; |
| 5 | |
| 6 | public sealed class ChordNotationSemanticTests |
| 7 | { |
| 8 | [Fact] |
| 9 | public void Vim_and_KeyGesture_normalize_to_same_sequence_for_equivalent_chords() |
| 10 | { |
| 11 | Assert.True(ChordNotationParser.TryParseVimToNormalized("<C-k> s p", out var vim, out _)); |
| 12 | Assert.True(KeyGestureChordSyntax.TryParseToNormalized("Ctrl+K s p", out var kg, out _)); |
| 13 | Assert.NotNull(vim); |
| 14 | Assert.NotNull(kg); |
| 15 | Assert.Equal(3, vim!.Steps.Count); |
| 16 | Assert.Equal(vim.Steps.Count, kg!.Steps.Count); |
| 17 | AssertNormalizedChord(vim.Steps[0], ChordModifierKeys.Control, "K"); |
| 18 | AssertNormalizedChord(kg.Steps[0], ChordModifierKeys.Control, "K"); |
| 19 | AssertNormalizedPlain(vim.Steps[1], "S"); |
| 20 | AssertNormalizedPlain(kg.Steps[1], "S"); |
| 21 | AssertNormalizedPlain(vim.Steps[2], "P"); |
| 22 | AssertNormalizedPlain(kg.Steps[2], "P"); |
| 23 | } |
| 24 | |
| 25 | [Fact] |
| 26 | public void KeyGesture_Ctrl_Shift_P_and_unicode_command_key() |
| 27 | { |
| 28 | Assert.True(KeyGestureChordSyntax.TryParseToNormalized("Ctrl + Shift + P", out var a, out _)); |
| 29 | Assert.NotNull(a); |
| 30 | Assert.Single(a!.Steps); |
| 31 | var ch = Assert.IsType<NormalizedChordStep>(a.Steps[0]); |
| 32 | Assert.Equal(ChordModifierKeys.Control | ChordModifierKeys.Shift, ch.Modifiers); |
| 33 | Assert.Equal("P", ch.KeySymbol); |
| 34 | |
| 35 | Assert.True(KeyGestureChordSyntax.TryParseToNormalized("\u2318K", out var b, out _)); |
| 36 | var ch2 = Assert.IsType<NormalizedChordStep>(b!.Steps[0]); |
| 37 | Assert.Equal(ChordModifierKeys.Meta, ch2.Modifiers); |
| 38 | Assert.Equal("K", ch2.KeySymbol); |
| 39 | } |
| 40 | |
| 41 | [Fact] |
| 42 | public void KeyGesture_sequence_two_chords() |
| 43 | { |
| 44 | Assert.True(KeyGestureChordSyntax.TryParseToNormalized("Ctrl+K Ctrl+C", out var s, out _)); |
| 45 | Assert.NotNull(s); |
| 46 | Assert.Equal(2, s!.Steps.Count); |
| 47 | AssertNormalizedChord(s.Steps[0], ChordModifierKeys.Control, "K"); |
| 48 | AssertNormalizedChord(s.Steps[1], ChordModifierKeys.Control, "C"); |
| 49 | } |
| 50 | |
| 51 | private static void AssertNormalizedChord(NormalizedSequenceStep step, ChordModifierKeys mods, string key) |
| 52 | { |
| 53 | var c = Assert.IsType<NormalizedChordStep>(step); |
| 54 | Assert.Equal(mods, c.Modifiers); |
| 55 | Assert.Equal(key, c.KeySymbol); |
| 56 | } |
| 57 | |
| 58 | private static void AssertNormalizedPlain(NormalizedSequenceStep step, string key) |
| 59 | { |
| 60 | var p = Assert.IsType<NormalizedPlainKeyStep>(step); |
| 61 | Assert.Equal(key, p.KeySymbol); |
| 62 | } |
| 63 | } |
| 64 | |