Exemplo n.º 1
0
        public void ValidateCaret_AdjustedCaretProperly()
        {
            var sut = new ConControls.Controls.Text.ConsoleTextController
            {
                Width    = 5,
                WrapMode = WrapMode.SimpleWrap,
                Text     = "0123456789\n0123456789"
            };

            sut.BufferLineCount.Should().Be(6);

            Point valid    = new Point(1, 1);
            Point tooLeft  = new Point(-1, 1);
            Point tooUp    = new Point(1, -1);
            Point tooRight = new Point(5, 1);
            Point tooDown  = new Point(1, 6);

            Point left  = new Point(0, 1);
            Point up    = new Point(1, 0);
            Point right = new Point(4, 1);
            Point down  = new Point(0, 5);

            sut.ValidateCaret(valid).Should().Be(valid);
            sut.ValidateCaret(tooLeft).Should().Be(left);
            sut.ValidateCaret(tooUp).Should().Be(up);
            sut.ValidateCaret(tooRight).Should().Be(right);
            sut.ValidateCaret(tooDown).Should().Be(down);
        }
Exemplo n.º 2
0
        public void MoveCaret_UnwrappedEmptyLastLine_CorrectResults()
        {
            var sut = new ConControls.Controls.Text.ConsoleTextController
            {
                Text     = "Hello\nWorld!\n",
                WrapMode = WrapMode.NoWrap,
                Width    = 5
            };

            sut.MoveCaretHome(new Point(1, 1)).Should().Be(Point.Empty);
            sut.MoveCaretEnd(new Point(1, 1)).Should().Be(new Point(0, 2));
            sut.MoveCaretToBeginOfLine(new Point(1, 1)).Should().Be(new Point(0, 1));
            sut.MoveCaretToEndOfLIne(Point.Empty).Should().Be(new Point(5, 0));
            sut.MoveCaretToEndOfLIne(new Point(1, 2)).Should().Be(new Point(0, 2));
            sut.MoveCaretLeft(Point.Empty).Should().Be(Point.Empty);
            sut.MoveCaretLeft(new Point(1, 1)).Should().Be(new Point(0, 1));
            sut.MoveCaretLeft(new Point(0, 2)).Should().Be(new Point(6, 1));
            sut.MoveCaretUp(Point.Empty).Should().Be(Point.Empty);
            sut.MoveCaretUp(new Point(6, 1)).Should().Be(new Point(5, 0));
            sut.MoveCaretRight(Point.Empty).Should().Be(new Point(1, 0));
            sut.MoveCaretRight(new Point(5, 0)).Should().Be(new Point(0, 1));
            sut.MoveCaretRight(new Point(0, 2)).Should().Be(new Point(0, 2));
            sut.MoveCaretDown(Point.Empty).Should().Be(new Point(0, 1));
            sut.MoveCaretDown(new Point(3, 1)).Should().Be(new Point(0, 2));
        }
Exemplo n.º 3
0
        public void TextProcessing_TestCase_001()
        {
            const string text = "0123456789\n0123456789";
            var          sut  = new ConControls.Controls.Text.ConsoleTextController
            {
                Width    = 5,
                WrapMode = WrapMode.SimpleWrap,
                Text     = text
            };

            sut.BufferLineCount.Should().Be(6);
            sut.MaxLineLength.Should().Be(5);
            sut.Text.Should().Be(text);
            sut.Width.Should().Be(5);
            sut.WrapMode.Should().Be(WrapMode.SimpleWrap);
            sut.GetLineLength(-1).Should().Be(0);
            sut.GetLineLength(0).Should().Be(5);
            sut.GetLineLength(1).Should().Be(5);
            sut.GetLineLength(2).Should().Be(0);
            sut.GetLineLength(3).Should().Be(5);
            sut.GetLineLength(4).Should().Be(5);
            sut.GetLineLength(5).Should().Be(0);

            sut.GetCharacters(new Rectangle(Point.Empty, new Size(5, 6)))
            .Should()
            .Equal(
                '0', '1', '2', '3', '4',
                '5', '6', '7', '8', '9',
                '\0', '\0', '\0', '\0', '\0',
                '0', '1', '2', '3', '4',
                '5', '6', '7', '8', '9',
                '\0', '\0', '\0', '\0', '\0');
            sut.GetCharacters(new Rectangle(2, 2, 7, 2))
            .Should()
            .Equal(
                '\0', '\0', '\0', '\0', '\0', '\0', '\0',
                '2', '3', '4', '\0', '\0', '\0', '\0');

            sut.WrapMode = WrapMode.NoWrap;
            sut.Width    = 4;

            sut.BufferLineCount.Should().Be(2);
            sut.MaxLineLength.Should().Be(10);
            sut.Text.Should().Be(text);
            sut.Width.Should().Be(4);
            sut.WrapMode.Should().Be(WrapMode.NoWrap);
            sut.GetLineLength(-1).Should().Be(0);
            sut.GetLineLength(0).Should().Be(10);
            sut.GetLineLength(1).Should().Be(10);
            sut.GetLineLength(2).Should().Be(0);

            sut.GetCharacters(new Rectangle(3, 1, 10, 2))
            .Should()
            .Equal(
                '3', '4', '5', '6', '7', '8', '9', '\0', '\0', '\0',
                '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0');
        }
Exemplo n.º 4
0
        public void EndCaret_WrappedEmpty_Empty()
        {
            var sut = new ConControls.Controls.Text.ConsoleTextController
            {
                Width    = 5,
                WrapMode = WrapMode.SimpleWrap
            };

            sut.EndCaret.Should().Be(Point.Empty);
        }
Exemplo n.º 5
0
        public void Append_TestCase_001()
        {
            const string text = "01234\r\n56\n\r\n789\n012345678";
            var          sut  = new ConControls.Controls.Text.ConsoleTextController
            {
                Width    = 5,
                WrapMode = WrapMode.SimpleWrap,
                Text     = text
            };

            sut.BufferLineCount.Should().Be(7);
            sut.GetLineLength(0).Should().Be(5);
            sut.GetLineLength(1).Should().Be(0);
            sut.GetLineLength(2).Should().Be(2);
            sut.GetLineLength(3).Should().Be(0);
            sut.GetLineLength(4).Should().Be(3);
            sut.GetLineLength(5).Should().Be(5);
            sut.GetLineLength(6).Should().Be(4);

            sut.Append(text);
            sut.Text.Should().Be(text + text);
            sut.BufferLineCount.Should().Be(13);
            sut.MaxLineLength.Should().Be(5);
            sut.GetLineLength(0).Should().Be(5);
            sut.GetLineLength(1).Should().Be(0);
            sut.GetLineLength(2).Should().Be(2);
            sut.GetLineLength(3).Should().Be(0);
            sut.GetLineLength(4).Should().Be(3);
            sut.GetLineLength(5).Should().Be(5);
            sut.GetLineLength(6).Should().Be(5);
            sut.GetLineLength(7).Should().Be(4);
            sut.GetLineLength(8).Should().Be(2);
            sut.GetLineLength(9).Should().Be(0);
            sut.GetLineLength(10).Should().Be(3);
            sut.GetLineLength(11).Should().Be(5);
            sut.GetLineLength(12).Should().Be(4);

            sut.GetCharacters(new Rectangle(Point.Empty, new Size(5, 13)))
            .Should()
            .Equal(
                '0', '1', '2', '3', '4',
                '\0', '\0', '\0', '\0', '\0',
                '5', '6', '\0', '\0', '\0',
                '\0', '\0', '\0', '\0', '\0',
                '7', '8', '9', '\0', '\0',
                '0', '1', '2', '3', '4',
                '5', '6', '7', '8', '0',
                '1', '2', '3', '4', '\0',
                '5', '6', '\0', '\0', '\0',
                '\0', '\0', '\0', '\0', '\0',
                '7', '8', '9', '\0', '\0',
                '0', '1', '2', '3', '4',
                '5', '6', '7', '8', '\0'
                );
        }
Exemplo n.º 6
0
        public void EndCaret_UnwrappedNonEmptyLastLine_CorrectResult()
        {
            var sut = new ConControls.Controls.Text.ConsoleTextController
            {
                Text     = "Hello\nWorld",
                Width    = 5,
                WrapMode = WrapMode.NoWrap
            };

            sut.EndCaret.Should().Be(new Point(5, 1));
        }
Exemplo n.º 7
0
        public void Append_Empty_Empty()
        {
            var sut = new ConControls.Controls.Text.ConsoleTextController
            {
                Width    = 5,
                WrapMode = WrapMode.SimpleWrap
            };

            sut.Append(string.Empty);
            sut.MaxLineLength.Should().Be(0);
        }
Exemplo n.º 8
0
        public void MoveCaretPageDown_WrappedEmpty_CorrectResults()
        {
            var sut = new ConControls.Controls.Text.ConsoleTextController
            {
                WrapMode = WrapMode.SimpleWrap,
                Width    = 5
            };

            sut.MoveCaretPageDown(Point.Empty, 5).Should().Be(Point.Empty);
            sut.MoveCaretPageDown(new Point(1, 1), 5).Should().Be(Point.Empty);
        }
Exemplo n.º 9
0
        public void EndCaret_WrappedEmptyLastLine_CorrectResult()
        {
            var sut = new ConControls.Controls.Text.ConsoleTextController
            {
                Text     = "HelloWorld\n",
                Width    = 5,
                WrapMode = WrapMode.SimpleWrap
            };

            sut.EndCaret.Should().Be(new Point(0, 3));
        }
Exemplo n.º 10
0
        public void Width_NeverBelowOne()
        {
            var sut = new ConControls.Controls.Text.ConsoleTextController();

            sut.Width.Should().Be(1);
            sut.Width = 10;
            sut.Width.Should().Be(10);
            sut.Width = 0;
            sut.Width.Should().Be(1);
            sut.Width = -5;
            sut.Width.Should().Be(1);
        }
Exemplo n.º 11
0
        public void MoveCaretPageDown_WrappedNonEmpty_CorrectResults()
        {
            var sut = new ConControls.Controls.Text.ConsoleTextController
            {
                Text     = "Line1Line2L3\nLine4",
                WrapMode = WrapMode.SimpleWrap,
                Width    = 5
            };

            sut.MoveCaretPageDown(Point.Empty, 5).Should().Be(new Point(0, 4));
            sut.MoveCaretPageDown(new Point(1, 1), 5).Should().Be(new Point(0, 4));
            sut.MoveCaretPageDown(new Point(3, 0), 2).Should().Be(new Point(2, 2));
        }
Exemplo n.º 12
0
        public void Clear_Cleared()
        {
            const string text = "hello world!";
            var          sut  = new ConControls.Controls.Text.ConsoleTextController
            {
                Width    = 5,
                WrapMode = WrapMode.SimpleWrap,
                Text     = text
            };

            sut.Text.Should().Be(text);
            sut.Clear();
            sut.Text.Should().BeEmpty();
        }
Exemplo n.º 13
0
        public void MoveCaretPageDown_UnwrappedNonEmpty_CorrectResults()
        {
            var sut = new ConControls.Controls.Text.ConsoleTextController
            {
                Text     = "Line1\nLine2\nLongLine3\nLine4",
                WrapMode = WrapMode.NoWrap,
                Width    = 5
            };

            sut.MoveCaretPageDown(Point.Empty, 5).Should().Be(new Point(0, 3));
            sut.MoveCaretPageDown(new Point(1, 1), 5).Should().Be(new Point(1, 3));
            sut.MoveCaretPageDown(new Point(3, 3), 2).Should().Be(new Point(3, 3));
            sut.MoveCaretPageDown(new Point(7, 2), 2).Should().Be(new Point(5, 3));
        }
Exemplo n.º 14
0
        public void MoveCaret_WrappedEmpty_CorrectResults()
        {
            var sut = new ConControls.Controls.Text.ConsoleTextController
            {
                WrapMode = WrapMode.SimpleWrap,
                Width    = 5
            };

            sut.MoveCaretHome(new Point(1, 1)).Should().Be(Point.Empty);
            sut.MoveCaretEnd(new Point(1, 1)).Should().Be(Point.Empty);
            sut.MoveCaretToBeginOfLine(new Point(1, 0)).Should().Be(Point.Empty);
            sut.MoveCaretToEndOfLIne(Point.Empty).Should().Be(Point.Empty);
            sut.MoveCaretLeft(Point.Empty).Should().Be(Point.Empty);
            sut.MoveCaretUp(Point.Empty).Should().Be(Point.Empty);
            sut.MoveCaretRight(Point.Empty).Should().Be(Point.Empty);
            sut.MoveCaretDown(Point.Empty).Should().Be(Point.Empty);
        }
Exemplo n.º 15
0
        public void TextProcessing_TestCase_002()
        {
            const string text = "01234\r\n01234";
            var          sut  = new ConControls.Controls.Text.ConsoleTextController
            {
                Width    = 5,
                WrapMode = WrapMode.SimpleWrap,
                Text     = text
            };

            sut.GetCharacters(new Rectangle(Point.Empty, new Size(6, 4)))
            .Should()
            .Equal(
                '0', '1', '2', '3', '4', '\0',
                '\0', '\0', '\0', '\0', '\0', '\0',
                '0', '1', '2', '3', '4', '\0',
                '\0', '\0', '\0', '\0', '\0', '\0');
        }
Exemplo n.º 16
0
        public void ValidateCaret_Wrapped_LowerEnd()
        {
            var sut = new ConControls.Controls.Text.ConsoleTextController
            {
                Width    = 5,
                WrapMode = WrapMode.SimpleWrap,
                Text     = "0123456789\n0123456789"
            };

            sut.BufferLineCount.Should().Be(6);

            var endPoint = new Point(0, 5);
            var tooRight = new Point(1, 5);
            var tooLow   = new Point(0, 6);

            sut.ValidateCaret(endPoint).Should().Be(endPoint);
            sut.ValidateCaret(tooRight).Should().Be(endPoint);
            sut.ValidateCaret(tooLow).Should().Be(new Point(0, 5));
        }
Exemplo n.º 17
0
        public void TextProcessing_RequestingAreaWithNegativeSize_Empty()
        {
            const string text = "01234\r\n01234";
            var          sut  = new ConControls.Controls.Text.ConsoleTextController
            {
                Width    = 5,
                WrapMode = WrapMode.SimpleWrap,
                Text     = text
            };

            sut.GetCharacters(new Rectangle(Point.Empty, new Size(-1, 1)))
            .Should()
            .BeEmpty();
            sut.GetCharacters(new Rectangle(Point.Empty, new Size(1, -1)))
            .Should()
            .BeEmpty();
            sut.GetCharacters(new Rectangle(Point.Empty, new Size(-1, -1)))
            .Should()
            .BeEmpty();
        }
Exemplo n.º 18
0
        public void WrapMode_Applied()
        {
            const string text = "hello world!\ngood bye!";
            var          sut  = new ConControls.Controls.Text.ConsoleTextController
            {
                Width = 4,
                Text  = text
            };

            sut.WrapMode.Should().Be(WrapMode.NoWrap);
            sut.BufferLineCount.Should().Be(2);
            sut.WrapMode = WrapMode.NoWrap;
            sut.WrapMode.Should().Be(WrapMode.NoWrap);
            sut.BufferLineCount.Should().Be(2);

            sut.WrapMode = WrapMode.SimpleWrap;
            sut.WrapMode.Should().Be(WrapMode.SimpleWrap);
            sut.BufferLineCount.Should().Be(7);
            sut.WrapMode = WrapMode.SimpleWrap;
            sut.WrapMode.Should().Be(WrapMode.SimpleWrap);
            sut.BufferLineCount.Should().Be(7);
        }
Exemplo n.º 19
0
        public void ValidateCaret_Empty_PointEmpty()
        {
            var sut = new ConControls.Controls.Text.ConsoleTextController
            {
                Width    = 5,
                WrapMode = WrapMode.SimpleWrap,
                Text     = string.Empty
            };

            sut.BufferLineCount.Should().Be(0);

            Point valid    = Point.Empty;
            Point tooLeft  = new Point(-1, 0);
            Point tooUp    = new Point(0, -1);
            Point tooRight = new Point(5, 0);
            Point tooDown  = new Point(0, 6);

            sut.ValidateCaret(valid).Should().Be(valid);
            sut.ValidateCaret(tooLeft).Should().Be(valid);
            sut.ValidateCaret(tooUp).Should().Be(valid);
            sut.ValidateCaret(tooRight).Should().Be(valid);
            sut.ValidateCaret(tooDown).Should().Be(valid);
        }