forked from VsVim/VsVim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BlockCaretControllerTest.cs
180 lines (159 loc) · 6.65 KB
/
BlockCaretControllerTest.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
using Microsoft.VisualStudio.Text.Editor;
using Moq;
using NUnit.Framework;
using Vim.UnitTest.Mock;
namespace Vim.UI.Wpf.Test
{
[TestFixture]
class BlockCaretControllerTest
{
private Mock<ITextView> _view;
private Mock<IVimBuffer> _buffer;
private Mock<IBlockCaret> _caret;
private MockVimLocalSettings _localSettings;
private MockVimGlobalSettings _settings;
private BlockCaretController _controller;
[SetUp]
public void SetUp()
{
_view = new Mock<ITextView>();
_settings = new MockVimGlobalSettings();
_localSettings = new MockVimLocalSettings() { GlobalSettingsImpl = _settings };
_buffer = new Mock<IVimBuffer>();
_buffer.SetupGet(x => x.ModeKind).Returns(ModeKind.Command);
_buffer.SetupGet(x => x.TextView).Returns(_view.Object);
_buffer.SetupGet(x => x.Settings).Returns(_localSettings);
_caret = new Mock<IBlockCaret>(MockBehavior.Strict);
_caret.SetupSet(x => x.CaretDisplay = CaretDisplay.Invisible);
_caret.SetupSet(x => x.CaretOpacity = _settings.CaretOpacity);
_controller = new BlockCaretController(_buffer.Object, _caret.Object);
}
[Test]
public void OperatorPending1()
{
var mode = new Mock<INormalMode>();
mode.SetupGet(x => x.IsOperatorPending).Returns(true).Verifiable();
_buffer.SetupGet(x => x.NormalMode).Returns(mode.Object);
_buffer.SetupGet(x => x.ModeKind).Returns(ModeKind.Normal);
_caret.SetupSet(x => x.CaretDisplay = CaretDisplay.HalfBlock).Verifiable();
_controller.Update();
_caret.Verify();
}
[Test, Description("Other modes shouldn't even consider operator pending")]
public void OperaterPending2()
{
var mode = new Mock<INormalMode>();
mode.SetupGet(x => x.IsOperatorPending).Returns(true).Verifiable();
_buffer.SetupGet(x => x.NormalMode).Returns(mode.Object);
_buffer.SetupGet(x => x.ModeKind).Returns(ModeKind.Command);
_caret.SetupSet(x => x.CaretDisplay = CaretDisplay.Invisible).Verifiable();
_controller.Update();
_caret.Verify();
}
[Test]
public void IsInReplace1()
{
var mode = new Mock<INormalMode>();
mode.SetupGet(x => x.IsInReplace).Returns(true);
_buffer.SetupGet(x => x.NormalMode).Returns(mode.Object);
_buffer.SetupGet(x => x.ModeKind).Returns(ModeKind.Normal);
_caret.SetupSet(x => x.CaretDisplay = CaretDisplay.QuarterBlock).Verifiable();
_controller.Update();
_caret.Verify();
}
[Test, Description("Replace wins over operator pending")]
public void IsInReplace2()
{
var mode = new Mock<INormalMode>();
mode.SetupGet(x => x.IsInReplace).Returns(true);
mode.SetupGet(x => x.IsOperatorPending).Returns(true);
_buffer.SetupGet(x => x.NormalMode).Returns(mode.Object);
_buffer.SetupGet(x => x.ModeKind).Returns(ModeKind.Normal);
_caret.SetupSet(x => x.CaretDisplay = CaretDisplay.QuarterBlock).Verifiable();
_controller.Update();
_caret.Verify();
}
[Test]
public void NormalMode1()
{
var mode = new Mock<INormalMode>();
var search = new Mock<IIncrementalSearch>();
_buffer.SetupGet(x => x.NormalMode).Returns(mode.Object);
_buffer.SetupGet(x => x.ModeKind).Returns(ModeKind.Normal);
mode.SetupGet(x => x.IncrementalSearch).Returns(search.Object);
_caret.SetupSet(x => x.CaretDisplay = CaretDisplay.Block).Verifiable();
_controller.Update();
_caret.Verify();
}
[Test]
public void NormalMode2()
{
var mode = new Mock<INormalMode>();
var search = new Mock<IIncrementalSearch>();
_buffer.SetupGet(x => x.NormalMode).Returns(mode.Object);
_buffer.SetupGet(x => x.ModeKind).Returns(ModeKind.Normal);
mode.SetupGet(x => x.IncrementalSearch).Returns(search.Object);
search.SetupGet(x => x.InSearch).Returns(true);
_caret.SetupSet(x => x.CaretDisplay = CaretDisplay.Invisible).Verifiable();
_controller.Update();
_caret.Verify();
}
[Test]
public void CommandMode1()
{
_buffer.SetupGet(x => x.ModeKind).Returns(ModeKind.Command);
_caret.SetupSet(x => x.CaretDisplay = CaretDisplay.Invisible);
_controller.Update();
}
[Test]
public void DisabledMode1()
{
_buffer.SetupGet(x => x.ModeKind).Returns(ModeKind.Disabled);
_caret.SetupSet(x => x.CaretDisplay = CaretDisplay.NormalCaret);
_controller.Update();
}
[Test]
public void VisualMode1()
{
_buffer.SetupGet(x => x.ModeKind).Returns(ModeKind.VisualBlock);
_caret.SetupSet(x => x.CaretDisplay = CaretDisplay.Block);
_controller.Update();
}
[Test]
public void VisualMode2()
{
_buffer.SetupGet(x => x.ModeKind).Returns(ModeKind.VisualCharacter);
_caret.SetupSet(x => x.CaretDisplay = CaretDisplay.Block);
_controller.Update();
}
[Test]
public void VisualMode3()
{
_buffer.SetupGet(x => x.ModeKind).Returns(ModeKind.VisualLine);
_caret.SetupSet(x => x.CaretDisplay = CaretDisplay.Block);
_controller.Update();
}
[Test]
public void ReplaceMode1()
{
_buffer.SetupGet(x => x.ModeKind).Returns(ModeKind.Replace);
_caret.SetupSet(x => x.CaretDisplay = CaretDisplay.QuarterBlock);
_controller.Update();
}
[Test]
public void CaretOpacity1()
{
_caret.SetupSet(x => x.CaretOpacity = 0.01d).Verifiable();
var setting = new Setting(
GlobalSettingNames.CaretOpacityName,
"",
SettingKind.StringKind,
SettingValue.NewStringValue(""),
SettingValue.NewStringValue(""),
true);
_settings.CaretOpacity = 1;
_settings.RaiseSettingChanged(setting);
_caret.Verify();
}
}
}