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); }
public void ReplacingAtEnd() { var buffer = new ConsoleInputBuffer(); buffer.Insert("abcd"); buffer.MoveCursor(SeekOrigin.End, 0); buffer.Invoking(b => b.Replace('x')).Should().Throw <Exception>(); }
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"); }
public void RemovingAtEnd() { var buffer = new ConsoleInputBuffer(); buffer.Insert("abcd"); buffer.MoveCursor(SeekOrigin.End, 0); buffer.Remove().Should().BeFalse(); buffer.Contents.Should().Be("abcd"); }
public void ReplacePartOfString() { var buffer = new ConsoleInputBuffer(); buffer.Insert("abcd"); buffer.MoveCursor(SeekOrigin.Begin, 1); buffer.Replace("xy"); buffer.Contents.Should().Be("axyd"); }
public void MovingCursorBogusly() { var buffer = new ConsoleInputBuffer(); buffer.Insert("abcd"); Action movement = () => buffer.MoveCursor((SeekOrigin)0x10, 1); movement.ShouldThrow <ArgumentOutOfRangeException>(); }
public void ReplacingAtEnd() { var buffer = new ConsoleInputBuffer(); buffer.Insert("abcd"); buffer.MoveCursor(SeekOrigin.End, 0); Action replacementAction = () => buffer.Replace('x'); replacementAction.ShouldThrow <Exception>(); }
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); }
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"); }
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"); }
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"); }
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"); }