예제 #1
0
 public void ReduceLength()
 {
     using (var buffer = new StringBuffer("Food"))
     {
         buffer.CharCapacity.Should().Be(5);
         buffer.Length = 3;
         buffer.ToString().Should().Be("Foo");
         buffer.CharCapacity.Should().Be(5, "shouldn't reduce capacity when dropping length");
     }
 }
예제 #2
0
        public void ReduceLength(string testString)
        {
            using (var buffer = new StringBuffer(testString))
            {
                buffer.CharCapacity.Should().Be((uint)testString.Length + 1);

                for (int i = 1; i <= testString.Length; i++)
                {
                    buffer.Length = (uint)(testString.Length - i);
                    buffer.ToString().Should().Be(testString.Substring(0, testString.Length - i));
                    buffer.CharCapacity.Should().Be((uint)testString.Length + 1, "shouldn't reduce capacity when dropping length");
                }
            }
        }
예제 #3
0
        public unsafe void ConstructFromString(string testString)
        {
            using (var buffer = new StringBuffer(testString))
            {
                buffer.Length.Should().Be((uint)testString.Length);
                buffer.CharCapacity.Should().Be((uint)testString.Length + 1);

                for (int i = 0; i < testString.Length; i++)
                {
                    buffer[(uint)i].Should().Be(testString[i]);
                }

                buffer.CharPointer[testString.Length].Should().Be('\0', "should be null terminated");

                buffer.ToString().Should().Be(testString);
            }
        }
예제 #4
0
        public void AppendTests(string source, string value, int startIndex, int count, string expected)
        {
            // From string
            using (var buffer = new StringBuffer(source))
            {
                buffer.Append(value, startIndex, count);
                buffer.ToString().Should().Be(expected);
            }

            // From buffer
            using (var buffer = new StringBuffer(source))
            using (var valueBuffer = new StringBuffer(value))
            {
                if (count == -1)
                    buffer.Append(valueBuffer, (ulong)startIndex);
                else
                    buffer.Append(valueBuffer, (ulong)startIndex, (ulong)count);
                buffer.ToString().Should().Be(expected);
            }
        }
예제 #5
0
        public void ToStringOverSizeThrowsOverflow()
        {
            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.ToString();
                action.ShouldThrow<OverflowException>();
            }
        }