public void TextViewClosedImmediatelyAfterInitialLayout()
            {
                var textBuffer    = CreateTextBuffer("");
                var vimTextBuffer = _vimBufferFactory.CreateVimTextBuffer(textBuffer, _vim);

                var textView = MockObjectFactory.CreateTextView(textBuffer, factory: _factory);

                textView.SetupGet(x => x.TextViewLines).Returns((ITextViewLineCollection)null);
                textView.SetupGet(x => x.InLayout).Returns(false);
                textView.SetupGet(x => x.IsClosed).Returns(false);

                var vimBuffer = _vimBufferFactory.CreateVimBuffer(textView.Object, vimTextBuffer);

                Assert.Equal(ModeKind.Uninitialized, vimBuffer.ModeKind);

                textView.SetupGet(x => x.TextViewLines).Returns(() =>
                {
                    var lines = _factory.Create <ITextViewLineCollection>();
                    lines.SetupGet(x => x.IsValid).Returns(true);
                    return(lines.Object);
                });
                textView.SetupGet(x => x.InLayout).Returns(false);
                textView.SetupGet(x => x.IsClosed).Returns(false);
                textView.Raise(x => x.LayoutChanged += null, (TextViewLayoutChangedEventArgs)null);
                Assert.Equal(ModeKind.Uninitialized, vimBuffer.ModeKind);

                Assert.Equal(1, TestableSynchronizationContext.PostedCallbackCount);
                textView.SetupGet(x => x.IsClosed).Returns(true);
                textView.SetupGet(x => x.TextViewLines).Throws(new Exception());
                TestableSynchronizationContext.RunAll();
                Assert.Equal(ModeKind.Uninitialized, vimBuffer.ModeKind);
            }
Exemple #2
0
 public void Start_LineShouldSelectWholeLine()
 {
     Create(VisualKind.Line, "foo", "bar");
     _context.RunAll();
     Assert.Equal(_textView.TextBuffer.GetLineFromLineNumber(0).Start, _textView.Selection.Start.Position);
     Assert.Equal(_textView.TextBuffer.GetLineFromLineNumber(0).EndIncludingLineBreak, _textView.Selection.End.Position);
 }
Exemple #3
0
            private void AssertLastLine(int lineNumber)
            {
                TestableSynchronizationContext.RunAll();
                var actual = _textView.GetLastVisibleLineNumber();

                Assert.Equal(lineNumber, actual);
            }
            public void TextViewInLayoutInsideLayoutEvent()
            {
                var textBuffer    = CreateTextBuffer("");
                var vimTextBuffer = _vimBufferFactory.CreateVimTextBuffer(textBuffer, _vim);

                var textView = MockObjectFactory.CreateTextView(textBuffer, factory: _factory);

                textView.SetupGet(x => x.TextViewLines).Returns((ITextViewLineCollection)null);
                textView.SetupGet(x => x.InLayout).Returns(false);
                textView.SetupGet(x => x.IsClosed).Returns(false);

                var vimBuffer = _vimBufferFactory.CreateVimBuffer(textView.Object, vimTextBuffer);

                Assert.Equal(ModeKind.Uninitialized, vimBuffer.ModeKind);

                // Still can't initialize here because inside the event we are in another layout
                // which prevents a mode change
                textView.SetupGet(x => x.TextViewLines).Throws(new Exception());
                textView.SetupGet(x => x.InLayout).Returns(true);
                textView.Raise(x => x.LayoutChanged += null, (TextViewLayoutChangedEventArgs)null);
                Assert.Equal(ModeKind.Uninitialized, vimBuffer.ModeKind);

                textView.SetupGet(x => x.Caret.Position).Returns(new CaretPosition());
                textView.SetupGet(x => x.TextViewLines).Returns(_factory.Create <ITextViewLineCollection>().Object);
                textView.SetupGet(x => x.InLayout).Returns(false);
                textView.Raise(x => x.LayoutChanged += null, (TextViewLayoutChangedEventArgs)null);
                TestableSynchronizationContext.RunAll();
                Dispatcher.CurrentDispatcher.DoEvents();
                Assert.Equal(ModeKind.Normal, vimBuffer.ModeKind);
            }
Exemple #5
0
 public void SelectOfText()
 {
     Create("cat dog");
     _textSelection.Select(0, 3);
     TestableSynchronizationContext.RunAll();
     Assert.Equal(ModeKind.SelectCharacter, _vimBuffer.ModeKind);
 }
        public void SelectionChanged3()
        {
            _vimBuffer.SetupGet(x => x.IsProcessingInput).Returns(false).Verifiable();
            _vimBuffer.SetupGet(x => x.ModeKind).Returns(ModeKind.Normal).Verifiable();
            _selection.SetupGet(x => x.IsEmpty).Returns(false).Verifiable();
            _selection.Raise(x => x.SelectionChanged += null, null, EventArgs.Empty);
            Assert.False(_context.IsEmpty);
            _factory.Verify();

            _vimBuffer
            .Setup(x => x.SwitchMode(ModeKind.VisualCharacter, ModeArgument.None))
            .Returns(_factory.Create <IMode>().Object)
            .Verifiable();
            _context.RunAll();
            _factory.Verify();
        }
Exemple #7
0
            public void BackgroundCompleted()
            {
                Create("dog", "cat", "fish", "dog");
                _asyncTaggerSource.SetBackgroundFunc(span => TestUtils.GetDogTags(span));
                _asyncTagger.GetTags(_textBuffer.GetLineRange(0).Extent);
                _asyncTagger.AsyncBackgroundRequestData.Value.Task.Wait();

                // The background request is now complete and it's posted to the UI thread.  Create a
                // new request on a new snapshot.  This will supercede the existing request
                _textBuffer.Replace(new Span(0, 0), "big ");
                _asyncTagger.GetTags(_textBuffer.GetLineRange(0).Extent);
                Assert.True(_asyncTagger.AsyncBackgroundRequestData.IsSome());
                var tokenSource = _asyncTagger.AsyncBackgroundRequestData.Value.CancellationTokenSource;

                // The background will try to post twice (once for progress and the other for complete)
                for (var i = 0; i < 2; i++)
                {
                    TestableSynchronizationContext.RunOne();
                    Assert.True(_asyncTagger.AsyncBackgroundRequestData.IsSome());
                    Assert.Equal(tokenSource, _asyncTagger.AsyncBackgroundRequestData.Value.CancellationTokenSource);
                }

                _asyncTagger.AsyncBackgroundRequestData.Value.Task.Wait();
                TestableSynchronizationContext.RunAll();
            }
Exemple #8
0
            public void GetTags()
            {
                Create("dog", "cat", "fish", "dog");
                _asyncTaggerSource.SetBackgroundFunc(span => TestUtils.GetDogTags(span));
                _asyncTagger.GetTags(_textBuffer.GetLineRange(0).Extent);
                Assert.True(_asyncTagger.AsyncBackgroundRequestData.IsSome());

                // Background is done.  Because we control the synchronization TestableSynchronizationContext though the foreground
                // thread still sees it as active and hence will continue to queue data on it
                _asyncTagger.AsyncBackgroundRequestData.Value.Task.Wait();
                Assert.True(_asyncTagger.AsyncBackgroundRequestData.IsSome());
                _asyncTagger.GetTags(_textBuffer.GetLineRange(3).Extent);

                // Clear the queue, the missing work will be seen and immedieatly requeued
                TestableSynchronizationContext.RunAll();
                WaitForBackgroundToComplete();

                var tags = _asyncTagger.GetTags(_textBuffer.GetExtent());

                Assert.Equal(
                    new[] { _textBuffer.GetLineSpan(0, 3), _textBuffer.GetLineSpan(3, 3) },
                    tags.Select(x => x.Span));
                TestableSynchronizationContext.RunAll();
                WaitForBackgroundToComplete();
            }
Exemple #9
0
        protected void EnterSelect(int start, int length)
        {
            var span = new SnapshotSpan(_textBuffer.CurrentSnapshot, start, length);

            _textView.SelectAndMoveCaret(span);
            TestableSynchronizationContext.RunAll();
            Assert.Equal(ModeKind.SelectCharacter, _vimBuffer.ModeKind);
        }
Exemple #10
0
 protected override void WaitUntilCompleted(TestableSynchronizationContext context)
 {
     Assert.NotNull(context);
     while (_asyncTagger.AsyncBackgroundRequestData.IsSome())
     {
         Thread.Yield();
         context.RunAll();
     }
 }
Exemple #11
0
                public void Forward()
                {
                    Create("big dog", "big cat", "big tree", "big fish");
                    var characterSpan = new CharacterSpan(_textBuffer.GetSpan(1, 3));
                    var visualSpan    = VisualSpan.NewCharacter(characterSpan);

                    visualSpan.Select(_textView, SearchPath.Forward);
                    TestableSynchronizationContext.RunAll();
                    Assert.False(_textView.Selection.IsReversed);
                    Assert.Equal(characterSpan.Span, _textView.GetSelectionSpan());
                }
Exemple #12
0
 public void ExtendSelection()
 {
     Create("cat dog");
     _textSelection.Select(0, 3);
     TestableSynchronizationContext.RunAll();
     Assert.Equal(ModeKind.SelectCharacter, _vimBuffer.ModeKind);
     _textSelection.Select(0, 5);
     Assert.False(TestableSynchronizationContext.IsEmpty);
     TestableSynchronizationContext.RunAll();
     Assert.Equal(ModeKind.SelectCharacter, _vimBuffer.ModeKind);
 }
Exemple #13
0
                public void Forward()
                {
                    Create("big dog", "big cat", "big tree", "big fish");
                    var lineRange  = _textBuffer.GetLineRange(1);
                    var visualSpan = VisualSpan.NewLine(lineRange);

                    visualSpan.Select(_textView, SearchPath.Forward);
                    TestableSynchronizationContext.RunAll();
                    Assert.False(_textView.Selection.IsReversed);
                    Assert.Equal(lineRange.ExtentIncludingLineBreak, _textView.GetSelectionSpan());
                }
Exemple #14
0
                public void ForwardIntoLineBreak()
                {
                    Create("cat", "dog");
                    var characterSpan = new CharacterSpan(_textBuffer.GetSpan(0, 4));
                    var visualSpan    = VisualSpan.NewCharacter(characterSpan);

                    visualSpan.Select(_textView, SearchPath.Forward);
                    TestableSynchronizationContext.RunAll();
                    Assert.Equal(4, _textView.Selection.StreamSelectionSpan.Length);
                    Assert.False(_textView.Selection.IsReversed);
                }
Exemple #15
0
                public void IncludeLineBreak()
                {
                    Create("cat", "dog");
                    _textView.Selection.Select(_textBuffer.GetPoint(0), _textBuffer.GetPoint(5));
                    TestableSynchronizationContext.RunAll();
                    var visualSpan    = VisualSpan.CreateForSelection(_textView, VisualKind.Character, tabStop: 4);
                    var characterSpan = visualSpan.AsCharacter().Item;

                    Assert.True(characterSpan.IncludeLastLineLineBreak);
                    Assert.Equal(1, characterSpan.LineCount);
                }
Exemple #16
0
                public void Simple()
                {
                    Create("big dog", "big cat", "big tree", "big fish");
                    var blockSpan  = _vimBuffer.GetBlockSpan(1, 2, 0, 2);
                    var visualSpan = VisualSpan.NewBlock(blockSpan);

                    visualSpan.Select(_textView, SearchPath.Forward);
                    TestableSynchronizationContext.RunAll();
                    Assert.Equal(blockSpan, _vimBuffer.GetSelectionBlockSpan());
                    Assert.Equal(TextSelectionMode.Box, _textView.Selection.Mode);
                }
Exemple #17
0
                public void EndsInEmptyLineCase()
                {
                    Create("cat", "", "dog");
                    _textView.Selection.Select(_textBuffer.GetPoint(0), _textBuffer.GetPoint(6));
                    TestableSynchronizationContext.RunAll();
                    Assert.Equal(1, _textView.Selection.StreamSelectionSpan.End.Position.GetContainingLine().LineNumber);
                    var visualSpan    = VisualSpan.CreateForSelection(_textView, VisualKind.Character, tabStop: 4);
                    var characterSpan = visualSpan.AsCharacter().Item;

                    Assert.Equal(2, characterSpan.LineCount);
                    Assert.True(characterSpan.IncludeLastLineLineBreak);
                }
Exemple #18
0
                public void Virtual(string line1)
                {
                    Create(line1, "");
                    var point1        = _textBuffer.GetVirtualPointInLine(0, 0);
                    var point2        = _textBuffer.GetVirtualPointInLine(0, 4);
                    var span          = new VirtualSnapshotSpan(point1, point2);
                    var characterSpan = new CharacterSpan(span, true);
                    var visualSpan    = VisualSpan.NewCharacter(characterSpan);

                    visualSpan.Select(_textView, SearchPath.Forward);
                    TestableSynchronizationContext.RunAll();
                    Assert.Equal(point1, _textView.Selection.Start);
                    Assert.Equal(point2, _textView.Selection.End);
                }
Exemple #19
0
            public void EndOfLineSelection()
            {
                var vimBuffer = CreateVimBuffer("cat", "dog", "tree");

                vimBuffer.GlobalSettings.VirtualEdit = "";
                var textBuffer   = vimBuffer.TextBuffer;
                var textSnapshot = textBuffer.CurrentSnapshot;
                var selection    = vimBuffer.TextView.Selection;
                var span         = textBuffer.GetLineRange(0);

                selection.Select(span.ExtentIncludingLineBreak);
                TestableSynchronizationContext.RunAll();
                Assert.Equal(span.ExtentIncludingLineBreak, selection.StreamSelectionSpan.SnapshotSpan);
                Assert.Equal(textSnapshot.Version.VersionNumber, textBuffer.CurrentSnapshot.Version.VersionNumber);
            }
Exemple #20
0
                public void Virtual(string line1)
                {
                    Create(line1, "");
                    var point1 = _textBuffer.GetVirtualPointInLine(0, 0);
                    var point2 = _textBuffer.GetVirtualPointInLine(0, 4);
                    var span   = new VirtualSnapshotSpan(point1, point2);

                    _textView.Selection.Select(point1, point2);
                    TestableSynchronizationContext.RunAll();
                    var visualSpan = VisualSpan.CreateForVirtualSelection(_textView, VisualKind.Character, tabStop: 4, useVirtualSpace: true);

                    Assert.Equal(point1, visualSpan.AsCharacter().Item.VirtualStart);
                    Assert.Equal(point2, visualSpan.AsCharacter().Item.VirtualEnd);
                    Assert.Equal(span.Length, visualSpan.AsCharacter().Item.VirtualLength);
                }
Exemple #21
0
                public void CaretInTabAnchorAboveTab()
                {
                    Create(4, "trucker", "\tcat");
                    var blockSpan  = new BlockSpan(_textBuffer.GetPoint(1), tabStop: 4, spaces: 1, height: 2);
                    var visualSpan = VisualSpan.NewBlock(blockSpan);

                    visualSpan.Select(_textView, SearchPath.Forward);
                    TestableSynchronizationContext.RunAll();
                    Assert.Equal(
                        new[]
                    {
                        _textBuffer.GetLineSpan(0, 0, 4),
                        _textBuffer.GetLineSpan(1, 0, 1)
                    },
                        _textView.Selection.SelectedSpans);
                }
Exemple #22
0
                public void SimpleCaretPastTab2()
                {
                    Create("trucker", "\tcat");
                    var blockSpan  = new BlockSpan(_textBuffer.GetPoint(1), tabStop: 2, spaces: 3, height: 2);
                    var visualSpan = VisualSpan.NewBlock(blockSpan);

                    visualSpan.Select(_textView, SearchPath.Forward);
                    TestableSynchronizationContext.RunAll();
                    Assert.Equal(
                        new[]
                    {
                        _textBuffer.GetLineSpan(0, 1, 3),
                        _textBuffer.GetLineSpan(1, 1, 2)
                    },
                        _textView.Selection.SelectedSpans);
                }
Exemple #23
0
                public void SimpleCaretPastTab()
                {
                    Create("trucker", "\tcat");
                    var blockSpan  = new BlockSpan(_textBuffer.GetPoint(1), tabStop: 2, spaces: 2, height: 2);
                    var visualSpan = VisualSpan.NewBlock(blockSpan);

                    visualSpan.Select(_textView, SearchPath.Forward);
                    TestableSynchronizationContext.RunAll();

                    // It may seem odd for the second span to start on column 1 since the tab is partially
                    // included in the line.  However Visual Studio has this behavior.  It won't select a
                    // character at the start / end of a selection unless it's completely included
                    Assert.Equal(
                        new[]
                    {
                        _textBuffer.GetLineSpan(0, 1, 2),
                        _textBuffer.GetLineSpan(1, 1, 1)
                    },
                        _textView.Selection.SelectedSpans);
                }
            public void TextViewDelayInitialize()
            {
                var textBuffer = CreateTextBuffer("");
                var textView   = MockObjectFactory.CreateTextView(textBuffer, factory: _factory);

                textView.SetupGet(x => x.TextViewLines).Returns((ITextViewLineCollection)null);
                textView.SetupGet(x => x.InLayout).Returns(false);
                textView.SetupGet(x => x.Caret.Position).Returns(new CaretPosition());
                textView.SetupGet(x => x.IsClosed).Returns(false);
                var vimTextBuffer = _vimBufferFactory.CreateVimTextBuffer(textBuffer, _vim);
                var vimBuffer     = _vimBufferFactory.CreateVimBuffer(textView.Object, vimTextBuffer);

                Assert.Equal(ModeKind.Uninitialized, vimBuffer.ModeKind);

                textView.SetupGet(x => x.TextViewLines).Returns(new Mock <ITextViewLineCollection>().Object);
                textView.Raise(x => x.LayoutChanged += null, (TextViewLayoutChangedEventArgs)null);
                TestableSynchronizationContext.RunAll();
                Dispatcher.CurrentDispatcher.DoEvents();

                Assert.Equal(ModeKind.Normal, vimBuffer.ModeKind);
            }
            public void TextViewClosedInsideLayoutEvent()
            {
                var textBuffer    = CreateTextBuffer("");
                var vimTextBuffer = _vimBufferFactory.CreateVimTextBuffer(textBuffer, _vim);

                var textView = MockObjectFactory.CreateTextView(textBuffer, factory: _factory);

                textView.SetupGet(x => x.TextViewLines).Returns((ITextViewLineCollection)null);
                textView.SetupGet(x => x.InLayout).Returns(false);
                textView.SetupGet(x => x.IsClosed).Returns(false);

                var vimBuffer = _vimBufferFactory.CreateVimBuffer(textView.Object, vimTextBuffer);

                Assert.Equal(ModeKind.Uninitialized, vimBuffer.ModeKind);

                textView.SetupGet(x => x.TextViewLines).Throws(new Exception());
                textView.SetupGet(x => x.InLayout).Throws(new Exception());
                textView.SetupGet(x => x.IsClosed).Returns(true);
                textView.Raise(x => x.LayoutChanged += null, (TextViewLayoutChangedEventArgs)null);
                Assert.Equal(ModeKind.Uninitialized, vimBuffer.ModeKind);
                TestableSynchronizationContext.RunAll();
            }