forked from VsVim/VsVim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
KeyUtilTest.cs
153 lines (141 loc) · 5.95 KB
/
KeyUtilTest.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
using System;
using System.Collections.Generic;
using System.Windows.Input;
using NUnit.Framework;
namespace Vim.UI.Wpf.Test
{
[TestFixture]
public class KeyUtilTest
{
private void KeyToKeyInput(char c, Key key)
{
KeyToKeyInput(c, key, ModifierKeys.None);
}
private KeyInput ConvertToKeyInput(Key key)
{
return ConvertToKeyInput(key, ModifierKeys.None);
}
private KeyInput ConvertToKeyInput(Key key, ModifierKeys modKeys)
{
KeyInput ki;
Assert.IsTrue(KeyUtil.TryConvertToKeyInput(key, modKeys, out ki));
return ki;
}
private void KeyToKeyInput(char c, Key key, ModifierKeys mod)
{
var left = KeyInputUtil.CharToKeyInput(c);
KeyInput right;
Assert.IsTrue(KeyUtil.TryConvertToKeyInput(key, mod, out right));
Assert.AreEqual(left, right);
}
private void WellKnownBothWays(VimKey wellKnownKey, Key key)
{
var left = KeyInputUtil.VimKeyToKeyInput(wellKnownKey);
KeyInput right;
Assert.IsTrue(KeyUtil.TryConvertToKeyInput(key, out right));
Assert.AreEqual(left, right);
}
[Test]
public void KeyToKeyInput()
{
KeyToKeyInput(' ', Key.Space);
KeyToKeyInput(';', Key.OemSemicolon);
KeyToKeyInput(':', Key.OemSemicolon, ModifierKeys.Shift);
KeyToKeyInput('/', Key.Oem2);
KeyToKeyInput('?', Key.Oem2, ModifierKeys.Shift);
KeyToKeyInput('.', Key.OemPeriod);
KeyToKeyInput('>', Key.OemPeriod, ModifierKeys.Shift);
KeyToKeyInput(',', Key.OemComma);
KeyToKeyInput('<', Key.OemComma, ModifierKeys.Shift);
KeyToKeyInput('[', Key.OemOpenBrackets);
KeyToKeyInput('{', Key.OemOpenBrackets, ModifierKeys.Shift);
KeyToKeyInput(']', Key.OemCloseBrackets);
KeyToKeyInput('}', Key.OemCloseBrackets, ModifierKeys.Shift);
KeyToKeyInput('\b', Key.Back);
KeyToKeyInput('\t', Key.Tab);
KeyToKeyInput('-', Key.OemMinus);
KeyToKeyInput('=', Key.OemPlus);
KeyToKeyInput('+', Key.OemPlus, ModifierKeys.Shift);
KeyToKeyInput('~', Key.OemTilde, ModifierKeys.Shift);
}
[Test]
public void WellKnownBothWays()
{
WellKnownBothWays(VimKey.Left, Key.Left);
WellKnownBothWays(VimKey.Right, Key.Right);
WellKnownBothWays(VimKey.Up, Key.Up);
WellKnownBothWays(VimKey.Down, Key.Down);
WellKnownBothWays(VimKey.F1, Key.F1);
WellKnownBothWays(VimKey.F2, Key.F2);
WellKnownBothWays(VimKey.F3, Key.F3);
WellKnownBothWays(VimKey.F4, Key.F4);
WellKnownBothWays(VimKey.F5, Key.F5);
WellKnownBothWays(VimKey.F6, Key.F6);
WellKnownBothWays(VimKey.F7, Key.F7);
WellKnownBothWays(VimKey.F8, Key.F8);
WellKnownBothWays(VimKey.F9, Key.F9);
WellKnownBothWays(VimKey.F10, Key.F10);
WellKnownBothWays(VimKey.F11, Key.F11);
WellKnownBothWays(VimKey.F12, Key.F12);
WellKnownBothWays(VimKey.Delete, Key.Delete);
WellKnownBothWays(VimKey.Escape, Key.Escape);
WellKnownBothWays(VimKey.KeypadMultiply, Key.Multiply);
WellKnownBothWays(VimKey.KeypadPlus, Key.Add);
WellKnownBothWays(VimKey.KeypadMinus, Key.Subtract);
WellKnownBothWays(VimKey.KeypadDecimal, Key.Decimal);
WellKnownBothWays(VimKey.KeypadDivide, Key.Divide);
WellKnownBothWays(VimKey.Keypad0, Key.NumPad0);
WellKnownBothWays(VimKey.Keypad1, Key.NumPad1);
WellKnownBothWays(VimKey.Keypad2, Key.NumPad2);
WellKnownBothWays(VimKey.Keypad3, Key.NumPad3);
WellKnownBothWays(VimKey.Keypad4, Key.NumPad4);
WellKnownBothWays(VimKey.Keypad5, Key.NumPad5);
WellKnownBothWays(VimKey.Keypad6, Key.NumPad6);
WellKnownBothWays(VimKey.Keypad7, Key.NumPad7);
WellKnownBothWays(VimKey.Keypad8, Key.NumPad8);
WellKnownBothWays(VimKey.Keypad9, Key.NumPad9);
}
[Test]
public void ConvertToKeyInput1()
{
var ki = ConvertToKeyInput(Key.A, ModifierKeys.Shift);
Assert.AreEqual('A', ki.Char);
Assert.AreEqual(KeyModifiers.Shift, ki.KeyModifiers);
}
[Test]
public void ConvertToKeyInput2()
{
var ki = ConvertToKeyInput(Key.A, ModifierKeys.None);
Assert.AreEqual('a', ki.Char);
Assert.AreEqual(KeyModifiers.None, ki.KeyModifiers);
}
[Test]
public void ConvertToKeyInput3()
{
var ki = ConvertToKeyInput(Key.A, ModifierKeys.Control);
Assert.AreEqual('a', ki.Char);
Assert.AreEqual(KeyModifiers.Control, ki.KeyModifiers);
}
[Test]
public void ConvertToKeyInput4()
{
var list = new List<Tuple<char, Key>>() {
Tuple.Create('1', Key.D1),
Tuple.Create('2', Key.D2),
Tuple.Create('3', Key.D3) };
foreach (var tuple in list)
{
var ki = ConvertToKeyInput(tuple.Item2, ModifierKeys.None);
Assert.AreEqual(tuple.Item1, ki.Char);
Assert.AreEqual(KeyModifiers.None, ki.KeyModifiers);
}
}
[Test]
public void ConvertToKeyInput5()
{
var ki = ConvertToKeyInput(Key.F12, ModifierKeys.Shift | ModifierKeys.Control);
Assert.AreEqual(VimKey.F12, ki.Key);
Assert.AreEqual(KeyModifiers.Shift | KeyModifiers.Control, ki.KeyModifiers);
}
}
}