Example #1
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();
            }
Example #2
0
        public void SimpleMultipleSameLine()
        {
            using (var context = new TestableSynchronizationContext())
            {
                Create("cat dog dog", "fish");
                var tags     = _tagger.GetTags(_textBuffer.GetExtent()).ToList();
                var expected = new[] { _textBuffer.GetSpan(4, 3), _textBuffer.GetSpan(8, 3) };
                if (tags.Count == 0)
                {
                    // Fine for the result to be delayed but we must see a TagsChanged event occur
                    // to signal the new tags.  The SnapshotSpan values which occur in that list
                    // must include the expected span
                    Assert.False(IsComplete());
                    WaitUntilCompleted(context);
                    foreach (var value in expected)
                    {
                        Assert.Contains(_tagsChangedList, x => x.Span.Contains(value));
                    }
                    tags = _tagger.GetTags(_textBuffer.GetExtent()).ToList();
                }
                else
                {
                    // If the tags returned promptly they shouldn't have raised any tags changed
                    // events
                    Assert.Empty(_tagsChangedList);
                }

                Assert.Equal(expected, tags.Select(x => x.Span));
            }
        }
            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);
            }
        public SelectionChangeTrackerTest()
        {
            _factory = new MockRepository(MockBehavior.Loose);
            _selection = _factory.Create<ITextSelection>();
            _textView = MockObjectFactory.CreateTextView(
                selection: _selection.Object,
                factory: _factory);
            _vimHost = _factory.Create<IVimHost>();
            _vimHost.Setup(x => x.IsFocused(_textView.Object)).Returns(true);
            _vimBuffer = MockObjectFactory.CreateVimBuffer(
                textView: _textView.Object,
                vim: MockObjectFactory.CreateVim(host: _vimHost.Object).Object,
                factory: _factory);
            _vimBuffer.SetupGet(x => x.IsClosed).Returns(false);

            _mouseDevice = _factory.Create<IMouseDevice>();
            _selectionOverride = _factory.Create<IVisualModeSelectionOverride>();
            _selectionOverride.Setup(x => x.IsInsertModePreferred(It.IsAny<ITextView>())).Returns(false);
            var selectionList = new List<IVisualModeSelectionOverride>();
            selectionList.Add(_selectionOverride.Object);

            _context = new TestableSynchronizationContext();
            _context.Install();
            _tracker = new SelectionChangeTracker(_vimBuffer.Object, _factory.Create<ICommonOperations>(MockBehavior.Loose).Object, selectionList.ToFSharpList(), _mouseDevice.Object);
        }
Example #5
0
            private void AssertLastLine(int lineNumber)
            {
                TestableSynchronizationContext.RunAll();
                var actual = _textView.GetLastVisibleLineNumber();

                Assert.Equal(lineNumber, actual);
            }
Example #6
0
 public void SelectOfText()
 {
     Create("cat dog");
     _textSelection.Select(0, 3);
     TestableSynchronizationContext.RunAll();
     Assert.Equal(ModeKind.SelectCharacter, _vimBuffer.ModeKind);
 }
            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);
            }
        public SelectionChangeTrackerTest()
        {
            _factory   = new MockRepository(MockBehavior.Loose);
            _selection = _factory.Create <ITextSelection>();
            _textView  = MockObjectFactory.CreateTextView(
                selection: _selection.Object,
                factory: _factory);
            _vimHost = _factory.Create <IVimHost>();
            _vimHost.Setup(x => x.IsFocused(_textView.Object)).Returns(true);
            _vimBuffer = MockObjectFactory.CreateVimBuffer(
                textView: _textView.Object,
                vim: MockObjectFactory.CreateVim(host: _vimHost.Object).Object,
                factory: _factory);
            _vimBuffer.SetupGet(x => x.IsClosed).Returns(false);

            _mouseDevice       = _factory.Create <IMouseDevice>();
            _selectionOverride = _factory.Create <IVisualModeSelectionOverride>();
            _selectionOverride.Setup(x => x.IsInsertModePreferred(It.IsAny <ITextView>())).Returns(false);
            var selectionList = new List <IVisualModeSelectionOverride>();

            selectionList.Add(_selectionOverride.Object);

            _context = new TestableSynchronizationContext();
            _context.Install();
            _tracker = new SelectionChangeTracker(_vimBuffer.Object, _factory.Create <ICommonOperations>(MockBehavior.Loose).Object, selectionList.ToFSharpList(), _mouseDevice.Object);
        }
Example #9
0
 public void Start_LineShouldSelectWholeLine()
 {
     Create(VisualKind.Line, "foo", "bar");
     TestableSynchronizationContext.RunAll();
     Assert.Equal(_textView.TextBuffer.GetLineFromLineNumber(0).Start, _textView.Selection.Start.Position);
     Assert.Equal(_textView.TextBuffer.GetLineFromLineNumber(0).EndIncludingLineBreak, _textView.Selection.End.Position);
 }
Example #10
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();
            }
Example #11
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);
        }
Example #12
0
 protected override void WaitUntilCompleted(TestableSynchronizationContext context)
 {
     Assert.NotNull(context);
     while (_asyncTagger.AsyncBackgroundRequestData.IsSome())
     {
         Thread.Yield();
         context.RunAll();
     }
 }
Example #13
0
        private void ResetState()
        {
            Vim.MarkMap.Clear();

            Vim.VimData.SearchHistory.Reset();
            Vim.VimData.CommandHistory.Reset();
            Vim.VimData.LastCommand       = FSharpOption <StoredCommand> .None;
            Vim.VimData.LastCommandLine   = "";
            Vim.VimData.LastShellCommand  = FSharpOption <string> .None;
            Vim.VimData.LastTextInsert    = FSharpOption <string> .None;
            Vim.VimData.AutoCommands      = FSharpList <AutoCommand> .Empty;
            Vim.VimData.AutoCommandGroups = FSharpList <AutoCommandGroup> .Empty;

            Vim.KeyMap.ClearAll();
            Vim.KeyMap.IsZeroMappingEnabled = true;

            Vim.CloseAllVimBuffers();
            Vim.IsDisabled = false;

            // The majority of tests run without a VimRc file but a few do customize it for specific
            // test reasons.  Make sure it's consistent
            VimRcState = VimRcState.None;

            // Reset all of the global settings back to their default values.   Adds quite
            // a bit of sanity to the test bed
            foreach (var setting in Vim.GlobalSettings.Settings)
            {
                if (!setting.IsValueDefault && !setting.IsValueCalculated)
                {
                    Vim.GlobalSettings.TrySetValue(setting.Name, setting.DefaultValue);
                }
            }

            // Reset all of the register values to empty
            foreach (var name in Vim.RegisterMap.RegisterNames)
            {
                Vim.RegisterMap.GetRegister(name).UpdateValue("");
            }

            // Don't let recording persist across tests
            if (Vim.MacroRecorder.IsRecording)
            {
                Vim.MacroRecorder.StopRecording();
            }

            if (Vim.VimHost is MockVimHost vimHost)
            {
                vimHost.ShouldCreateVimBufferImpl = false;
                vimHost.Clear();
            }

            VariableMap.Clear();
            VimErrorDetector.Clear();
            TestableSynchronizationContext?.Dispose();
            TestableSynchronizationContext = null;
        }
Example #14
0
 public void CreateBuffer(params string[] lines)
 {
     _context = new TestableSynchronizationContext();
     SynchronizationContext.SetSynchronizationContext(_context);
     var tuple = EditorUtil.CreateViewAndOperations(lines);
     _textView = tuple.Item1;
     var service = EditorUtil.FactoryService;
     _buffer = service.vim.CreateBuffer(_textView);
     Assert.IsTrue(_context.IsEmpty);
 }
Example #15
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);
                }
Example #16
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);
                }
Example #17
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());
                }
Example #18
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);
                }
Example #19
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());
                }
 protected virtual void Create(params string[] lines)
 {
     _vimBuffer      = CreateVimBuffer(lines);
     _textView       = _vimBuffer.TextView;
     _textBuffer     = _vimBuffer.TextBuffer;
     _globalSettings = _vimBuffer.GlobalSettings;
     _globalSettings.SelectModeOptions = SelectModeOptions.Mouse | SelectModeOptions.Keyboard;
     _textSelection = _textView.Selection;
     _context       = new TestableSynchronizationContext();
     _context.Install();
 }
Example #21
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);
 }
 protected void Create(params string[] lines)
 {
     _vimBuffer = CreateVimBuffer(lines);
     _textView = _vimBuffer.TextView;
     _textBuffer = _vimBuffer.TextBuffer;
     _globalSettings = _vimBuffer.GlobalSettings;
     _globalSettings.SelectModeOptions = SelectModeOptions.Mouse | SelectModeOptions.Keyboard;
     _textSelection = _textView.Selection;
     _context = new TestableSynchronizationContext();
     _context.Install();
 }
Example #23
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);
                }
Example #24
0
 protected virtual void Create(params string[] lines)
 {
     _vimBuffer = CreateVimBuffer(lines);
     _textView = _vimBuffer.TextView;
     _textBuffer = _vimBuffer.TextBuffer;
     _globalSettings = _vimBuffer.GlobalSettings;
     _globalSettings.SelectModeOptions = SelectModeOptions.Mouse | SelectModeOptions.Keyboard;
     _textSelection = _textView.Selection;
     _context = new TestableSynchronizationContext();
     _context.Install();
     _testableMouseDevice = (TestableMouseDevice)MouseDevice;
     _testableMouseDevice.IsLeftButtonPressed = true;
 }
Example #25
0
 public void UsePrompt()
 {
     using (var TestableSynchronizationContext = new TestableSynchronizationContext())
     {
         Create("hello world");
         _asyncTaggerSource.SetPromptTags(_textBuffer.GetSpan(0, 1));
         var tags = _asyncTagger.GetTags(EntireBufferSpan).ToList();
         Assert.Single(tags);
         Assert.Equal(_textBuffer.GetSpan(0, 1), tags[0].Span);
         Assert.True(TestableSynchronizationContext.IsEmpty);
         Assert.True(_asyncTagger.TagCacheData.IsEmpty);
     }
 }
Example #26
0
            public void SimpleGet()
            {
                using (var context = new TestableSynchronizationContext())
                {
                    _source.Text = "cat";
                    _textBuffer.SetText("cat a cat");

                    var list = GetClassificationSpansFull(_textBuffer.GetExtent(), context);
                    Assert.Equal(2, list.Count);
                    Assert.Equal(
                        new[] { new Span(0, 3), new Span(6, 3) },
                        list.Select(x => x.Span.Span));
                }
            }
Example #27
0
            public void ChangeFromComplete()
            {
                using (var context = new TestableSynchronizationContext())
                {
                    _source.Text = "cat";
                    _textBuffer.SetText("cat a cat");

                    _classifier.GetClassificationSpans(_textBuffer.GetExtent());
                    var count = 0;
                    _classifier.ClassificationChanged += delegate { count++; };
                    _asyncTagger.WaitForBackgroundToComplete(context);
                    Assert.Equal(1, count);
                }
            }
Example #28
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);
                }
Example #29
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);
            }
Example #30
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);
                }
Example #31
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);
                }
Example #32
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);
                }
Example #33
0
            public void PrioritizeVisibleLines()
            {
                CreateWithView("dog", "cat", "dog", "bear");
                _mockFactory.SetVisibleLineRange(_mockTextView, _textBuffer.GetLineRange(2));
                _asyncTagger.GetTags(_textBuffer.GetLineRange(0).Extent);
                _asyncTagger.AsyncBackgroundRequestData.Value.Task.Wait();

                // The visible lines will finish first and post.  Let only this one go through
                TestableSynchronizationContext.RunOne();
                var tags = _asyncTagger.GetTags(_textBuffer.GetExtent());

                Assert.Equal(
                    new[] { _textBuffer.GetLineSpan(2, 3) },
                    tags.Select(x => x.Span));
                WaitForBackgroundToComplete();
            }
        protected virtual void Create(params string[] lines)
        {
            _context = new TestableSynchronizationContext();
            SynchronizationContext.SetSynchronizationContext(_context);
            _textView = CreateTextView(lines);
            _textBuffer = _textView.TextBuffer;
            _vimBuffer = Vim.CreateVimBuffer(_textView);
            _vimBuffer.SwitchMode(ModeKind.Normal, ModeArgument.None);
            _vimBufferData = _vimBuffer.VimBufferData;
            _vimTextBuffer = _vimBuffer.VimTextBuffer;
            _registerMap = _vimBuffer.RegisterMap;
            _globalSettings = _vimBuffer.LocalSettings.GlobalSettings;
            Assert.True(_context.IsEmpty);

            // Need to make sure it's focused so macro recording will work
            ((MockVimHost)_vimBuffer.Vim.VimHost).FocusedTextView = _textView;
        }
Example #35
0
        protected VimTestBase()
        {
            // Parts of the core editor in Vs2012 depend on there being an Application.Current value else
            // they will throw a NullReferenceException.  Create one here to ensure the unit tests successfully
            // pass
            if (Application.Current == null)
            {
                new Application();
            }

            if (!StaTaskScheduler.DefaultSta.IsRunningInScheduler)
            {
                throw new Exception($"Need to apply {nameof(WpfFactAttribute)} to this test case");
            }

            if (SynchronizationContext.Current?.GetType() != typeof(DispatcherSynchronizationContext))
            {
                throw new Exception("Invalid synchronization context on test start");
            }

            _vimEditorHost       = GetOrCreateVimEditorHost();
            ClipboardDevice.Text = string.Empty;

            // One setting we do differ on for a default is 'timeout'.  We don't want them interfering
            // with the reliability of tests.  The default is on but turn it off here to prevent any
            // problems
            Vim.GlobalSettings.Timeout = false;

            // Turn off autoloading of digraphs for the vast majority of tests.
            Vim.AutoLoadDigraphs = false;

            // Don't let the personal VimRc of the user interfere with the unit tests
            Vim.AutoLoadVimRc       = false;
            Vim.AutoLoadSessionData = false;

            // Don't let the current directory leak into the tests
            Vim.VimData.CurrentDirectory = "";

            // Don't show trace information in the unit tests.  It really clutters the output in an
            // xUnit run
            VimTrace.TraceSwitch.Level = TraceLevel.Off;

            TestableSynchronizationContext = new TestableSynchronizationContext();
        }
        public SelectionChangeTrackerTest()
        {
            _factory = new MockRepository(MockBehavior.Loose);
            _selection = _factory.Create<ITextSelection>();
            _textView = MockObjectFactory.CreateTextView(
                selection: _selection.Object,
                factory: _factory);
            _vimBuffer = MockObjectFactory.CreateVimBuffer(
                textView: _textView.Object,
                factory: _factory);

            _selectionOverride = _factory.Create<IVisualModeSelectionOverride>();
            _selectionOverride.Setup(x => x.IsInsertModePreferred(It.IsAny<ITextView>())).Returns(false);
            var selectionList = new List<IVisualModeSelectionOverride>();
            selectionList.Add(_selectionOverride.Object);

            _context = new TestableSynchronizationContext();
            _context.Install();
            _tracker = new SelectionChangeTracker(_vimBuffer.Object, selectionList.ToFSharpList());
        }
 public void Setup()
 {
     _factory = new MockRepository(MockBehavior.Loose);
     _selection = _factory.Create<ITextSelection>();
     _textView = MockObjectFactory.CreateTextView(
         selection: _selection.Object,
         factory: _factory);
     _buffer = MockObjectFactory.CreateVimBuffer(
         view: _textView.Object,
         factory: _factory);
     _context = new TestableSynchronizationContext();
     SynchronizationContext.SetSynchronizationContext(_context);
     _tracker = new SelectionChangeTracker(_buffer.Object);
 }
Example #38
0
 public void SetUp()
 {
     _before = SynchronizationContext.Current;
     _context = new TestableSynchronizationContext();
     SynchronizationContext.SetSynchronizationContext(_context);
 }
 public SelectionTrackerTest()
 {
     _before = SynchronizationContext.Current;
     _context = new TestableSynchronizationContext();
     SynchronizationContext.SetSynchronizationContext(_context);
 }
Example #40
0
        internal VsSimulation(IVimBufferCoordinator bufferCoordinator, bool simulateResharper, bool simulateStandardKeyMappings, IEditorOperationsFactoryService editorOperationsFactoryService, IKeyUtil keyUtil)
        {
            _keyUtil = keyUtil;
            _wpfTextView = (IWpfTextView)bufferCoordinator.VimBuffer.TextView;
            _factory = new MockRepository(MockBehavior.Strict);
            _vsKeyboardInputSimulation = new VsKeyboardInputSimulation(this, _wpfTextView);
            _testableSynchronizationContext = new TestableSynchronizationContext();
            _simulateStandardKeyMappings = simulateStandardKeyMappings;

            // Create the IVsAdapter and pick reasonable defaults here.  Consumers can modify 
            // this via an exposed property
            _vsAdapter = _factory.Create<IVsAdapter>();
            _vsAdapter.SetupGet(x => x.InAutomationFunction).Returns(false);
            _vsAdapter.SetupGet(x => x.KeyboardDevice).Returns(_vsKeyboardInputSimulation.KeyBoardDevice);
            _vsAdapter.Setup(x => x.IsReadOnly(It.IsAny<ITextBuffer>())).Returns(false);
            _vsAdapter.Setup(x => x.IsReadOnly(It.IsAny<ITextView>())).Returns(false);
            _vsAdapter.Setup(x => x.IsIncrementalSearchActive(_wpfTextView)).Returns(false);

            _reportDesignerUtil = _factory.Create<IReportDesignerUtil>();
            _reportDesignerUtil.Setup(x => x.IsExpressionView(_wpfTextView)).Returns(false);

            _displayWindowBroker = _factory.Create<IDisplayWindowBroker>();
            _displayWindowBroker.SetupGet(x => x.IsCompletionActive).Returns(false);
            _displayWindowBroker.SetupGet(x => x.IsQuickInfoActive).Returns(false);
            _displayWindowBroker.SetupGet(x => x.IsSignatureHelpActive).Returns(false);
            _displayWindowBroker.SetupGet(x => x.IsSmartTagSessionActive).Returns(false);

            _vimApplicationSettings = _factory.Create<IVimApplicationSettings>();
            _vimApplicationSettings.SetupGet(x => x.UseEditorDefaults).Returns(true);
            _vimApplicationSettings.SetupGet(x => x.UseEditorIndent).Returns(true);
            _vimApplicationSettings.SetupGet(x => x.UseEditorTabAndBackspace).Returns(true);

            _vsSimulationCommandTarget = new SimulationCommandTarget(
                bufferCoordinator.VimBuffer.TextView,
                editorOperationsFactoryService.GetEditorOperations(bufferCoordinator.VimBuffer.TextView));

            var textManager = _factory.Create<ITextManager>();
            var commandTargets = new List<ICommandTarget>();
            if (simulateResharper)
            {
                commandTargets.Add(ReSharperKeyUtil.GetOrCreate(bufferCoordinator));
            }
            commandTargets.Add(new StandardCommandTarget(bufferCoordinator, textManager.Object, _displayWindowBroker.Object, _vsSimulationCommandTarget));

            // Create the VsCommandTarget.  It's next is the final and default Visual Studio 
            // command target
            _vsCommandTarget = new VsCommandTarget(
                bufferCoordinator,
                textManager.Object,
                _vsAdapter.Object,
                _displayWindowBroker.Object,
                _keyUtil,
                _vimApplicationSettings.Object,
                _vsSimulationCommandTarget,
                commandTargets.ToReadOnlyCollectionShallow());

            // Time to setup the start command target.  If we are simulating R# then put them ahead of VsVim
            // on the IOleCommandTarget chain.  VsVim doesn't try to fight R# and prefers instead to be 
            // behind them
            if (simulateResharper)
            {
                _reSharperCommandTarget = new ReSharperCommandTargetSimulation(_wpfTextView, _vsCommandTarget);
                _commandTarget = _reSharperCommandTarget;
            }
            else
            {
                _commandTarget = _vsCommandTarget;
            }

            // Visual Studio hides the default IOleCommandTarget inside of the IWpfTextView property
            // bag.  The default KeyProcessor implementation looks here for IOleCommandTarget to 
            // process text input.  
            //
            // This should always point to the head of the IOleCommandTarget chain.  In the implementation
            // it actually points to the IVsTextView implementation which then immediately routes to the
            // IOleCommandTarget head
            _wpfTextView.Properties[typeof(IOleCommandTarget)] = _commandTarget;

            // Create the input controller.  Make sure that the VsVim one is ahead in the list
            // from the default Visual Studio one.  We can guarantee this is true due to MEF 
            // ordering of the components
            if (simulateResharper)
            {
                _vsKeyboardInputSimulation.KeyProcessors.Add(ReSharperKeyUtil.GetOrCreate(bufferCoordinator));
            }
            _vsKeyboardInputSimulation.KeyProcessors.Add(new VsVimKeyProcessor(_vsAdapter.Object, bufferCoordinator, _keyUtil, _reportDesignerUtil.Object));
            _vsKeyboardInputSimulation.KeyProcessors.Add((KeyProcessor)bufferCoordinator);
            _vsKeyboardInputSimulation.KeyProcessors.Add(new SimulationKeyProcessor(bufferCoordinator.VimBuffer.TextView));
        }
Example #41
0
        public void Create(params string[] lines)
        {
            _context = new TestableSynchronizationContext();
            SynchronizationContext.SetSynchronizationContext(_context);
            var tuple = EditorUtil.CreateTextViewAndEditorOperations(lines);
            _textView = tuple.Item1;
            _textBuffer = _textView.TextBuffer;
            var service = EditorUtil.FactoryService;
            _buffer = service.Vim.CreateVimBuffer(_textView);
            _buffer.SwitchMode(ModeKind.Normal, ModeArgument.None);
            _vimTextBuffer = _buffer.VimTextBuffer;
            _registerMap = _buffer.RegisterMap;
            _globalSettings = _buffer.LocalSettings.GlobalSettings;
            Assert.IsTrue(_context.IsEmpty);

            // Need to make sure it's focused so macro recording will work
            ((MockVimHost)_buffer.Vim.VimHost).FocusedTextView = _textView;
        }
Example #42
0
        internal VsSimulation(IVimBufferCoordinator bufferCoordinator, bool simulateResharper, bool simulateStandardKeyMappings, IEditorOperationsFactoryService editorOperationsFactoryService)
        {
            _wpfTextView = (IWpfTextView)bufferCoordinator.VimBuffer.TextView;
            _factory = new MockRepository(MockBehavior.Strict);
            _defaultKeyboardDevice = new DefaultKeyboardDevice(InputManager.Current);
            _testableSynchronizationContext = new TestableSynchronizationContext();

            // Create the IVsAdapter and pick reasonable defaults here.  Consumers can modify
            // this via an exposed property
            _vsAdapter = _factory.Create<IVsAdapter>();
            _vsAdapter.SetupGet(x => x.InAutomationFunction).Returns(false);
            _vsAdapter.SetupGet(x => x.KeyboardDevice).Returns(_defaultKeyboardDevice);
            _vsAdapter.Setup(x => x.IsReadOnly(It.IsAny<ITextBuffer>())).Returns(false);
            _vsAdapter.Setup(x => x.IsIncrementalSearchActive(_wpfTextView)).Returns(false);

            _resharperUtil = _factory.Create<IResharperUtil>();
            _resharperUtil.SetupGet(x => x.IsInstalled).Returns(simulateResharper);

            _displayWindowBroker = _factory.Create<IDisplayWindowBroker>();
            _displayWindowBroker.SetupGet(x => x.IsCompletionActive).Returns(false);
            _displayWindowBroker.SetupGet(x => x.IsQuickInfoActive).Returns(false);
            _displayWindowBroker.SetupGet(x => x.IsSignatureHelpActive).Returns(false);
            _displayWindowBroker.SetupGet(x => x.IsSmartTagSessionActive).Returns(false);

            _defaultCommandTarget = new DefaultCommandTarget(
                bufferCoordinator.VimBuffer.TextView,
                editorOperationsFactoryService.GetEditorOperations(bufferCoordinator.VimBuffer.TextView));

            // Visual Studio hides the default IOleCommandTarget inside of the IWpfTextView property
            // bag.  The default KeyProcessor implementation looks here for IOleCommandTarget to
            // process text input
            _wpfTextView.Properties[typeof(IOleCommandTarget)] = _defaultCommandTarget;

            // Create the VsCommandTarget.  It's next is the final and default Visual Studio
            // command target
            var vsTextView = _factory.Create<IVsTextView>();
            IOleCommandTarget nextCommandTarget = _defaultCommandTarget;
            vsTextView.Setup(x => x.AddCommandFilter(It.IsAny<IOleCommandTarget>(), out nextCommandTarget)).Returns(VSConstants.S_OK);
            var vsCommandTarget = VsCommandTarget.Create(
                bufferCoordinator,
                vsTextView.Object,
                _vsAdapter.Object,
                _displayWindowBroker.Object,
                _resharperUtil.Object).Value;

            // Time to setup the start command target.  If we are simulating R# then put them ahead of VsVim
            // on the IOleCommandTarget chain.  VsVim doesn't try to fight R# and prefers instead to be
            // behind them
            if (simulateResharper)
            {
                var resharperCommandTarget = new ResharperCommandTarget(_wpfTextView, vsCommandTarget);
                _commandTarget = resharperCommandTarget;
            }
            else
            {
                _commandTarget = vsCommandTarget;
            }

            // Create the input controller.  Make sure that the VsVim one is ahead in the list
            // from the default Visual Studio one.  We can guarantee this is true due to MEF
            // ordering of the components
            var keyProcessors = new List<Microsoft.VisualStudio.Text.Editor.KeyProcessor>();
            keyProcessors.Add(new VsKeyProcessor(_vsAdapter.Object, bufferCoordinator));
            keyProcessors.Add(new SimulationKeyProcessor(bufferCoordinator.VimBuffer.TextView));
            _defaultInputController = new DefaultInputController(bufferCoordinator.VimBuffer.TextView, keyProcessors);
        }