Пример #1
0
        public void Should_correctly_setup_IgnoreWhitespaceMethod_with_one_click(IgnoreWhitespaceKind oldIgnoreWhitespace, IgnoreWhitespaceKind newIgnoreWhitespace, bool ignoreEol, bool ignoreChange, bool ignoreAllSpace)
        {
            Assert.AreNotEqual(oldIgnoreWhitespace, newIgnoreWhitespace);

            var accessor = _fileViewer.GetTestAccessor();

            accessor.IgnoreWhitespace = oldIgnoreWhitespace;

            switch (newIgnoreWhitespace)
            {
            case IgnoreWhitespaceKind.Eol:
                accessor.IgnoreWhitespaceAtEolToolStripMenuItem_Click(null, null);
                break;

            case IgnoreWhitespaceKind.Change:
                accessor.IgnoreWhitespaceChangesToolStripMenuItemClick(null, null);
                break;

            case IgnoreWhitespaceKind.AllSpace:
                accessor.IgnoreAllWhitespaceChangesToolStripMenuItem_Click(null, null);
                break;
            }

            accessor.IgnoreWhitespace.Should().Be(newIgnoreWhitespace);

            accessor.IgnoreWhitespaceAtEolButton.Checked.Should().Be(ignoreEol);
            accessor.IgnoreWhitespaceAtEolMenuItem.Checked.Should().Be(ignoreEol);

            accessor.IgnoreWhiteSpacesButton.Checked.Should().Be(ignoreChange);
            accessor.IgnoreWhiteSpacesMenuItem.Checked.Should().Be(ignoreChange);

            accessor.IgnoreAllWhitespacesButton.Checked.Should().Be(ignoreAllSpace);
            accessor.IgnoreAllWhitespacesMenuItem.Checked.Should().Be(ignoreAllSpace);
        }
Пример #2
0
        public void DoAutoCRLF_should_not_unnecessarily_duplicate_line_ending(AutoCRLFType autoCRLFType, string file)
        {
            using (var testHelper = new GitModuleTestHelper())
            {
                testHelper.Module.LocalConfigFile.SetEnum("core.autocrlf", autoCRLFType);
                testHelper.Module.LocalConfigFile.Save();

                var content = EmbeddedResourceLoader.Load(Assembly.GetExecutingAssembly(), $"{GetType().Namespace}.MockData.{file}.bin");

                var uiCommands = new GitUICommands(testHelper.Module);
                _uiCommandsSource.UICommands.Returns(x => uiCommands);
                _fileViewer.UICommandsSource = _uiCommandsSource;

                var fvi = _fileViewer.GetTestAccessor().FileViewerInternal;
                fvi.SetText(content, null, false);
                var doc = fvi.GetTestAccessor().TextEditor.Document;
                var end = doc.OffsetToPosition(content.Length);
                fvi.GetTestAccessor().TextEditor.ActiveTextAreaControl.SelectionManager.SetSelection(new TextLocation(0, 0), end);

                // act - 'copy to selection' menu click will call through to DoAutoCRLF
                _fileViewer.GetTestAccessor().CopyToolStripMenuItem.PerformClick();

                // assert
                var text = Clipboard.GetText();
                using (ApprovalResults.ForScenario(file, autoCRLFType))
                {
                    Approvals.Verify(text);
                }
            }
        }
Пример #3
0
        public void FileViewer_highlight_selected_text_when_enabled()
        {
            const string textToSelect       = "Selected";
            const string selectedLinePrefix = "2:";
            const string sampleText         =
                "0\n" +
                "1:Selected\n" +
                "2:\n" +
                "3:Selected\n" +
                "4:";

            using var testHelper = new GitModuleTestHelper();
            var uiCommands = new GitUICommands(testHelper.Module);

            _uiCommandsSource.UICommands.Returns(x => uiCommands);
            _fileViewer.UICommandsSource = _uiCommandsSource;
            _fileViewer.GetTestAccessor().FileViewerInternal.SetText(sampleText, null);
            SelectionManager selectionManager = _fileViewer.GetTestAccessor().FileViewerInternal.GetTestAccessor().TextEditor.ActiveTextAreaControl.TextArea.SelectionManager;

            // act
            selectionManager.SetSelection(new TextLocation(selectedLinePrefix.Length, 1), new TextLocation(selectedLinePrefix.Length + textToSelect.Length, 1));

            // assert
            selectionManager.SelectedText.Should().Be(textToSelect);
            selectionManager.SelectionCollection.Single().StartPosition.Line.Should().Be(1);
            int caretOffset = _fileViewer.GetTestAccessor().FileViewerInternal.GetTestAccessor().TextEditor.ActiveTextAreaControl.TextArea.Caret.Offset;

            caretOffset.Should().Be(0, "Caret position should be in default state");

            _fileViewer.GetTestAccessor().FileViewerInternal.GoToNextOccurrence();
            caretOffset = _fileViewer.GetTestAccessor().FileViewerInternal.GetTestAccessor().TextEditor.ActiveTextAreaControl.TextArea.Caret.Offset;
            caretOffset.Should().Be(4, $"Caret should have been moved to the first occurrence of '{textToSelect}'");

            _fileViewer.GetTestAccessor().FileViewerInternal.GoToNextOccurrence();
            caretOffset = _fileViewer.GetTestAccessor().FileViewerInternal.GetTestAccessor().TextEditor.ActiveTextAreaControl.TextArea.Caret.Offset;
            caretOffset.Should().Be(18, "Caret should have been moved to the second occurence of '" + textToSelect + "'");

            _fileViewer.GetTestAccessor().FileViewerInternal.GoToPreviousOccurrence();
            caretOffset = _fileViewer.GetTestAccessor().FileViewerInternal.GetTestAccessor().TextEditor.ActiveTextAreaControl.TextArea.Caret.Offset;
            caretOffset.Should().Be(4, "Caret should have been moved back to the first occurence of '" + textToSelect + "'");
        }