forked from VsVim/VsVim
/
CommonOperationsTest.cs
1323 lines (1206 loc) · 54.5 KB
/
CommonOperationsTest.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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.Linq;
using EditorUtils.UnitTest;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Outlining;
using Moq;
using NUnit.Framework;
using Vim.Extensions;
using Vim.UnitTest.Mock;
namespace Vim.UnitTest
{
// TODO: Need to remove several of the mock's here. No reason to mock IVimLocalSettings and
// a couple others.
[TestFixture]
public sealed class CommonOperationsTest : VimTestBase
{
private ITextView _textView;
private ITextBuffer _textBuffer;
private IFoldManager _foldManager;
private MockRepository _factory;
private Mock<IVimHost> _vimHost;
private Mock<IJumpList> _jumpList;
private Mock<IVimLocalSettings> _localSettings;
private Mock<IVimGlobalSettings> _globalSettings;
private Mock<IOutliningManager> _outlining;
private Mock<IStatusUtil> _statusUtil;
private Mock<ISmartIndentationService> _smartIndentationService;
private Mock<IVimTextBuffer> _vimTextBuffer;
private IUndoRedoOperations _undoRedoOperations;
private ISearchService _searchService;
private IVimData _vimData;
private ICommonOperations _operations;
private CommonOperations _operationsRaw;
private Register UnnamedRegister
{
get { return Vim.RegisterMap.GetRegister(RegisterName.Unnamed); }
}
public void Create(params string[] lines)
{
_textView = CreateTextView(lines);
_textView.Caret.MoveTo(new SnapshotPoint(_textView.TextSnapshot, 0));
_textBuffer = _textView.TextBuffer;
_foldManager = FoldManagerFactory.GetFoldManager(_textView);
_factory = new MockRepository(MockBehavior.Strict);
// Create the Vim instance with our Mock'd services
_vimData = new VimData();
var registerMap = VimUtil.CreateRegisterMap(MockObjectFactory.CreateClipboardDevice(_factory).Object);
_vimHost = _factory.Create<IVimHost>();
_globalSettings = _factory.Create<IVimGlobalSettings>();
_globalSettings.SetupGet(x => x.Magic).Returns(true);
_globalSettings.SetupGet(x => x.SmartCase).Returns(false);
_globalSettings.SetupGet(x => x.IgnoreCase).Returns(true);
_globalSettings.SetupGet(x => x.IsVirtualEditOneMore).Returns(false);
_globalSettings.SetupGet(x => x.UseEditorIndent).Returns(false);
_globalSettings.SetupGet(x => x.UseEditorSettings).Returns(false);
_globalSettings.SetupGet(x => x.VirtualEdit).Returns(String.Empty);
_globalSettings.SetupGet(x => x.WrapScan).Returns(true);
_globalSettings.SetupGet(x => x.ShiftWidth).Returns(2);
_searchService = new SearchService(TextSearchService, _globalSettings.Object);
var vim = MockObjectFactory.CreateVim(
registerMap: registerMap,
host: _vimHost.Object,
settings: _globalSettings.Object,
searchService: _searchService,
factory: _factory);
// Create the IVimTextBuffer instance with our Mock'd services
_localSettings = MockObjectFactory.CreateLocalSettings(_globalSettings.Object, _factory);
_localSettings.SetupGet(x => x.AutoIndent).Returns(false);
_localSettings.SetupGet(x => x.GlobalSettings).Returns(_globalSettings.Object);
_localSettings.SetupGet(x => x.ExpandTab).Returns(true);
_localSettings.SetupGet(x => x.TabStop).Returns(4);
_vimTextBuffer = MockObjectFactory.CreateVimTextBuffer(
_textBuffer,
localSettings: _localSettings.Object,
vim: vim.Object,
factory: _factory);
// Create the VimBufferData instance with our Mock'd services
_jumpList = _factory.Create<IJumpList>();
_statusUtil = _factory.Create<IStatusUtil>();
_undoRedoOperations = VimUtil.CreateUndoRedoOperations(_statusUtil.Object);
var vimBufferData = CreateVimBufferData(
_vimTextBuffer.Object,
_textView,
statusUtil: _statusUtil.Object,
jumpList: _jumpList.Object,
undoRedoOperations: _undoRedoOperations);
_smartIndentationService = _factory.Create<ISmartIndentationService>();
_outlining = _factory.Create<IOutliningManager>();
_outlining
.Setup(x => x.ExpandAll(It.IsAny<SnapshotSpan>(), It.IsAny<Predicate<ICollapsed>>()))
.Returns<IEnumerable<ICollapsible>>(null);
_operationsRaw = new CommonOperations(
vimBufferData,
EditorOperationsFactoryService.GetEditorOperations(_textView),
FSharpOption.Create(_outlining.Object),
_smartIndentationService.Object);
_operations = _operationsRaw;
}
[TearDown]
public void TearDown()
{
_operations = null;
_operationsRaw = null;
}
private static string CreateLinesWithLineBreak(params string[] lines)
{
return lines.Aggregate((x, y) => x + Environment.NewLine + y) + Environment.NewLine;
}
/// <summary>
/// Standard case of deleting several lines in the buffer
/// </summary>
[Test]
public void DeleteLines_Multiple()
{
Create("cat", "dog", "bear");
_operations.DeleteLines(_textBuffer.GetLine(0), 2, UnnamedRegister);
Assert.AreEqual(CreateLinesWithLineBreak("cat", "dog"), UnnamedRegister.StringValue);
Assert.AreEqual("bear", _textView.GetLine(0).GetText());
Assert.AreEqual(OperationKind.LineWise, UnnamedRegister.OperationKind);
}
/// <summary>
/// Verify the deleting of lines where the count causes the deletion to cross
/// over a fold
/// </summary>
[Test]
public void DeleteLines_OverFold()
{
Create("cat", "dog", "bear", "fish", "tree");
_foldManager.CreateFold(_textView.GetLineRange(1, 2));
_operations.DeleteLines(_textBuffer.GetLine(0), 3, UnnamedRegister);
Assert.AreEqual(CreateLinesWithLineBreak("cat", "dog", "bear", "fish"), UnnamedRegister.StringValue);
Assert.AreEqual("tree", _textView.GetLine(0).GetText());
Assert.AreEqual(OperationKind.LineWise, UnnamedRegister.OperationKind);
}
/// <summary>
/// Verify the deleting of lines where the count causes the deletion to cross
/// over a fold which begins the deletion span
/// </summary>
[Test]
public void DeleteLines_StartOfFold()
{
Create("cat", "dog", "bear", "fish", "tree");
_foldManager.CreateFold(_textView.GetLineRange(0, 1));
_operations.DeleteLines(_textBuffer.GetLine(0), 2, UnnamedRegister);
Assert.AreEqual(CreateLinesWithLineBreak("cat", "dog", "bear"), UnnamedRegister.StringValue);
Assert.AreEqual("fish", _textView.GetLine(0).GetText());
Assert.AreEqual(OperationKind.LineWise, UnnamedRegister.OperationKind);
}
[Test]
public void DeleteLines_Simple()
{
Create("foo", "bar", "baz", "jaz");
_operations.DeleteLines(_textBuffer.GetLine(0), 1, UnnamedRegister);
Assert.AreEqual("bar", _textView.GetLine(0).GetText());
Assert.AreEqual("foo" + Environment.NewLine, UnnamedRegister.StringValue);
Assert.AreEqual(0, _textView.GetCaretPoint().Position);
}
[Test]
public void DeleteLines_WithCount()
{
Create("foo", "bar", "baz", "jaz");
_operations.DeleteLines(_textBuffer.GetLine(0), 2, UnnamedRegister);
Assert.AreEqual("baz", _textView.GetLine(0).GetText());
Assert.AreEqual("foo" + Environment.NewLine + "bar" + Environment.NewLine, UnnamedRegister.StringValue);
Assert.AreEqual(0, _textView.GetCaretPoint().Position);
}
/// <summary>
/// Delete the last line and make sure it actually deletes a line from the buffer
/// </summary>
[Test]
public void DeleteLines_LastLine()
{
Create("foo", "bar");
_operations.DeleteLines(_textBuffer.GetLine(1), 1, UnnamedRegister);
Assert.AreEqual("bar" + Environment.NewLine, UnnamedRegister.StringValue);
Assert.AreEqual(1, _textView.TextSnapshot.LineCount);
Assert.AreEqual("foo", _textView.GetLine(0).GetText());
}
/// <summary>
/// Ensure that a join of 2 lines which don't have any blanks will produce lines which
/// are separated by a single space
/// </summary>
[Test]
public void Join_RemoveSpaces_NoBlanks()
{
Create("foo", "bar");
_operations.Join(_textView.GetLineRange(0, 1), JoinKind.RemoveEmptySpaces);
Assert.AreEqual("foo bar", _textView.TextSnapshot.GetLineFromLineNumber(0).GetText());
Assert.AreEqual(1, _textView.TextSnapshot.LineCount);
}
/// <summary>
/// Ensure that we properly remove the leading spaces at the start of the next line if
/// we are removing spaces
/// </summary>
[Test]
public void Join_RemoveSpaces_BlanksStartOfSecondLine()
{
Create("foo", " bar");
_operations.Join(_textView.GetLineRange(0, 1), JoinKind.RemoveEmptySpaces);
Assert.AreEqual("foo bar", _textView.TextSnapshot.GetLineFromLineNumber(0).GetText());
Assert.AreEqual(1, _textView.TextSnapshot.LineCount);
}
/// <summary>
/// Don't touch the spaces when we join without editing them
/// </summary>
[Test]
public void Join_KeepSpaces_BlanksStartOfSecondLine()
{
Create("foo", " bar");
_operations.Join(_textView.GetLineRange(0, 1), JoinKind.KeepEmptySpaces);
Assert.AreEqual("foo bar", _textView.TextSnapshot.GetLineFromLineNumber(0).GetText());
Assert.AreEqual(1, _textView.TextSnapshot.LineCount);
}
/// <summary>
/// Do a join of 3 lines
/// </summary>
[Test]
public void Join_RemoveSpaces_ThreeLines()
{
Create("foo", "bar", "baz");
_operations.Join(_textView.GetLineRange(0, 2), JoinKind.RemoveEmptySpaces);
Assert.AreEqual("foo bar baz", _textView.TextSnapshot.GetLineFromLineNumber(0).GetText());
Assert.AreEqual(1, _textView.TextSnapshot.LineCount);
}
/// <summary>
/// Ensure we can properly join an empty line
/// </summary>
[Test]
public void Join_RemoveSpaces_EmptyLine()
{
Create("cat", "", "dog", "tree", "rabbit");
_operations.Join(_textView.GetLineRange(0, 1), JoinKind.RemoveEmptySpaces);
Assert.AreEqual("cat ", _textView.GetLine(0).GetText());
Assert.AreEqual("dog", _textView.GetLine(1).GetText());
}
/// <summary>
/// No tabs is just a column offset
/// </summary>
[Test]
public void GetSpacesToColumn_NoTabs()
{
Create("hello world");
Assert.AreEqual(2, _operationsRaw.GetSpacesToColumn(_textBuffer.GetLine(0), 2));
}
/// <summary>
/// Tabs count as tabstop spaces
/// </summary>
[Test]
public void GetSpacesToColumn_Tabs()
{
Create("\thello world");
_localSettings.SetupGet(x => x.TabStop).Returns(4);
Assert.AreEqual(5, _operationsRaw.GetSpacesToColumn(_textBuffer.GetLine(0), 2));
}
/// <summary>
/// Without any tabs this should be a straight offset
/// </summary>
[Test]
public void GetPointForSpaces_NoTabs()
{
Create("hello world");
var point = _operationsRaw.GetPointForSpaces(_textBuffer.GetLine(0), 2);
Assert.AreEqual(_textBuffer.GetPoint(2), point);
}
/// <summary>
/// Count the tabs as a 'tabstop' value when calculating the Point
/// </summary>
[Test]
public void GetPointForSpaces_Tabs()
{
Create("\thello world");
_localSettings.SetupGet(x => x.TabStop).Returns(4);
var point = _operationsRaw.GetPointForSpaces(_textBuffer.GetLine(0), 5);
Assert.AreEqual(_textBuffer.GetPoint(2), point);
}
/// <summary>
/// Verify that we properly return the new line text for the first line
/// </summary>
[Test]
public void GetNewLineText_FirstLine()
{
Create("cat", "dog");
Assert.AreEqual(Environment.NewLine, _operations.GetNewLineText(_textBuffer.GetPoint(0)));
}
/// <summary>
/// Verify that we properly return the new line text for the first line when using a non
/// default new line ending
/// </summary>
[Test]
public void GetNewLineText_FirstLine_LineFeed()
{
Create("cat", "dog");
_textBuffer.Replace(new Span(0, 0), "cat\ndog");
Assert.AreEqual("\n", _operations.GetNewLineText(_textBuffer.GetPoint(0)));
}
/// <summary>
/// Verify that we properly return the new line text for middle lines
/// </summary>
[Test]
public void GetNewLineText_MiddleLine()
{
Create("cat", "dog", "bear");
Assert.AreEqual(Environment.NewLine, _operations.GetNewLineText(_textBuffer.GetLine(1).Start));
}
/// <summary>
/// Verify that we properly return the new line text for middle lines when using a non
/// default new line ending
/// </summary>
[Test]
public void GetNewLineText_MiddleLine_LineFeed()
{
Create("");
_textBuffer.Replace(new Span(0, 0), "cat\ndog\nbear");
Assert.AreEqual("\n", _operations.GetNewLineText(_textBuffer.GetLine(1).Start));
}
/// <summary>
/// Verify that we properly return the new line text for end lines
/// </summary>
[Test]
public void GetNewLineText_EndLine()
{
Create("cat", "dog", "bear");
Assert.AreEqual(Environment.NewLine, _operations.GetNewLineText(_textBuffer.GetLine(2).Start));
}
/// <summary>
/// Verify that we properly return the new line text for middle lines when using a non
/// default new line ending
/// </summary>
[Test]
public void GetNewLineText_EndLine_LineFeed()
{
Create("");
_textBuffer.Replace(new Span(0, 0), "cat\ndog\nbear");
Assert.AreEqual("\n", _operations.GetNewLineText(_textBuffer.GetLine(2).Start));
}
[Test]
public void GoToDefinition1()
{
Create("foo");
_jumpList.Setup(x => x.Add(_textView.GetCaretPoint())).Verifiable();
_vimHost.Setup(x => x.GoToDefinition()).Returns(true);
var res = _operations.GoToDefinition();
Assert.IsTrue(res.IsSucceeded);
_jumpList.Verify();
}
[Test]
public void GoToDefinition2()
{
Create("foo");
_vimHost.Setup(x => x.GoToDefinition()).Returns(false);
var res = _operations.GoToDefinition();
Assert.IsTrue(res.IsFailed);
Assert.IsTrue(((Result.Failed)res).Item.Contains("foo"));
}
[Test, Description("Make sure we don't crash when nothing is under the cursor")]
public void GoToDefinition3()
{
Create(" foo");
_vimHost.Setup(x => x.GoToDefinition()).Returns(false);
var res = _operations.GoToDefinition();
Assert.IsTrue(res.IsFailed);
}
[Test]
public void GoToDefinition4()
{
Create(" foo");
_vimHost.Setup(x => x.GoToDefinition()).Returns(false);
var res = _operations.GoToDefinition();
Assert.IsTrue(res.IsFailed);
Assert.AreEqual(Resources.Common_GotoDefNoWordUnderCursor, res.AsFailed().Item);
}
[Test]
public void GoToDefinition5()
{
Create("foo bar baz");
_vimHost.Setup(x => x.GoToDefinition()).Returns(false);
var res = _operations.GoToDefinition();
Assert.IsTrue(res.IsFailed);
Assert.AreEqual(Resources.Common_GotoDefFailed("foo"), res.AsFailed().Item);
}
/// <summary>
/// Simple insertion of a single item into the ITextBuffer
/// </summary>
[Test]
public void Put_Single()
{
Create("dog", "cat");
_operations.Put(_textView.GetLine(0).Start.Add(1), StringData.NewSimple("fish"), OperationKind.CharacterWise);
Assert.AreEqual("dfishog", _textView.GetLine(0).GetText());
}
/// <summary>
/// Put a block StringData value into the ITextBuffer over existing text
/// </summary>
[Test]
public void Put_BlockOverExisting()
{
Create("dog", "cat");
_operations.Put(_textView.GetLine(0).Start, VimUtil.CreateStringDataBlock("a", "b"), OperationKind.CharacterWise);
Assert.AreEqual("adog", _textView.GetLine(0).GetText());
Assert.AreEqual("bcat", _textView.GetLine(1).GetText());
}
/// <summary>
/// Put a block StringData value into the ITextBuffer where the length of the values
/// exceeds the number of lines in the ITextBuffer. This will force the insert to create
/// new lines to account for it
/// </summary>
[Test]
public void Put_BlockLongerThanBuffer()
{
Create("dog");
_operations.Put(_textView.GetLine(0).Start.Add(1), VimUtil.CreateStringDataBlock("a", "b"), OperationKind.CharacterWise);
Assert.AreEqual("daog", _textView.GetLine(0).GetText());
Assert.AreEqual(" b", _textView.GetLine(1).GetText());
}
/// <summary>
/// A linewise insertion for Block should just insert each value onto a new line
/// </summary>
[Test]
public void Put_BlockLineWise()
{
Create("dog", "cat");
_operations.Put(_textView.GetLine(1).Start, VimUtil.CreateStringDataBlock("a", "b"), OperationKind.LineWise);
Assert.AreEqual("dog", _textView.GetLine(0).GetText());
Assert.AreEqual("a", _textView.GetLine(1).GetText());
Assert.AreEqual("b", _textView.GetLine(2).GetText());
Assert.AreEqual("cat", _textView.GetLine(3).GetText());
}
/// <summary>
/// Put a single StringData instance linewise into the ITextBuffer.
/// </summary>
[Test]
public void Put_LineWiseSingleWord()
{
Create("cat");
_operations.Put(_textView.GetLine(0).Start, StringData.NewSimple("fish\n"), OperationKind.LineWise);
Assert.AreEqual("fish", _textView.GetLine(0).GetText());
Assert.AreEqual("cat", _textView.GetLine(1).GetText());
}
/// <summary>
/// Do a put at the end of the ITextBuffer which is of a single StringData and is characterwise
/// </summary>
[Test]
public void Put_EndOfBufferSingleCharacterwise()
{
Create("cat");
_operations.Put(_textView.GetEndPoint(), StringData.NewSimple("dog"), OperationKind.CharacterWise);
Assert.AreEqual("catdog", _textView.GetLine(0).GetText());
}
/// <summary>
/// Do a put at the end of the ITextBuffer linewise. This is a corner case because the code has
/// to move the final line break from the end of the StringData to the front. Ensure that we don't
/// keep the final \n in the inserted string because that will mess up the line count in the
/// ITextBuffer
/// </summary>
[Test]
public void Put_EndOfBufferLinewise()
{
Create("cat");
_operations.Put(_textView.GetEndPoint(), StringData.NewSimple("dog\n"), OperationKind.LineWise);
Assert.AreEqual("cat", _textView.GetLine(0).GetText());
Assert.AreEqual("dog", _textView.GetLine(1).GetText());
Assert.AreEqual(2, _textView.TextSnapshot.LineCount);
}
[Test, Description("Only shift whitespace")]
public void ShiftLineRangeLeft1()
{
Create("foo");
_operations.ShiftLineRangeLeft(_textBuffer.GetLineRange(0), 1);
Assert.AreEqual("foo", _textBuffer.CurrentSnapshot.GetLineFromLineNumber(0).GetText());
}
[Test, Description("Don't puke on an empty line")]
public void ShiftLineRangeLeft2()
{
Create("");
_operations.ShiftLineRangeLeft(_textBuffer.GetLineRange(0), 1);
Assert.AreEqual("", _textBuffer.CurrentSnapshot.GetLineFromLineNumber(0).GetText());
}
[Test]
public void ShiftLineRangeLeft3()
{
Create(" foo", " bar");
_operations.ShiftLineRangeLeft(_textBuffer.GetLineRange(0, 1), 1);
Assert.AreEqual("foo", _textBuffer.CurrentSnapshot.GetLineFromLineNumber(0).GetText());
Assert.AreEqual("bar", _textBuffer.CurrentSnapshot.GetLineFromLineNumber(1).GetText());
}
[Test]
public void ShiftLineRangeLeft4()
{
Create(" foo");
_operations.ShiftLineRangeLeft(_textBuffer.GetLineRange(0), 1);
Assert.AreEqual(" foo", _textBuffer.CurrentSnapshot.GetLineFromLineNumber(0).GetText());
}
[Test]
public void ShiftLineRangeLeft5()
{
Create(" a", " b", "c");
_operations.ShiftLineRangeLeft(_textBuffer.GetLineRange(0), 1);
Assert.AreEqual("a", _textBuffer.GetLine(0).GetText());
Assert.AreEqual(" b", _textBuffer.GetLine(1).GetText());
}
[Test]
public void ShiftLineRangeLeft6()
{
Create(" foo");
_operations.ShiftLineRangeLeft(_textView.GetLineRange(0), 1);
Assert.AreEqual(" foo", _textBuffer.GetLineRange(0).GetText());
}
[Test]
public void ShiftLineRangeLeft7()
{
Create(" foo");
_operations.ShiftLineRangeLeft(_textView.GetLineRange(0), 400);
Assert.AreEqual("foo", _textBuffer.GetLineRange(0).GetText());
}
[Test]
public void ShiftLineRangeLeft8()
{
Create(" foo", " bar");
_operations.ShiftLineRangeLeft(2);
Assert.AreEqual(" foo", _textBuffer.GetLineRange(0).GetText());
Assert.AreEqual(" bar", _textBuffer.GetLineRange(1).GetText());
}
[Test]
public void ShiftLineRangeLeft9()
{
Create(" foo", " bar");
_textView.MoveCaretTo(_textBuffer.GetLineRange(1).Start.Position);
_operations.ShiftLineRangeLeft(1);
Assert.AreEqual(" foo", _textBuffer.GetLineRange(0).GetText());
Assert.AreEqual(" bar", _textBuffer.GetLineRange(1).GetText());
}
[Test]
public void ShiftLineRangeLeft10()
{
Create(" foo", "", " bar");
_operations.ShiftLineRangeLeft(3);
Assert.AreEqual("foo", _textBuffer.GetLineRange(0).GetText());
Assert.AreEqual("", _textBuffer.GetLineRange(1).GetText());
Assert.AreEqual(" bar", _textBuffer.GetLineRange(2).GetText());
}
[Test]
public void ShiftLineRangeLeft11()
{
Create(" foo", " ", " bar");
_operations.ShiftLineRangeLeft(3);
Assert.AreEqual("foo", _textBuffer.GetLineRange(0).GetText());
Assert.AreEqual(" ", _textBuffer.GetLineRange(1).GetText());
Assert.AreEqual(" bar", _textBuffer.GetLineRange(2).GetText());
}
[Test]
public void ShiftLineRangeLeft_TabStartUsingSpaces()
{
Create("\tcat");
_localSettings.SetupGet(x => x.ExpandTab).Returns(true);
_operations.ShiftLineRangeLeft(1);
Assert.AreEqual(" cat", _textView.GetLine(0).GetText());
}
[Test]
[Description("Vim will actually normalize the line and then shift")]
public void ShiftLineRangeLeft_MultiTabStartUsingSpaces()
{
Create("\t\tcat");
_localSettings.SetupGet(x => x.ExpandTab).Returns(true);
_operations.ShiftLineRangeLeft(1);
Assert.AreEqual(" cat", _textView.GetLine(0).GetText());
}
[Test]
public void ShiftLineRangeLeft_TabStartUsingTabs()
{
Create("\tcat");
_localSettings.SetupGet(x => x.ExpandTab).Returns(false);
_operations.ShiftLineRangeLeft(1);
Assert.AreEqual(" cat", _textView.GetLine(0).GetText());
}
[Test]
public void ShiftLineRangeLeft_SpaceStartUsingTabs()
{
Create(" cat");
_localSettings.SetupGet(x => x.ExpandTab).Returns(false);
_operations.ShiftLineRangeLeft(1);
Assert.AreEqual(" cat", _textView.GetLine(0).GetText());
}
[Test]
public void ShiftLineRangeLeft_TabStartFollowedBySpacesUsingTabs()
{
Create("\t cat");
_localSettings.SetupGet(x => x.ExpandTab).Returns(false);
_operations.ShiftLineRangeLeft(1);
Assert.AreEqual("\t cat", _textView.GetLine(0).GetText());
}
[Test]
public void ShiftLineRangeLeft_SpacesStartFollowedByTabFollowedBySpacesUsingTabs()
{
Create(" \t cat");
_localSettings.SetupGet(x => x.ExpandTab).Returns(false);
_operations.ShiftLineRangeLeft(1);
Assert.AreEqual("\t\t cat", _textView.GetLine(0).GetText());
}
[Test]
public void ShiftLineRangeLeft_SpacesStartFollowedByTabFollowedBySpacesUsingTabsWithModifiedTabStop()
{
Create(" \t cat");
_localSettings.SetupGet(x => x.ExpandTab).Returns(false);
_localSettings.SetupGet(x => x.TabStop).Returns(2);
_operations.ShiftLineRangeLeft(1);
Assert.AreEqual("\t\t\t\tcat", _textView.GetLine(0).GetText());
}
[Test]
public void ShiftLineRangeLeft_ShortSpacesStartFollowedByTabFollowedBySpacesUsingTabs()
{
Create(" \t cat");
_localSettings.SetupGet(x => x.ExpandTab).Returns(false);
_operations.ShiftLineRangeLeft(1);
Assert.AreEqual("\t cat", _textView.GetLine(0).GetText());
}
[Test]
public void ShiftLineRangeRight1()
{
Create("foo");
_operations.ShiftLineRangeRight(_textBuffer.GetLineRange(0), 1);
Assert.AreEqual(" foo", _textBuffer.CurrentSnapshot.GetLineFromLineNumber(0).GetText());
}
[Test]
public void ShiftLineRangeRight2()
{
Create("a", "b", "c");
_operations.ShiftLineRangeRight(_textBuffer.GetLineRange(0), 1);
Assert.AreEqual(" a", _textBuffer.GetLine(0).GetText());
Assert.AreEqual("b", _textBuffer.GetLine(1).GetText());
}
[Test]
public void ShiftLineRangeRight3()
{
Create("foo");
_operations.ShiftLineRangeRight(1);
Assert.AreEqual(" foo", _textBuffer.GetLineRange(0).GetText());
}
[Test]
public void ShiftLineRangeRight4()
{
Create("foo", " bar");
_operations.ShiftLineRangeRight(2);
Assert.AreEqual(" foo", _textBuffer.GetLineRange(0).GetText());
Assert.AreEqual(" bar", _textBuffer.GetLineRange(1).GetText());
}
/// <summary>
/// Shift the line range right starting with the second line
/// </summary>
[Test]
public void ShiftLineRangeRight_SecondLine()
{
Create("foo", " bar");
_textView.MoveCaretTo(_textBuffer.GetLineRange(1).Start.Position);
_operations.ShiftLineRangeRight(1);
Assert.AreEqual("foo", _textBuffer.GetLineRange(0).GetText());
Assert.AreEqual(" bar", _textBuffer.GetLineRange(1).GetText());
}
/// <summary>
/// Blank lines should expand when shifting right
/// </summary>
[Test]
public void ShiftLineRangeRight_ExpandBlank()
{
Create("foo", " ", "bar");
_operations.ShiftLineRangeRight(3);
Assert.AreEqual(" foo", _textBuffer.GetLineRange(0).GetText());
Assert.AreEqual(" ", _textBuffer.GetLineRange(1).GetText());
Assert.AreEqual(" bar", _textBuffer.GetLineRange(2).GetText());
}
[Test]
public void ShiftLineRangeRight_NoExpandTab()
{
Create("cat", "dog");
_globalSettings.SetupGet(x => x.UseEditorSettings).Returns(false);
_globalSettings.SetupGet(x => x.ShiftWidth).Returns(4);
_localSettings.SetupGet(x => x.ExpandTab).Returns(false);
_operations.ShiftLineRangeRight(1);
Assert.AreEqual("\tcat", _textView.GetLine(0).GetText());
}
[Test]
public void ShiftLineRangeRight_NoExpandTabKeepSpacesWhenFewerThanTabStop()
{
Create("cat", "dog");
_globalSettings.SetupGet(x => x.UseEditorSettings).Returns(false);
_globalSettings.SetupGet(x => x.ShiftWidth).Returns(2);
_localSettings.SetupGet(x => x.TabStop).Returns(4);
_localSettings.SetupGet(x => x.ExpandTab).Returns(false);
_operations.ShiftLineRangeRight(1);
Assert.AreEqual(" cat", _textView.GetLine(0).GetText());
}
[Test]
public void ShiftLineRangeRight_SpacesStartUsingTabs()
{
Create(" cat", "dog");
_globalSettings.SetupGet(x => x.UseEditorSettings).Returns(false);
_localSettings.SetupGet(x => x.ExpandTab).Returns(false);
_localSettings.SetupGet(x => x.TabStop).Returns(2);
_operations.ShiftLineRangeRight(1);
Assert.AreEqual("\t\tcat", _textView.GetLine(0).GetText());
}
/// <summary>
/// Make sure it shifts on the appropriate column and not column 0
/// </summary>
[Test]
public void ShiftLineBlockRight_Simple()
{
Create("cat", "dog");
_operations.ShiftLineBlockRight(_textView.GetBlock(column: 1, length: 1, startLine: 0, lineCount: 2), 1);
Assert.AreEqual("c at", _textView.GetLine(0).GetText());
Assert.AreEqual("d og", _textView.GetLine(1).GetText());
}
/// <summary>
/// Make sure it shifts on the appropriate column and not column 0
/// </summary>
[Test]
public void ShiftLineBlockLeft_Simple()
{
Create("c at", "d og");
_operations.ShiftLineBlockLeft(_textView.GetBlock(column: 1, length: 1, startLine: 0, lineCount: 2), 1);
Assert.AreEqual("cat", _textView.GetLine(0).GetText());
Assert.AreEqual("dog", _textView.GetLine(1).GetText());
}
/// <summary>
/// Make sure the caret column is maintained when specified going down
/// </summary>
[Test]
public void MaintainCaretColumn_Down()
{
Create("the dog chased the ball", "hello", "the cat climbed the tree");
var motionResult = VimUtil.CreateMotionResult(
_textView.GetLineRange(0, 1).ExtentIncludingLineBreak,
motionKind: MotionKind.NewLineWise(CaretColumn.NewInLastLine(2)),
flags: MotionResultFlags.MaintainCaretColumn);
_operations.MoveCaretToMotionResult(motionResult);
Assert.AreEqual(2, _operationsRaw.MaintainCaretColumn.Value);
}
/// <summary>
/// Don't maintain the caret column if the maintain flag is not specified
/// </summary>
[Test]
public void MaintainCaretColumn_IgnoreIfFlagNotSpecified()
{
Create("the dog chased the ball", "hello", "the cat climbed the tree");
var motionResult = VimUtil.CreateMotionResult(
_textView.GetLineRange(0, 1).ExtentIncludingLineBreak,
motionKind: MotionKind.NewLineWise(CaretColumn.NewInLastLine(2)),
flags: MotionResultFlags.None);
var data = VimUtil.CreateMotionResult(
new SnapshotSpan(_textBuffer.CurrentSnapshot, 1, 2),
true,
MotionKind.CharacterWiseInclusive);
_operations.MoveCaretToMotionResult(data);
Assert.AreEqual(2, _textView.GetCaretPoint().Position);
}
[Test]
public void MoveCaretToMotionResult2()
{
Create("foo", "bar", "baz");
var data = VimUtil.CreateMotionResult(
new SnapshotSpan(_textBuffer.CurrentSnapshot, 0, 1),
true,
MotionKind.CharacterWiseInclusive);
_operations.MoveCaretToMotionResult(data);
Assert.AreEqual(0, _textView.GetCaretPoint().Position);
}
[Test]
public void MoveCaretToMotionResult3()
{
Create("foo", "bar", "baz");
var data = VimUtil.CreateMotionResult(
new SnapshotSpan(_textBuffer.CurrentSnapshot, 0, 0),
true,
MotionKind.CharacterWiseInclusive);
_operations.MoveCaretToMotionResult(data);
Assert.AreEqual(0, _textView.GetCaretPoint().Position);
}
[Test]
public void MoveCaretToMotionResult4()
{
Create("foo", "bar", "baz");
var data = VimUtil.CreateMotionResult(
new SnapshotSpan(_textBuffer.CurrentSnapshot, 0, 3),
false,
MotionKind.CharacterWiseInclusive);
_operations.MoveCaretToMotionResult(data);
Assert.AreEqual(0, _textView.GetCaretPoint().Position);
}
[Test]
public void MoveCaretToMotionResult6()
{
Create("foo", "bar", "baz");
var data = VimUtil.CreateMotionResult(
new SnapshotSpan(_textBuffer.CurrentSnapshot, 0, 1),
true,
MotionKind.CharacterWiseExclusive);
_operations.MoveCaretToMotionResult(data);
Assert.AreEqual(1, _textView.GetCaretPoint().Position);
}
[Test]
[Description("Motion to empty last line")]
public void MoveCaretToMotionResult7()
{
Create("foo", "bar", "");
var data = VimUtil.CreateMotionResult(
new SnapshotSpan(_textBuffer.CurrentSnapshot, 0, _textBuffer.CurrentSnapshot.Length),
true,
MotionKind.NewLineWise(CaretColumn.None));
_operations.MoveCaretToMotionResult(data);
Assert.AreEqual(2, _textView.GetCaretPoint().GetContainingLine().LineNumber);
}
[Test]
[Description("Need to respect the specified column")]
public void MoveCaretToMotionResult8()
{
Create("foo", "bar", "");
var data = VimUtil.CreateMotionResult(
_textBuffer.GetLineRange(0, 1).Extent,
true,
MotionKind.NewLineWise(CaretColumn.NewInLastLine(1)));
_operations.MoveCaretToMotionResult(data);
Assert.AreEqual(Tuple.Create(1, 1), SnapshotPointUtil.GetLineColumn(_textView.GetCaretPoint()));
}
[Test]
[Description("Ignore column if it's past the end of the line")]
public void MoveCaretToMotionResult9()
{
Create("foo", "bar", "");
var data = VimUtil.CreateMotionResult(
_textBuffer.GetLineRange(0, 1).Extent,
true,
MotionKind.NewLineWise(CaretColumn.NewInLastLine(100)));
_operations.MoveCaretToMotionResult(data);
Assert.AreEqual(Tuple.Create(1, 2), SnapshotPointUtil.GetLineColumn(_textView.GetCaretPoint()));
}
[Test]
[Description("Need to respect the specified column")]
public void MoveCaretToMotionResult10()
{
Create("foo", "bar", "");
var data = VimUtil.CreateMotionResult(
_textBuffer.GetLineRange(0, 1).Extent,
true,
MotionKind.NewLineWise(CaretColumn.NewInLastLine(0)));
_operations.MoveCaretToMotionResult(data);
Assert.AreEqual(Tuple.Create(1, 0), SnapshotPointUtil.GetLineColumn(_textView.GetCaretPoint()));
}
[Test]
[Description("Reverse spans should move to the start of the span")]
public void MoveCaretToMotionResult11()
{
Create("dog", "cat", "bear");
var data = VimUtil.CreateMotionResult(
_textBuffer.GetLineRange(0, 1).Extent,
false,
MotionKind.CharacterWiseInclusive);
_operations.MoveCaretToMotionResult(data);
Assert.AreEqual(Tuple.Create(0, 0), SnapshotPointUtil.GetLineColumn(_textView.GetCaretPoint()));
}
[Test]
[Description("Reverse spans should move to the start of the span and respect column")]
public void MoveCaretToMotionResult12()
{
Create("dog", "cat", "bear");
var data = VimUtil.CreateMotionResult(
_textBuffer.GetLineRange(0, 1).ExtentIncludingLineBreak,
false,
MotionKind.NewLineWise(CaretColumn.NewInLastLine(2)));
_operations.MoveCaretToMotionResult(data);
Assert.AreEqual(Tuple.Create(0, 2), SnapshotPointUtil.GetLineColumn(_textView.GetCaretPoint()));
}
[Test]
[Description("Exclusive spans going backward should go through normal movements")]
public void MoveCaretToMotionResult14()
{
Create("dog", "cat", "bear");
var data = VimUtil.CreateMotionResult(
_textBuffer.GetLineRange(0, 1).ExtentIncludingLineBreak,
false,
MotionKind.CharacterWiseExclusive);
_operations.MoveCaretToMotionResult(data);
Assert.AreEqual(_textBuffer.GetLine(0).Start, _textView.GetCaretPoint());
}
[Test]
[Description("Used with the - motion")]
public void MoveCaretToMotionResult_ReverseLineWiseWithColumn()
{
Create(" dog", "cat", "bear");
var data = VimUtil.CreateMotionResult(
span: _textView.GetLineRange(0, 1).ExtentIncludingLineBreak,
isForward: false,
motionKind: MotionKind.NewLineWise(CaretColumn.NewInLastLine(1)));
_operations.MoveCaretToMotionResult(data);
Assert.AreEqual(1, _textView.GetCaretPoint().Position);
}
/// <summary>
/// Spans going forward which have the AfterLastLine value should have the caret after the
/// last line
/// </summary>
[Test]
public void MoveCaretToMotionResult_CaretAfterLastLine()
{
Create("dog", "cat", "bear");
var data = VimUtil.CreateMotionResult(
_textBuffer.GetLineRange(0).ExtentIncludingLineBreak,
true,
MotionKind.NewLineWise(CaretColumn.AfterLastLine));
_operations.MoveCaretToMotionResult(data);
Assert.AreEqual(_textBuffer.GetLine(1).Start, _textView.GetCaretPoint());
}
/// <summary>