Beispiel #1
0
        protected VimTest()
        {
            _factory = new MockRepository(MockBehavior.Strict);
            _globalSettings = new GlobalSettings();
            _fileSystem = _factory.Create<IFileSystem>(MockBehavior.Strict);
            _bufferFactory = VimBufferFactory;
            _simpleListener = new SimpleListener();
            var creationListeners = new [] { new Lazy<IVimBufferCreationListener>(() => _simpleListener) };

            var map = new Dictionary<string, VariableValue>();
            _keyMap = new KeyMap(_globalSettings, map);
            _vimHost = _factory.Create<IVimHost>(MockBehavior.Strict);
            _vimHost.Setup(x => x.CreateHiddenTextView()).Returns(CreateTextView());
            _vimHost.Setup(x => x.AutoSynchronizeSettings).Returns(true);
            _vimRaw = new Vim(
                _vimHost.Object,
                _bufferFactory,
                CompositionContainer.GetExportedValue<IVimInterpreterFactory>(),
                creationListeners.ToFSharpList(),
                _globalSettings,
                _factory.Create<IMarkMap>().Object,
                _keyMap,
                MockObjectFactory.CreateClipboardDevice().Object,
                _factory.Create<ISearchService>().Object,
                _fileSystem.Object,
                new VimData(_globalSettings),
                _factory.Create<IBulkOperations>().Object,
                map,
                new EditorToSettingSynchronizer());
            _vim = _vimRaw;
            _vim.AutoLoadVimRc = false;
        }
Beispiel #2
0
        /// <summary>
        /// Go to the 'count' tab in the given direction.  If the count exceeds the count in
        /// the given direction then it should wrap around to the end of the list of items
        /// </summary>
        internal void GoToNextTab(Vim.Path direction, int count)
        {
            // First get the index of the current tab so we know where we are incrementing
            // from.  Make sure to check that our view is actually a part of the active
            // views
            var children = GetActiveViews();
            var activeView = ViewManager.Instance.ActiveView;
            var index = children.IndexOf(activeView);
            if (index == -1)
            {
                return;
            }

            count = count % children.Count;
            if (direction.IsForward)
            {
                index += count;
                index %= children.Count;
            }
            else
            {
                index -= count;
                if (index < 0)
                {
                    index += children.Count;
                }
            }

            children[index].ShowInFront();
        }
Beispiel #3
0
        private IVimBuffer CreateVimBuffer()
        {
            var container = GetOrCreateCompositionContainer();
            var factory   = container.GetExport <ITextEditorFactoryService>().Value;
            var textView  = factory.CreateTextView();

            // Verify we actually created the IVimBuffer instance
            var vimBuffer = Vim.GetOrCreateVimBuffer(textView);

            Assert.NotNull(vimBuffer);

            // Do one round of DoEvents since several services queue up actions to
            // take immediately after the IVimBuffer is created
            for (var i = 0; i < 10; i++)
            {
                Dispatcher.CurrentDispatcher.DoEvents();
            }

            return(vimBuffer);
        }
Beispiel #4
0
        protected VsCommandTargetTest(bool isReSharperInstalled)
        {
            _textView          = CreateTextView("");
            _textBuffer        = _textView.TextBuffer;
            _vimBuffer         = Vim.CreateVimBuffer(_textView);
            _bufferCoordinator = new VimBufferCoordinator(_vimBuffer);
            _vim     = _vimBuffer.Vim;
            _factory = new MockRepository(MockBehavior.Strict);

            _nextTarget = _factory.Create <IOleCommandTarget>(MockBehavior.Strict);
            _vsAdapter  = _factory.Create <IVsAdapter>();
            _vsAdapter.SetupGet(x => x.KeyboardDevice).Returns(InputManager.Current.PrimaryKeyboardDevice);
            _vsAdapter.Setup(x => x.InAutomationFunction).Returns(false);
            _vsAdapter.Setup(x => x.InDebugMode).Returns(false);
            _vsAdapter.Setup(x => x.IsIncrementalSearchActive(It.IsAny <ITextView>())).Returns(false);

            _broker                 = _factory.Create <IDisplayWindowBroker>(MockBehavior.Loose);
            _textManager            = _factory.Create <ITextManager>();
            _vimApplicationSettings = _factory.Create <IVimApplicationSettings>();

            var commandTargets = new List <ICommandTarget>();

            if (isReSharperInstalled)
            {
                commandTargets.Add(ReSharperKeyUtil.GetOrCreate(_bufferCoordinator));
            }
            commandTargets.Add(new StandardCommandTarget(_bufferCoordinator, _textManager.Object, _broker.Object, _nextTarget.Object));

            var oldCommandFilter = _nextTarget.Object;

            _targetRaw = new VsCommandTarget(
                _bufferCoordinator,
                _textManager.Object,
                _vsAdapter.Object,
                _broker.Object,
                KeyUtil,
                _vimApplicationSettings.Object,
                _nextTarget.Object,
                commandTargets.ToReadOnlyCollectionShallow());
            _target = _targetRaw;
        }
        private void Create(params string[] lines)
        {
            _vimHost = (MockVimHost)Vim.VimHost;
            _textView = CreateTextView(lines);
            _globalSettings = Vim.GlobalSettings;
            _globalSettings.IncrementalSearch = true;
            _globalSettings.WrapScan = true;

            var vimTextBuffer = Vim.CreateVimTextBuffer(_textView.TextBuffer);

            _factory = new MockRepository(MockBehavior.Strict);
            _statusUtil = _factory.Create<IStatusUtil>();
            _statusUtil.Setup(x => x.OnWarning(Resources.Common_SearchBackwardWrapped));
            _statusUtil.Setup(x => x.OnWarning(Resources.Common_SearchForwardWrapped));

            _vimData = Vim.VimData;
            var vimBufferData = CreateVimBufferData(vimTextBuffer, _textView);
            var operations = CommonOperationsFactory.GetCommonOperations(vimBufferData);
            _searchRaw = new IncrementalSearch(vimBufferData, operations);
            _search = _searchRaw;
        }
            public void CloseBufferDuringRecord()
            {
                var textView2  = CreateTextView("another buffer");
                var vimBuffer2 = Vim.CreateVimBuffer(textView2);

                vimBuffer2.SwitchMode(ModeKind.Normal, ModeArgument.None);

                Create("hello world");

                // Stand-in for HostFactory which calls IVimBuffer.Close in response to the associated ITextView.Closed.
                // The root cause of the referenced issue was that MacroRecorder disposed its buffer event handlers on IVimBuffer.Close.
                // Since IVimBuffer.Close is raised before the final IVimBuffer.KeyInputEnd is raised, the last keystroke failed to record.
                _textView.Closed += (s, e) => _vimBuffer.Close();

                _vimBuffer.Process("qaZQ");
                Assert.True(_vimBuffer.IsClosed);

                VimHost.FocusedTextView = textView2;
                vimBuffer2.Process("q");
                Assert.Equal("ZQ", _vimBuffer.GetRegister('a').StringValue);
            }
Beispiel #7
0
 private void CreateVim()
 {
     var creationListeners = new [] { new Lazy<IVimBufferCreationListener>(() => _simpleListener) };
     _vimRaw = new Vim(
         _vimHost.Object,
         _bufferFactory,
         CompositionContainer.GetExportedValue<IVimInterpreterFactory>(),
         creationListeners.ToFSharpList(),
         _globalSettings,
         _factory.Create<IMarkMap>().Object,
         _keyMap,
         MockObjectFactory.CreateClipboardDevice().Object,
         _factory.Create<ISearchService>().Object,
         _fileSystem.Object,
         new VimData(_globalSettings),
         _factory.Create<IBulkOperations>().Object,
         _variableMap,
         new EditorToSettingSynchronizer());
     _vim = _vimRaw;
     _vim.AutoLoadVimRc = false;
 }
Beispiel #8
0
        private void Create(params string[] lines)
        {
            _textView      = CreateTextView(lines);
            _vimTextBuffer = Vim.CreateVimTextBuffer(_textView.TextBuffer);
            _registerMap   = Vim.RegisterMap;
            var vimBufferData = CreateVimBufferData(
                _vimTextBuffer,
                _textView);

            _commandUtil = VimUtil.CreateCommandUtil(vimBufferData);
            var motionCapture = VimUtil.CreateMotionCapture(vimBufferData);

            _runnerRaw = new CommandRunner(
                _textView,
                _registerMap,
                motionCapture,
                _commandUtil,
                new StatusUtil(),
                VisualKind.Character);
            _runner = _runnerRaw;
        }
        protected VsCommandTargetTest()
        {
            _textView          = CreateTextView("");
            _textBuffer        = _textView.TextBuffer;
            _vimBuffer         = Vim.CreateVimBuffer(_textView);
            _bufferCoordinator = new VimBufferCoordinator(_vimBuffer);
            _vim     = _vimBuffer.Vim;
            _factory = new MockRepository(MockBehavior.Strict);

            // By default Resharper isn't loaded
            _resharperUtil = _factory.Create <IReSharperUtil>();
            _resharperUtil.SetupGet(x => x.IsInstalled).Returns(false);

            _nextTarget = _factory.Create <IOleCommandTarget>(MockBehavior.Strict);
            _vsAdapter  = _factory.Create <IVsAdapter>();
            _vsAdapter.SetupGet(x => x.KeyboardDevice).Returns(InputManager.Current.PrimaryKeyboardDevice);
            _vsAdapter.Setup(x => x.InAutomationFunction).Returns(false);
            _vsAdapter.Setup(x => x.InDebugMode).Returns(false);
            _vsAdapter.Setup(x => x.IsIncrementalSearchActive(It.IsAny <ITextView>())).Returns(false);

            _broker      = _factory.Create <IDisplayWindowBroker>(MockBehavior.Loose);
            _textManager = _factory.Create <ITextManager>();

            var oldCommandFilter = _nextTarget.Object;
            var vsTextView       = _factory.Create <IVsTextView>(MockBehavior.Loose);

            vsTextView.Setup(x => x.AddCommandFilter(It.IsAny <IOleCommandTarget>(), out oldCommandFilter)).Returns(0);
            var result = VsCommandTarget.Create(
                _bufferCoordinator,
                vsTextView.Object,
                _textManager.Object,
                _vsAdapter.Object,
                _broker.Object,
                _resharperUtil.Object,
                KeyUtil);

            Assert.True(result.IsSuccess);
            _targetRaw = result.Value;
            _target    = _targetRaw;
        }
        public void Create(bool hasTextLines, bool hasTagger, params string[] lines)
        {
            _factory    = new MockRepository(MockBehavior.Loose);
            _textView   = CreateTextView(lines);
            _textBuffer = _textView.TextBuffer;
            _buffer     = Vim.CreateVimBuffer(_textView);

            // Have adatper ignore by default
            _adapter = _factory.Create <IExternalEditAdapter>(MockBehavior.Strict);
            _adapter.Setup(x => x.IsExternalEditTag(It.IsAny <ITag>())).Returns(false);
            _adapter.Setup(x => x.IsExternalEditMarker(It.IsAny <IVsTextLineMarker>())).Returns(false);
            var adapterList = new List <IExternalEditAdapter> {
                _adapter.Object
            };

            Result <IVsTextLines> textLines = Result.Error;

            if (hasTextLines)
            {
                _vsTextLines = _factory.Create <IVsTextLines>(MockBehavior.Strict);
                _vsTextLines.SetupNoEnumMarkers();
                textLines = Result.CreateSuccess(_vsTextLines.Object);
            }

            var taggerList = new List <ITagger <ITag> >();

            if (hasTagger)
            {
                _tagger = _factory.Create <ITagger <ITag> >(MockBehavior.Loose);
                _tagger.Setup(x => x.GetTags(It.IsAny <NormalizedSnapshotSpanCollection>())).Returns(new List <ITagSpan <ITag> >());
                taggerList.Add(_tagger.Object);
            }

            _monitor = new ExternalEditMonitor(
                _buffer,
                ProtectedOperations,
                textLines,
                taggerList.ToReadOnlyCollectionShallow(),
                adapterList.ToReadOnlyCollectionShallow());
        }
Beispiel #11
0
        private void Create(KeyRemapMode countKeyRemapMode, params string[] lines)
        {
            _textView      = CreateTextView(lines);
            _vimTextBuffer = Vim.CreateVimTextBuffer(_textView.TextBuffer);
            _registerMap   = Vim.RegisterMap;
            var vimBufferData = CreateVimBufferData(
                _vimTextBuffer,
                _textView);

            _commandUtil = CreateCommandUtil(vimBufferData);
            var incrementalSearch = new IncrementalSearch(
                vimBufferData,
                CommonOperationsFactory.GetCommonOperations(vimBufferData));
            var motionCapture = new MotionCapture(vimBufferData, incrementalSearch);

            _runnerRaw = new CommandRunner(
                vimBufferData,
                motionCapture,
                _commandUtil,
                VisualKind.Character,
                countKeyRemapMode);
            _runner = _runnerRaw;
        }
Beispiel #12
0
        private void CreateVim()
        {
            var creationListeners = new [] { new Lazy <IVimBufferCreationListener>(() => _simpleListener) };

            _vimRaw = new Vim(
                _vimHost.Object,
                _bufferFactory,
                CompositionContainer.GetExportedValue <IVimInterpreterFactory>(),
                creationListeners.ToFSharpList(),
                _globalSettings,
                _factory.Create <IMarkMap>().Object,
                _keyMap,
                MockObjectFactory.CreateClipboardDevice().Object,
                _factory.Create <ISearchService>().Object,
                _fileSystem.Object,
                new VimData(_globalSettings),
                _factory.Create <IBulkOperations>().Object,
                _variableMap,
                new EditorToSettingSynchronizer(),
                new StatusUtilFactory());
            _vim = _vimRaw;
            _vim.AutoLoadVimRc = false;
        }
Beispiel #13
0
 /// <summary>
 /// Create a Visual Studio simulation with the specified set of lines
 /// </summary>
 private void CreateCore(bool simulateResharper, bool usePeekRole, params string[] lines)
 {
     if (usePeekRole)
     {
         _textBuffer = CreateTextBuffer(lines);
         _textView   = TextEditorFactoryService.CreateTextView(
             _textBuffer,
             TextEditorFactoryService.CreateTextViewRoleSet(PredefinedTextViewRoles.Document, PredefinedTextViewRoles.Editable, Constants.TextViewRoleEmbeddedPeekTextView));
     }
     else
     {
         _textView   = CreateTextView(lines);
         _textBuffer = _textView.TextBuffer;
     }
     _vimBuffer         = Vim.CreateVimBuffer(_textView);
     _bufferCoordinator = new VimBufferCoordinator(_vimBuffer);
     _vsSimulation      = new VsSimulation(
         _bufferCoordinator,
         simulateResharper: simulateResharper,
         simulateStandardKeyMappings: false,
         editorOperationsFactoryService: EditorOperationsFactoryService,
         keyUtil: KeyUtil);
 }
Beispiel #14
0
        private void Create2(
            ModeKind kind = ModeKind.VisualCharacter,
            params string[] lines)
        {
            _textView   = CreateTextView(lines);
            _textBuffer = _textView.TextBuffer;
            var vimTextBuffer = Vim.CreateVimTextBuffer(_textBuffer);
            var vimBufferData = CreateVimBufferData(vimTextBuffer, _textView);
            var visualKind    = VisualKind.OfModeKind(kind).Value;

            _selection = _textView.Selection;
            _factory   = new MockRepository(MockBehavior.Strict);
            _tracker   = _factory.Create <ISelectionTracker>();
            _tracker.Setup(x => x.Start());
            _tracker.Setup(x => x.UpdateSelection());
            _tracker.Setup(x => x.RecordCaretTrackingPoint(It.IsAny <ModeArgument>()));
            _tracker.SetupGet(x => x.IsRunning).Returns(true);
            _operations = _factory.Create <ICommonOperations>();
            _operations.SetupGet(x => x.TextView).Returns(_textView);
            _operations.Setup(x => x.MoveCaretToPoint(It.IsAny <SnapshotPoint>(), ViewFlags.Standard));
            _commandUtil = _factory.Create <ICommandUtil>();
            var motionUtil = new MotionUtil(vimBufferData, _operations.Object);
            var capture    = new MotionCapture(vimBufferData, new IncrementalSearch(vimBufferData, _operations.Object));
            var runner     = new CommandRunner(
                _textView,
                Vim.RegisterMap,
                capture,
                vimBufferData.LocalSettings,
                _commandUtil.Object,
                (new Mock <IStatusUtil>()).Object,
                VisualKind.Character,
                KeyRemapMode.Visual);

            _modeRaw = new VisualMode(vimBufferData, _operations.Object, motionUtil, visualKind, runner, capture, _tracker.Object);
            _mode    = _modeRaw;
            _mode.OnEnter(ModeArgument.None);
        }
Beispiel #15
0
 public VimRcTest()
 {
     _vim = (Vim)Vim;
     _globalSettings = Vim.GlobalSettings;
     _fileSystem = new Mock<IFileSystem>();
     _originalFileSystem = _vim._fileSystem;
     _vim._fileSystem = _fileSystem.Object;
     VimHost.CreateHiddenTextViewFunc = () => TextEditorFactoryService.CreateTextView();
 }
Beispiel #16
0
        protected void Create(bool insertMode, params string[] lines)
        {
            _factory = new MockRepository(MockBehavior.Strict)
            {
                DefaultValue = DefaultValue.Mock
            };
            _textView          = CreateTextView(lines);
            _textBuffer        = _textView.TextBuffer;
            _vim               = _factory.Create <IVim>(MockBehavior.Loose);
            _editorOptions     = _factory.Create <IEditorOptions>(MockBehavior.Loose);
            _textChangeTracker = _factory.Create <ITextChangeTracker>(MockBehavior.Loose);
            _textChangeTracker.SetupGet(x => x.CurrentChange).Returns(FSharpOption <TextChange> .None);
            _undoRedoOperations = new UndoRedoOperations(VimHost, new StatusUtil(), FSharpOption <ITextUndoHistory> .None, null);
            _wordCompletionSessionFactoryService = _factory.Create <IWordCompletionSessionFactoryService>();

            var localSettings = new LocalSettings(Vim.GlobalSettings);

            _vimBuffer      = Vim.CreateVimBuffer(_textView);
            _globalSettings = _vimBuffer.GlobalSettings;
            var vimTextBuffer = Vim.GetOrCreateVimTextBuffer(_textView.TextBuffer);
            var vimBufferData = CreateVimBufferData(vimTextBuffer, _textView);

            _operations = CommonOperationsFactory.GetCommonOperations(vimBufferData);
            _broker     = _factory.Create <IDisplayWindowBroker>();
            _broker.SetupGet(x => x.IsCompletionActive).Returns(false);
            _broker.SetupGet(x => x.IsQuickInfoActive).Returns(false);
            _broker.SetupGet(x => x.IsSignatureHelpActive).Returns(false);
            _insertUtil = _factory.Create <IInsertUtil>();
            _insertUtil.Setup(x => x.NewUndoSequence());
            _motionUtil  = _factory.Create <IMotionUtil>();
            _commandUtil = _factory.Create <ICommandUtil>();
            _capture     = _factory.Create <IMotionCapture>();

            // Setup the mouse.  By default we say it has no buttons down as that's the normal state
            _mouseDevice = _factory.Create <IMouseDevice>();
            _mouseDevice.SetupGet(x => x.IsLeftButtonPressed).Returns(false);

            // Setup the keyboard.  By default we don't say that any button is pressed.  Insert mode is usually
            // only concerned with arrow keys and we will set those up as appropriate for the typing tests
            _keyboardDevice = _factory.Create <IKeyboardDevice>();
            _keyboardDevice.Setup(x => x.IsArrowKeyDown).Returns(false);

            _modeRaw = new global::Vim.Modes.Insert.InsertMode(
                _vimBuffer,
                _operations,
                _broker.Object,
                _editorOptions.Object,
                _undoRedoOperations,
                _textChangeTracker.Object,
                _insertUtil.Object,
                _motionUtil.Object,
                _commandUtil.Object,
                _capture.Object,
                !insertMode,
                _keyboardDevice.Object,
                _mouseDevice.Object,
                _wordCompletionSessionFactoryService.Object);
            _mode = _modeRaw;
            _mode.OnEnter(ModeArgument.None);
            _mode.CommandRan += (sender, e) => { _lastCommandRan = e.CommandRunData; };
        }
Beispiel #17
0
 protected IVimBuffer CreateVimBufferWithName(string fileName, params string[] lines)
 {
     var textView = CreateTextView(lines);
     textView.TextBuffer.Properties[MockVimHost.FileNameKey] = fileName;
     return Vim.CreateVimBuffer(textView);
 }
 void ISharedService.GoToNextTab(Vim.Path path, int count)
 {
 }
Beispiel #19
0
 public void Setup()
 {
     _factory = new MockRepository(MockBehavior.Strict);
     _settings = new GlobalSettings();
     _markMap = _factory.Create<IMarkMap>(MockBehavior.Strict);
     _fileSystem = _factory.Create<IFileSystem>(MockBehavior.Strict);
     _bufferFactory = VimBufferFactory;
     _keyMap = new KeyMap();
     _vimHost = _factory.Create<IVimHost>(MockBehavior.Strict);
     _searchInfo = _factory.Create<ISearchService>(MockBehavior.Strict);
     _vimRaw = new Vim(
         _vimHost.Object,
         _bufferFactory,
         FSharpList<Lazy<IVimBufferCreationListener>>.Empty,
         _settings,
         _markMap.Object,
         _keyMap,
         MockObjectFactory.CreateClipboardDevice().Object,
         _searchInfo.Object,
         _fileSystem.Object,
         new VimData());
     _vim = _vimRaw;
     _vim.AutoLoadVimRc = false;
 }
Beispiel #20
0
 private void RunNone()
 {
     _fileSystem.Setup(x => x.LoadVimRcContents()).Returns(FSharpOption <FileContents> .None);
     Assert.True(Vim.LoadVimRc().IsLoadFailed);
 }
Beispiel #21
0
        /// <summary>
        /// Go to the 'count' tab in the given direction.  If the count exceeds the count in
        /// the given direction then it should wrap around to the end of the list of items
        /// </summary>
        public override void GoToNextTab(Vim.Path direction, int count)
        {
            // First get the index of the current tab so we know where we are incrementing
            // from.  Make sure to check that our view is actually a part of the active
            // views
            var windowFrameState = _sharedService.GetWindowFrameState();
            var index = windowFrameState.ActiveWindowFrameIndex;
            if (index == -1)
            {
                return;
            }

            var childCount = windowFrameState.WindowFrameCount;
            count = count % childCount;
            if (direction.IsForward)
            {
                index += count;
                index %= childCount;
            }
            else
            {
                index -= count;
                if (index < 0)
                {
                    index += childCount;
                }
            }

            _sharedService.GoToTab(index);
        }
Beispiel #22
0
 public VimSceneNode GetVimNodeFromId(int id)
 => ElementIndexToSceneNode.GetOrDefault(Vim.ElementIndexFromId(id));
Beispiel #23
0
        public override void GoToNextTab(Vim.Path direction, int count)
        {
            var children = GetActiveViews();
            var activeView = ViewManager.Instance.ActiveView;
            var index = children.IndexOf(activeView);
            if (index == -1)
            {
                return;
            }

            if (direction.IsForward)
            {
                index += count;
            }
            else
            {
                index -= count;
            }

            index %= children.Count;
            children[index].ShowInFront();
        }
Beispiel #24
0
 protected void Create(params string[] lines)
 {
     _textView   = CreateTextView(lines);
     _textBuffer = _textView.TextBuffer;
     _vimBuffer  = Vim.CreateVimBuffer(_textView);
 }
Beispiel #25
0
            public void RemoveBuffer1()
            {
                var view = new Mock <IWpfTextView>(MockBehavior.Strict);

                Assert.False(Vim.RemoveVimBuffer(view.Object));
            }
Beispiel #26
0
 private void CreateBuffer(params string[] lines)
 {
     _textView = CreateTextView(lines);
     _buffer   = Vim.CreateVimBuffer(_textView);
 }
Beispiel #27
0
 public VimRcTest()
 {
     _vim = (Vim)Vim;
     _globalSettings = Vim.GlobalSettings;
     _fileSystem = new Mock<IFileSystem>();
     _fileSystem.Setup(x => x.GetVimRcDirectories()).Returns(new string[] { });
     _originalFileSystem = _vim.FileSystem;
     _vim.FileSystem = _fileSystem.Object;
     VimHost.CreateHiddenTextViewFunc = () => TextEditorFactoryService.CreateTextView();
 }
Beispiel #28
0
 private void CreateVim()
 {
     var creationListeners = new[] { new Lazy<IVimBufferCreationListener>(() => _simpleListener) };
     var markMap = _factory.Create<IMarkMap>();
     markMap.Setup(x => x.SetMark(Mark.LastJump, It.IsAny<IVimBufferData>(), 0, 0)).Returns(true);
     markMap.Setup(x => x.SetLastExitedPosition("VimTest.cs", 0, 0)).Returns(true);
     _vimRaw = new Vim(
         _vimHost.Object,
         _bufferFactory,
         CompositionContainer.GetExportedValue<IVimInterpreterFactory>(),
         creationListeners.ToFSharpList(),
         _globalSettings,
         markMap.Object,
         _keyMap,
         MockObjectFactory.CreateClipboardDevice().Object,
         _factory.Create<ISearchService>().Object,
         _fileSystem.Object,
         new VimData(_globalSettings),
         _factory.Create<IBulkOperations>().Object,
         _variableMap,
         new EditorToSettingSynchronizer(),
         new StatusUtilFactory());
     _vim = _vimRaw;
     _vim.AutoLoadVimRc = false;
     _vim.AutoLoadSessionData = false;
 }
Beispiel #29
0
        public virtual void Dispose()
        {
            Vim.MarkMap.Clear();

            if (VimErrorDetector.HasErrors())
            {
                var msg = String.Format("Extension Exception: {0}", VimErrorDetector.GetErrors().First().Message);

                // Need to clear before we throw or every subsequent test will fail with the same error
                VimErrorDetector.Clear();

                throw new Exception(msg);
            }
            VimErrorDetector.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.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.AllSettings)
            {
                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();
            }

            var vimHost = Vim.VimHost as MockVimHost;

            if (vimHost != null)
            {
                vimHost.ShouldCreateVimBufferImpl = false;
                vimHost.Clear();
            }

            VariableMap.Clear();
        }
Beispiel #30
0
 /// <summary>
 /// Go to the 'count' tab in the given direction.  If the count exceeds the count in
 /// the given direction then it should wrap around to the end of the list of items
 /// </summary>
 public override void GoToNextTab(Vim.Path direction, int count)
 {
     _sharedService.GoToNextTab(direction, count);
 }
Beispiel #31
0
 public Element GetElementFromId(int id)
 => Vim.ElementFromId(id);
Beispiel #32
0
        /// <summary>
        /// Create an IVimBuffer instance with the given lines
        /// </summary>
        protected IVimBuffer CreateVimBuffer(params string[] lines)
        {
            var textView = CreateTextView(lines);

            return(Vim.CreateVimBuffer(textView));
        }
Beispiel #33
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.DigraphMap.Clear();
            Vim.KeyMap.IsZeroMappingEnabled = true;

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

            // If digraphs were loaded, reload them.
            if (Vim.AutoLoadDigraphs)
            {
                DigraphUtil.AddToMap(Vim.DigraphMap, DigraphUtil.DefaultDigraphs);
            }

            // 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;
        }
Beispiel #34
0
        /// <summary>
        /// Create an IVimTextBuffer instance with the given lines
        /// </summary>
        protected IVimTextBuffer CreateVimTextBuffer(params string[] lines)
        {
            var textBuffer = CreateTextBuffer(lines);

            return(Vim.CreateVimTextBuffer(textBuffer));
        }
Beispiel #35
-1
        public VimTest()
        {
            _factory = new MockRepository(MockBehavior.Strict);
            _globalSettings = new GlobalSettings();
            _markMap = _factory.Create<IMarkMap>(MockBehavior.Strict);
            _fileSystem = _factory.Create<IFileSystem>(MockBehavior.Strict);
            _bufferFactory = VimBufferFactory;

            var map = new Dictionary<string, VariableValue>();
            _keyMap = new KeyMap(_globalSettings, map);
            _vimHost = _factory.Create<IVimHost>(MockBehavior.Strict);
            _searchInfo = _factory.Create<ISearchService>(MockBehavior.Strict);
            _vimRaw = new Vim(
                _vimHost.Object,
                _bufferFactory,
                FSharpList<Lazy<IVimBufferCreationListener>>.Empty,
                _globalSettings,
                _markMap.Object,
                _keyMap,
                MockObjectFactory.CreateClipboardDevice().Object,
                _searchInfo.Object,
                _fileSystem.Object,
                new VimData(),
                _factory.Create<IBulkOperations>().Object,
                map);
            _vim = _vimRaw;
            _vim.AutoLoadVimRc = false;
        }