Example #1
0
 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);
     }
 }
Example #2
0
 public void ToStringCountOverLengthThrows()
 {
     using (var buffer = new StringBuffer())
     {
         Action action = () => buffer.SubString(startIndex: 0, count: 1);
         action.ShouldThrow<ArgumentOutOfRangeException>();
     }
 }
Example #3
0
        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");
            }
        }
Example #4
0
        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");
            }
        }
Example #5
0
 public void SubStringNegativeCountThrows()
 {
     using (var buffer = new StringBuffer())
     {
         Action action = () => buffer.SubString(startIndex: 0, count: -2);
         action.ShouldThrow<ArgumentOutOfRangeException>().And.ParamName.Should().Be("count");
     }
 }
Example #6
0
        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();
            }
        }