コード例 #1
0
        public void MovingCursorRelativeToEnd()
        {
            var buffer = new ConsoleInputBuffer();

            buffer.Insert("abcd");

            buffer.MoveCursor(SeekOrigin.End, 1, out int delta).Should().BeFalse();
            buffer.CursorIndex.Should().Be(0);
            delta.Should().Be(0);

            buffer.MoveCursor(SeekOrigin.End, 0, out delta).Should().BeTrue();
            buffer.CursorIndex.Should().Be(4);
            delta.Should().Be(4);

            buffer.MoveCursor(SeekOrigin.End, -2, out delta).Should().BeTrue();
            buffer.CursorIndex.Should().Be(2);
            delta.Should().Be(-2);

            buffer.MoveCursor(SeekOrigin.End, 4, out delta).Should().BeFalse();
            buffer.CursorIndex.Should().Be(2);
            delta.Should().Be(0);

            buffer.MoveCursor(SeekOrigin.End, -10, out delta).Should().BeFalse();
            buffer.CursorIndex.Should().Be(2);
            delta.Should().Be(0);
        }
コード例 #2
0
        public void ReplacingAtEnd()
        {
            var buffer = new ConsoleInputBuffer();

            buffer.Insert("abcd");
            buffer.MoveCursor(SeekOrigin.End, 0);

            buffer.Invoking(b => b.Replace('x')).Should().Throw <Exception>();
        }
コード例 #3
0
        public void ReplaceOneChar()
        {
            var buffer = new ConsoleInputBuffer();

            buffer.Insert("abcd");
            buffer.MoveCursor(SeekOrigin.Current, 1).Should().BeTrue();
            buffer.Replace('x');
            buffer.Contents.Should().Be("axcd");
        }
コード例 #4
0
        public void RemovingAtEnd()
        {
            var buffer = new ConsoleInputBuffer();

            buffer.Insert("abcd");
            buffer.MoveCursor(SeekOrigin.End, 0);

            buffer.Remove().Should().BeFalse();
            buffer.Contents.Should().Be("abcd");
        }
コード例 #5
0
        public void ReplacePartOfString()
        {
            var buffer = new ConsoleInputBuffer();

            buffer.Insert("abcd");

            buffer.MoveCursor(SeekOrigin.Begin, 1);
            buffer.Replace("xy");
            buffer.Contents.Should().Be("axyd");
        }
コード例 #6
0
        public void MovingCursorBogusly()
        {
            var buffer = new ConsoleInputBuffer();

            buffer.Insert("abcd");

            Action movement = () => buffer.MoveCursor((SeekOrigin)0x10, 1);

            movement.ShouldThrow <ArgumentOutOfRangeException>();
        }
コード例 #7
0
        public void ReplacingAtEnd()
        {
            var buffer = new ConsoleInputBuffer();

            buffer.Insert("abcd");
            buffer.MoveCursor(SeekOrigin.End, 0);

            Action replacementAction = () => buffer.Replace('x');

            replacementAction.ShouldThrow <Exception>();
        }
コード例 #8
0
        public void RemoveCharBeforeInMiddle()
        {
            var buffer = new ConsoleInputBuffer();

            buffer.Insert("abcd");

            buffer.MoveCursor(SeekOrigin.End, -1);
            buffer.RemoveCharBeforeCursor().Should().BeTrue();

            buffer.Contents.Should().Be("abd");
            buffer.Length.Should().Be(3);
            buffer.CursorIndex.Should().Be(2);
        }
コード例 #9
0
        public void InsertStringInMiddle()
        {
            var buffer = new ConsoleInputBuffer();

            buffer.Insert("abcd");
            buffer.MoveCursor(SeekOrigin.Begin, 2);

            buffer.Insert("xyz");

            buffer.Contents.Should().Be("abxyzcd");
            buffer.CursorIndex.Should().Be(2);
            buffer.Length.Should().Be(7);
            buffer.CursorIsAtEnd.Should().BeFalse();
            buffer.ToString().Should().Be("abxyzcd");
        }
コード例 #10
0
        public void RemoveMultipleChars()
        {
            var buffer = new ConsoleInputBuffer();

            buffer.Insert("abcd");
            buffer.MoveCursor(SeekOrigin.Begin, 1);

            buffer.Remove(2).Should().BeTrue();

            buffer.Contents.Should().Be("ad");
            buffer.CursorIndex.Should().Be(1);
            buffer.Length.Should().Be(2);
            buffer.CursorIsAtEnd.Should().BeFalse();
            buffer.ToString().Should().Be("ad");
        }
コード例 #11
0
        public void RemoveLastChar()
        {
            var buffer = new ConsoleInputBuffer();

            buffer.Insert("abcd");
            buffer.MoveCursor(SeekOrigin.Begin, 3);

            buffer.Remove().Should().BeTrue();

            buffer.Contents.Should().Be("abc");
            buffer.CursorIndex.Should().Be(3);
            buffer.Length.Should().Be(3);
            buffer.CursorIsAtEnd.Should().BeTrue();
            buffer.ToString().Should().Be("abc");
        }
コード例 #12
0
        public void Truncate()
        {
            var buffer = new ConsoleInputBuffer();

            buffer.Insert("abcd");
            buffer.MoveCursor(SeekOrigin.Begin, 2);

            buffer.Truncate();

            buffer.Contents.Should().Be("ab");
            buffer.CursorIndex.Should().Be(2);
            buffer.Length.Should().Be(2);
            buffer.CursorIsAtEnd.Should().BeTrue();
            buffer.ToString().Should().Be("ab");
        }