forked from VsVim/VsVim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
KeyboardMapTest.cs
83 lines (72 loc) · 2.16 KB
/
KeyboardMapTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using System;
using System.Windows.Input;
using NUnit.Framework;
namespace Vim.UI.Wpf.Test
{
[TestFixture]
public class KeyboardMapTest
{
private IntPtr _customId;
private KeyboardMap _map;
[SetUp]
public void Setup()
{
Setup(null);
}
public void Setup(string id)
{
if (String.IsNullOrEmpty(id))
{
_customId = IntPtr.Zero;
_map = new KeyboardMap(NativeMethods.GetKeyboardLayout(0));
}
else
{
_customId = NativeMethods.LoadKeyboardLayout(id, 0);
Assert.AreNotEqual(IntPtr.Zero, _customId);
_map = new KeyboardMap(_customId);
}
}
[TearDown]
public void TearDown()
{
if (_customId != IntPtr.Zero)
{
NativeMethods.UnloadKeyboardLayout(_customId);
}
}
private KeyInput GetKeyInput(Key key)
{
KeyInput ki;
Assert.IsTrue(_map.TryGetKeyInput(key, out ki));
return ki;
}
private KeyInput GetKeyInput(Key key, ModifierKeys modKeys)
{
KeyInput ki;
Assert.IsTrue(_map.TryGetKeyInput(key, modKeys, out ki));
return ki;
}
[Test]
public void TryGetKeyInput1()
{
KeyInput ki = GetKeyInput(Key.F12);
Assert.AreEqual(VimKey.F12, ki.Key);
Assert.AreEqual(KeyModifiers.None, ki.KeyModifiers);
}
[Test]
public void TryGetKeyInput2()
{
KeyInput ki = GetKeyInput(Key.F12, ModifierKeys.Shift);
Assert.AreEqual(VimKey.F12, ki.Key);
Assert.AreEqual(KeyModifiers.Shift, ki.KeyModifiers);
}
[Test]
public void TryGetKeyInput3()
{
Setup(NativeMethods.LanguagePortuguese);
KeyInput ki = GetKeyInput(Key.D8, ModifierKeys.Control | ModifierKeys.Alt);
Assert.AreEqual('[', ki.Char);
}
}
}