public void ToStringTest(string source, int startIndex, int count, string expected) { using (var buffer = new StringBuffer(source)) { buffer.SubString(startIndex: (ulong)startIndex, count: count).Should().Be(expected); } }
public void ToStringCountOverLengthThrows() { using (var buffer = new StringBuffer()) { Action action = () => buffer.SubString(startIndex: 0, count: 1); action.ShouldThrow<ArgumentOutOfRangeException>(); } }
public void SubStringIndexPlusCountCombinedOutOfRangeThrows() { using (var buffer = new StringBuffer("a")) { Action action = () => buffer.SubString(startIndex: 1, count: 1); action.ShouldThrow<ArgumentOutOfRangeException>().And.ParamName.Should().Be("startIndex"); buffer.Append("b"); action.ShouldNotThrow<ArgumentOutOfRangeException>(); action = () => buffer.SubString(startIndex: 1, count: 2); action.ShouldThrow<ArgumentOutOfRangeException>().And.ParamName.Should().Be("count"); } }
public void SubStringImplicitCountOverMaxStringThrows() { using (var buffer = new StringBuffer()) { var length = buffer.GetType().GetField("_length", BindingFlags.NonPublic | BindingFlags.Instance); length.SetValue(buffer, (uint)int.MaxValue + 1); Action action = () => buffer.SubString(startIndex: 0, count: -1); action.ShouldThrow<ArgumentOutOfRangeException>().And.ParamName.Should().Be("count"); } }
public void SubStringNegativeCountThrows() { using (var buffer = new StringBuffer()) { Action action = () => buffer.SubString(startIndex: 0, count: -2); action.ShouldThrow<ArgumentOutOfRangeException>().And.ParamName.Should().Be("count"); } }
public void SubStringIndexOverLengthThrows() { using (var buffer = new StringBuffer()) { Action action = () => buffer.SubString(startIndex: 1); action.ShouldThrow<ArgumentOutOfRangeException>().And.ParamName.Should().Be("startIndex"); buffer.Append("a"); action.ShouldThrow<ArgumentOutOfRangeException>().And.ParamName.Should().Be("startIndex"); buffer.Append("b"); action.ShouldNotThrow(); } }