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);
        }
Пример #2
0
        public void Create2(
            ModeKind kind = ModeKind.VisualCharacter,
            params string[] lines)
        {
            _textView   = EditorUtil.CreateView(lines);
            _textBuffer = _textView.TextBuffer;
            _selection  = _textView.Selection;
            _factory    = new MockRepository(MockBehavior.Strict);
            _map        = VimUtil.CreateRegisterMap(MockObjectFactory.CreateClipboardDevice(_factory).Object);
            _markMap    = new MarkMap(new TrackingLineColumnService());
            _tracker    = _factory.Create <ISelectionTracker>();
            _tracker.Setup(x => x.Start());
            _tracker.Setup(x => x.ResetCaret());
            _tracker.Setup(x => x.UpdateSelection());
            _jumpList           = _factory.Create <IJumpList>(MockBehavior.Loose);
            _undoRedoOperations = _factory.Create <IUndoRedoOperations>();
            _foldManager        = _factory.Create <IFoldManager>();
            _editorOperations   = _factory.Create <IEditorOperations>();
            _operations         = _factory.Create <ICommonOperations>();
            _operations.SetupGet(x => x.FoldManager).Returns(_foldManager.Object);
            _operations.SetupGet(x => x.UndoRedoOperations).Returns(_undoRedoOperations.Object);
            _operations.SetupGet(x => x.EditorOperations).Returns(_editorOperations.Object);
            _operations.SetupGet(x => x.TextView).Returns(_textView);
            _host        = _factory.Create <IVimHost>(MockBehavior.Loose);
            _commandUtil = _factory.Create <ICommandUtil>();
            _commandUtil
            .Setup(x => x.RunCommand(It.Is <Command>(y => y.IsLegacyCommand)))
            .Returns <Command>(c => c.AsLegacyCommand().Item.Function.Invoke(null));
            _incrementalSearch = MockObjectFactory.CreateIncrementalSearch(factory: _factory);
            var globalSettings = new GlobalSettings();
            var localSettings  = new LocalSettings(globalSettings, _textView);
            var motionUtil     = VimUtil.CreateTextViewMotionUtil(
                _textView,
                _markMap,
                localSettings);

            _bufferData = MockObjectFactory.CreateVimBuffer(
                _textView,
                "test",
                MockObjectFactory.CreateVim(_map, host: _host.Object, settings: globalSettings).Object,
                incrementalSearch: _incrementalSearch.Object,
                jumpList: _jumpList.Object,
                motionUtil: motionUtil);
            var capture = new MotionCapture(
                _host.Object,
                _textView,
                _incrementalSearch.Object,
                localSettings);
            var runner = new CommandRunner(
                _textView,
                _map,
                capture,
                _commandUtil.Object,
                (new Mock <IStatusUtil>()).Object,
                VisualKind.Character);

            _modeRaw = new VisualMode(_bufferData.Object, _operations.Object, kind, runner, capture, _tracker.Object);
            _mode    = _modeRaw;
            _mode.OnEnter(ModeArgument.None);
        }
Пример #3
0
 public void SetUp(bool insertMode)
 {
     _factory = new MockRepository(MockBehavior.Strict);
     _factory.DefaultValue = DefaultValue.Mock;
     _textView             = EditorUtil.CreateView();
     _vim            = _factory.Create <IVim>(MockBehavior.Loose);
     _editorOptions  = _factory.Create <IEditorOptions>(MockBehavior.Loose);
     _globalSettings = _factory.Create <IVimGlobalSettings>();
     _localSettings  = _factory.Create <IVimLocalSettings>();
     _localSettings.SetupGet(x => x.GlobalSettings).Returns(_globalSettings.Object);
     _textChangeTracker = _factory.Create <ITextChangeTracker>();
     _textChangeTracker.SetupGet(x => x.CurrentChange).Returns(FSharpOption <TextChange> .None);
     _undoRedoOperations = _factory.Create <IUndoRedoOperations>();
     _data = MockObjectFactory.CreateVimBuffer(
         _textView,
         settings: _localSettings.Object,
         vim: _vim.Object,
         factory: _factory);
     _operations = _factory.Create <ICommonOperations>();
     _operations.SetupGet(x => x.EditorOperations).Returns(_factory.Create <IEditorOperations>().Object);
     _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);
     _modeRaw = new Vim.Modes.Insert.InsertMode(
         _data.Object,
         _operations.Object,
         _broker.Object,
         _editorOptions.Object,
         _undoRedoOperations.Object,
         _textChangeTracker.Object,
         _isReplace: !insertMode);
     _mode = _modeRaw;
 }
Пример #4
0
        internal static CommandUtil CreateCommandUtil(
            ITextView textView,
            ICommonOperations operations                     = null,
            IMotionUtil motionUtil                           = null,
            IStatusUtil statusUtil                           = null,
            IRegisterMap registerMap                         = null,
            IMarkMap markMap                                 = null,
            IVimData vimData                                 = null,
            IVimLocalSettings localSettings                  = null,
            IUndoRedoOperations undoRedOperations            = null,
            ISmartIndentationService smartIndentationService = null,
            IFoldManager foldManager                         = null,
            IVimHost vimHost                                 = null,
            IMacroRecorder recorder                          = null,
            ISearchService searchService                     = null,
            ITextStructureNavigator wordNavigator            = null,
            IJumpList jumpList                               = null)
        {
            statusUtil              = statusUtil ?? new StatusUtil();
            undoRedOperations       = undoRedOperations ?? VimUtil.CreateUndoRedoOperations(statusUtil);
            localSettings           = localSettings ?? new LocalSettings(new GlobalSettings());
            registerMap             = registerMap ?? CreateRegisterMap(MockObjectFactory.CreateClipboardDevice().Object);
            markMap                 = markMap ?? new MarkMap(new TrackingLineColumnService());
            vimData                 = vimData ?? new VimData();
            motionUtil              = motionUtil ?? CreateTextViewMotionUtil(textView, markMap: markMap, vimData: vimData, settings: localSettings);
            operations              = operations ?? CreateCommonOperations(textView, localSettings, vimData: vimData, statusUtil: statusUtil);
            smartIndentationService = smartIndentationService ?? CreateSmartIndentationService();
            foldManager             = foldManager ?? CreateFoldManager(textView.TextBuffer);
            searchService           = searchService ?? CreateSearchService(localSettings.GlobalSettings);
            wordNavigator           = wordNavigator ?? CreateTextStructureNavigator(textView.TextBuffer, WordKind.NormalWord);
            jumpList                = jumpList ?? CreateJumpList();
            vimHost                 = vimHost ?? new MockVimHost();
            var vim = MockObjectFactory.CreateVim(
                registerMap: registerMap,
                map: markMap,
                host: vimHost,
                vimData: vimData,
                recorder: recorder,
                searchService: searchService);
            var buffer = MockObjectFactory.CreateVimBuffer(
                textView: textView,
                settings: localSettings,
                motionUtil: motionUtil,
                vim: vim.Object,
                wordNavigator: wordNavigator,
                jumpList: jumpList);

            return(new CommandUtil(
                       buffer.Object,
                       operations,
                       statusUtil,
                       undoRedOperations,
                       smartIndentationService,
                       foldManager));
        }
Пример #5
0
        private void Create(bool insertMode, params string[] lines)
        {
            _factory = new MockRepository(MockBehavior.Strict);
            _factory.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 = _factory.Create <IUndoRedoOperations>();
            _wordCompletionSessionFactoryService = _factory.Create <IWordCompletionSessionFactoryService>();

            var localSettings = new LocalSettings(Vim.GlobalSettings);

            _vimBuffer = MockObjectFactory.CreateVimBuffer(
                _textView,
                localSettings: localSettings,
                vim: _vim.Object,
                factory: _factory);
            _vimBuffer.SetupGet(x => x.ModeKind).Returns(ModeKind.Insert);
            _operations = _factory.Create <ICommonOperations>();
            _operations.SetupGet(x => x.EditorOperations).Returns(EditorUtil.FactoryService.EditorOperationsFactory.GetEditorOperations(_textView));
            _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>();

            // 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.IsKeyDown(It.IsAny <VimKey>())).Returns(false);

            _modeRaw = new Vim.Modes.Insert.InsertMode(
                _vimBuffer.Object,
                _operations.Object,
                _broker.Object,
                _editorOptions.Object,
                _undoRedoOperations.Object,
                _textChangeTracker.Object,
                _insertUtil.Object,
                !insertMode,
                _keyboardDevice.Object,
                _mouseDevice.Object,
                EditorUtil.FactoryService.WordUtilFactory.GetWordUtil(_textView.TextBuffer),
                _wordCompletionSessionFactoryService.Object);
            _mode             = _modeRaw;
            _mode.CommandRan += (sender, e) => { _lastCommandRan = e; };
        }
Пример #6
0
 public void Create(params string[] lines)
 {
     _textBuffer = EditorUtil.CreateBuffer(lines);
     _factory    = new MockRepository(MockBehavior.Strict);
     _textCaret  = _factory.Create <ITextCaret>();
     _textView   = MockObjectFactory.CreateTextView(textBuffer: _textBuffer, caret: _textCaret.Object, factory: _factory);
     _buffer     = MockObjectFactory.CreateVimBuffer(textView: _textView.Object, factory: _factory);
     _operations = _factory.Create <ICommonOperations>();
     _operations.Setup(x => x.MoveCaretToPoint(It.IsAny <SnapshotPoint>()));
     _operations.Setup(x => x.EnsureCaretOnScreenAndTextExpanded());
     _modeRaw = new SubstituteConfirmMode(_buffer.Object, _operations.Object);
     _mode    = _modeRaw;
 }
Пример #7
0
 protected override void Setup(string languageId)
 {
     base.Setup(languageId);
     _factory    = new MockRepository(MockBehavior.Strict);
     _textBuffer = _factory.Create <ITextBuffer>();
     _adapter    = _factory.Create <IVsAdapter>();
     _adapter.Setup(x => x.IsReadOnly(_textBuffer.Object)).Returns(false);
     _adapter.Setup(x => x.IsIncrementalSearchActive(It.IsAny <ITextView>())).Returns(false);
     _buffer      = MockObjectFactory.CreateVimBuffer(_textBuffer.Object);
     _vsProcessor = new VsKeyProcessor(_adapter.Object, _buffer.Object);
     _processor   = _vsProcessor;
     _device      = new MockKeyboardDevice();
 }
Пример #8
0
 public void Setup()
 {
     _factory   = new MockRepository(MockBehavior.Loose);
     _selection = _factory.Create <ITextSelection>();
     _textView  = MockObjectFactory.CreateTextView(
         selection: _selection.Object,
         factory: _factory);
     _buffer = MockObjectFactory.CreateVimBuffer(
         textView: _textView.Object,
         factory: _factory);
     _context = new TestableSynchronizationContext();
     SynchronizationContext.SetSynchronizationContext(_context);
     _tracker = new SelectionChangeTracker(_buffer.Object);
 }
Пример #9
0
 protected override void Setup(string languageId)
 {
     base.Setup(languageId);
     _factory    = new MockRepository(MockBehavior.Strict);
     _textBuffer = _factory.Create <ITextBuffer>();
     _vsAdapter  = _factory.Create <IVsAdapter>();
     _vsAdapter.Setup(x => x.IsIncrementalSearchActive(It.IsAny <ITextView>())).Returns(false);
     _buffer = MockObjectFactory.CreateVimBuffer(_textBuffer.Object);
     _buffer.Setup(x => x.CanProcess(It.IsAny <KeyInput>())).Returns(true);
     _buffer.Setup(x => x.Process(It.IsAny <KeyInput>())).Returns(ProcessResult.NewHandled(ModeSwitch.NoSwitch));
     _buffer.SetupGet(x => x.ModeKind).Returns(ModeKind.Normal);
     _bufferCoordinator = new VimBufferCoordinator(_buffer.Object);
     _vsProcessor       = new VsKeyProcessor(_vsAdapter.Object, _bufferCoordinator);
     _processor         = _vsProcessor;
     _device            = new MockKeyboardDevice();
 }
Пример #10
0
        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);

            var snapshot = _factory.Create <ITextSnapshot>();

            snapshot.SetupGet(x => x.Length).Returns(1);
            _nonEmptySpan = new VirtualSnapshotSpan(new SnapshotSpan(snapshot.Object, new Span(0, 1)));

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

            _context = new TestableSynchronizationContext();

            // Mock 'DoActionAsync' in 'ICommonOperations'.
            var commonOperations = _factory.Create <ICommonOperations>();

            commonOperations.Setup(x => x.DoActionAsync(It.IsAny <FSharpFunc <Unit, Unit> >()))
            .Callback((FSharpFunc <Unit, Unit> action) => _context.Post(_ => action.Invoke(null), null));

            _tracker = new SelectionChangeTracker(
                _vimBuffer.Object,
                commonOperations.Object,
                selectionList.ToFSharpList(),
                _mouseDevice.Object);
        }
Пример #11
0
        public void SetUp()
        {
            _factory = new MockRepository(MockBehavior.Strict);
            _selection = _factory.Create<ITextSelection>();
            _selection.Setup(x => x.IsEmpty).Returns(true);
            _operations = _factory.Create<ICommonOperations>();
            _buffer = EditorUtil.CreateTextBuffer();
            _caret = MockObjectFactory.CreateCaret(factory: _factory);
            _caret.SetupProperty(x => x.IsHidden);
            _textView = MockObjectFactory.CreateTextView(
                textBuffer: _buffer,
                caret: _caret.Object,
                selection: _selection.Object,
                factory: _factory);

            _bufferData = MockObjectFactory.CreateVimBuffer(textView: _textView.Object, factory: _factory);
            _processor = _factory.Create<ICommandProcessor>();
            _modeRaw = new CommandMode(_bufferData.Object, _processor.Object, _operations.Object);
            _mode = _modeRaw;
        }
Пример #12
0
        protected override VimKeyProcessor CreateKeyProcessor()
        {
            _factory     = new MockRepository(MockBehavior.Strict);
            _wpfTextView = CreateTextView();
            _mockAdapter = new MockAdapter();
            _editorAdaptersFactoryService = _factory.Create <IVsEditorAdaptersFactoryService>();
            _editorAdaptersFactoryService.Setup(x => x.GetViewAdapter(_wpfTextView)).Returns(_mockAdapter);

            _vsAdapter = _factory.Create <IVsAdapter>();
            _vsAdapter.Setup(x => x.IsIncrementalSearchActive(It.IsAny <ITextView>())).Returns(false);
            _vsAdapter.SetupGet(x => x.EditorAdapter).Returns(_editorAdaptersFactoryService.Object);
            _vsAdapter.Setup(x => x.IsReadOnly(_wpfTextView)).Returns(false);
            _mockVimBuffer = MockObjectFactory.CreateVimBuffer(_wpfTextView);
            _mockVimBuffer.Setup(x => x.CanProcess(It.IsAny <KeyInput>())).Returns(true);
            _mockVimBuffer.Setup(x => x.Process(It.IsAny <KeyInput>())).Returns(ProcessResult.NewHandled(ModeSwitch.NoSwitch));
            _mockVimBuffer.SetupGet(x => x.ModeKind).Returns(ModeKind.Normal);
            _bufferCoordinator = new VimBufferCoordinator(_mockVimBuffer.Object);
            _device            = new MockKeyboardDevice();
            return(new VsKeyProcessor(_vsAdapter.Object, _bufferCoordinator, KeyUtil));
        }
Пример #13
0
        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());
        }
Пример #14
0
        public void Setup(bool isShimmed = true, params string[] lines)
        {
            _factory    = new MockRepository(MockBehavior.Loose);
            _textBuffer = EditorUtil.CreateBuffer(lines);
            _textView   = MockObjectFactory.CreateTextView(textBuffer: _textBuffer);
            _buffer     = MockObjectFactory.CreateVimBuffer(textView: _textView.Object);
            _buffer.SetupGet(x => x.ModeKind).Returns(ModeKind.Normal).Verifiable();

            // 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);

            _aggregator = _factory.Create <ITagAggregator <ITag> >(MockBehavior.Strict);
            SetupTags();

            Result <IVsTextLines> result;

            if (isShimmed)
            {
                _vsTextLines = _factory.Create <IVsTextLines>();
                _vsTextLines.SetupNoEnumMarkers();
                result = Result.CreateSuccess(_vsTextLines.Object);
            }
            else
            {
                result = Result.Error;
            }

            var list = new List <IExternalEditAdapter> {
                _adapter.Object
            };
            var adapters = new ReadOnlyCollection <IExternalEditAdapter>(list);

            _monitor = new ExternalEditMonitor(
                _buffer.Object,
                result,
                adapters,
                _aggregator.Object);
        }