Exemplo n.º 1
0
            public void Append_ToEndOfExistingBufferConsolidating_ExactByteArrayLength_DataWithOffset()
            {
                var buffer = new Byte[] { 0x00, 0x11, 0x22, 0x33, 0x44 };
                var span   = BufferSpan.From(buffer, 2, 3);
                var data   = BufferSpan.From(new Byte[] { 0xAA, 0xDD, 0xEE, 0xBB, 0xCC }, 1, 2);
                var result = span.Append(data);

                Check.That(result.Buffer).IsSameReferenceAs(buffer);
                Check.That(result.BufferLength).IsEqualTo(5);
                Check.That(result.FreeBytes).IsEqualTo(0);
                Check.That(result.Offset).IsEqualTo(0);
                Check.That(result.Count).IsEqualTo(5);
                Check.That(result.IsEmpty).IsFalse();

                Check.That(result.ToArray())
                .ContainsExactly(
                    0x22,
                    0x33,
                    0x44,
                    0xDD,
                    0xEE
                    )
                .And.Not.IsSameReferenceAs(span.Buffer);

                Check.That(result.ToString()).IsEqualTo("22-33-44-DD-EE");
            }
Exemplo n.º 2
0
            public void Exception_When_OffsetAndCountIsGreaterThanCount()
            {
                var buffer = new Byte[] { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 };
                var span   = BufferSpan.From(buffer, 1, 4);

                Check.ThatCode(() => span.Slice(2, 3)).Throws <ArgumentOutOfRangeException>();
            }
Exemplo n.º 3
0
            public void Append_EmptySpan()
            {
                var buffer = new Byte[] {
                    0x00,
                    0x11,
                    0x22,
                    0x33,
                    0x44,
                    0x55,
                    0x66,
                    0x77,
                    0x88,
                    0x99,
                };

                var span   = BufferSpan.From(buffer, 1, 3);
                var data   = BufferSpan.Empty;
                var result = span.Append(data);

                Check.That(result.Buffer).IsSameReferenceAs(buffer);
                Check.That(result.BufferLength).IsEqualTo(10);
                Check.That(result.FreeBytes).IsEqualTo(6);
                Check.That(result.Offset).IsEqualTo(1);
                Check.That(result.Count).IsEqualTo(3);
                Check.That(result.IsEmpty).IsFalse();

                Check.That(result.ToArray()).ContainsExactly(0x11, 0x22, 0x33).And.Not.IsSameReferenceAs(span.Buffer);
                Check.That(result.ToString()).IsEqualTo("11-22-33");
            }
Exemplo n.º 4
0
            public void Append_IntoNewBuffer_DataWithOffset()
            {
                var buffer = new Byte[] { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 };
                var span   = BufferSpan.From(buffer, 2, 3);
                var data   = BufferSpan.From(new Byte[] { 0x12, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0x21 }, 1, 5);
                var result = span.Append(data);

                Check.That(result.Buffer).Not.IsSameReferenceAs(buffer);
                Check.That(result.BufferLength).IsEqualTo(8);
                Check.That(result.FreeBytes).IsEqualTo(0);
                Check.That(result.Offset).IsEqualTo(0);
                Check.That(result.Count).IsEqualTo(8);
                Check.That(result.IsEmpty).IsFalse();

                Check.That(result.ToArray())
                .ContainsExactly(
                    0x22,
                    0x33,
                    0x44,
                    0xAA,
                    0xBB,
                    0xCC,
                    0xDD,
                    0xEE
                    )
                .And.Not.IsSameReferenceAs(span.Buffer);

                Check.That(result.ToString()).IsEqualTo("22-33-44-AA-BB-CC-DD-EE");
            }
Exemplo n.º 5
0
            public void Exception_When_CountIsNegative()
            {
                var buffer = new Byte[] { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 };
                var span   = BufferSpan.From(buffer, 1, 4);

                Check.ThatCode(() => span.Slice(0, -1)).Throws <ArgumentOutOfRangeException>();
            }
Exemplo n.º 6
0
            public void Exception_When_BytesGreaterThanCount()
            {
                var buffer = new Byte[] { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 };
                var span   = BufferSpan.From(buffer, 1, 3);

                Check.ThatCode(() => span.Discard(4)).Throws <ArgumentOutOfRangeException>();
            }
Exemplo n.º 7
0
            public void Append_ToEmptySpan()
            {
                var span = BufferSpan.Empty;

                var data = BufferSpan.From(
                    0xAA,
                    0xBB,
                    0xCC,
                    0xDD,
                    0xEE
                    );

                var result = span.Append(data);

                Check.That(result.Buffer).Not.IsSameReferenceAs(span.Buffer);
                Check.That(result.BufferLength).IsEqualTo(5);
                Check.That(result.FreeBytes).IsEqualTo(0);
                Check.That(result.Offset).IsEqualTo(0);
                Check.That(result.Count).IsEqualTo(5);
                Check.That(result.IsEmpty).IsFalse();

                Check.That(result.ToArray())
                .ContainsExactly(
                    0xAA,
                    0xBB,
                    0xCC,
                    0xDD,
                    0xEE
                    );

                Check.That(result.ToString()).IsEqualTo("AA-BB-CC-DD-EE");
            }
Exemplo n.º 8
0
            public void Append_ToEndOfExistingBuffer_ExactByteArrayLength()
            {
                var buffer = new Byte[] { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 };
                var span   = BufferSpan.From(buffer, 1, 3);
                var data   = BufferSpan.From(0xDD, 0xEE);
                var result = span.Append(data);

                Check.That(result.Buffer).IsSameReferenceAs(buffer);
                Check.That(result.BufferLength).IsEqualTo(6);
                Check.That(result.FreeBytes).IsEqualTo(0);
                Check.That(result.Offset).IsEqualTo(1);
                Check.That(result.Count).IsEqualTo(5);
                Check.That(result.IsEmpty).IsFalse();

                Check.That(result.ToArray())
                .ContainsExactly(
                    0x11,
                    0x22,
                    0x33,
                    0xDD,
                    0xEE
                    )
                .And.Not.IsSameReferenceAs(span.Buffer);

                Check.That(result.ToString()).IsEqualTo("11-22-33-DD-EE");
            }
Exemplo n.º 9
0
            public void Exception_When_OffsetAndCountGreatherThanArrayLength()
            {
                var buffer = new Byte[] { 0x11, 0x22, 0x33 };

                Check.ThatCode(() => BufferSpan.From(buffer, 1, 3))
                .Throws <ArgumentOutOfRangeException>()
                .WithProperty(x => x.ParamName, "count");
            }
Exemplo n.º 10
0
            public void Exception_When_CountIsNegative()
            {
                var buffer = new Byte[] { 0x11, 0x22, 0x33, 0x44, 0x55 };

                Check.ThatCode(() => BufferSpan.From(buffer, 0, -1))
                .Throws <ArgumentOutOfRangeException>()
                .WithProperty(x => x.ParamName, "count");
            }
Exemplo n.º 11
0
            public void Usage()
            {
                var buffer = new Byte[] { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 };
                var span   = BufferSpan.From(buffer, 1, 3);

                Check.ThatCode(() => span[-1]).Throws <ArgumentOutOfRangeException>();
                Check.That(span[0]).IsEqualTo(0x11);
                Check.That(span[1]).IsEqualTo(0x22);
                Check.That(span[2]).IsEqualTo(0x33);
                Check.ThatCode(() => span[3]).Throws <ArgumentOutOfRangeException>();
            }
Exemplo n.º 12
0
            public void SevenBytes()
            {
                var span = BufferSpan.From(
                    0x11,
                    0x22,
                    0x33,
                    0x44,
                    0x55,
                    0x66,
                    0x77
                    );

                Check.That(span.ToString()).IsEqualTo("11-22-33-44-55-66-77");
            }
Exemplo n.º 13
0
            public void SevenBytes()
            {
                var span = BufferSpan.From(
                    0x11,
                    0x22,
                    0x33,
                    0x44,
                    0x55,
                    0x66,
                    0x77
                    );

                Check.That(span.ToString(":")).IsEqualTo("11:22:33:44:55:66:77");
            }
Exemplo n.º 14
0
            public void Construction_With_EmptyArray()
            {
                var span = BufferSpan.From();

                Check.That(span.Buffer).IsEmpty();
                Check.That(span.BufferLength).IsEqualTo(0);
                Check.That(span.FreeBytes).IsEqualTo(0);
                Check.That(span.Offset).IsEqualTo(0);
                Check.That(span.Count).IsEqualTo(0);
                Check.That(span.IsEmpty).IsTrue();

                Check.That(span.ToArray()).IsEmpty();
                Check.That(span.ToString()).IsEqualTo("<empty>");
            }
Exemplo n.º 15
0
            public void Construction()
            {
                var span = BufferSpan.From(0x11, 0x22, 0x33);

                Check.That(span.Buffer).ContainsExactly(0x11, 0x22, 0x33);
                Check.That(span.BufferLength).IsEqualTo(3);
                Check.That(span.FreeBytes).IsEqualTo(0);
                Check.That(span.Offset).IsEqualTo(0);
                Check.That(span.Count).IsEqualTo(3);
                Check.That(span.IsEmpty).IsFalse();

                Check.That(span.ToArray()).ContainsExactly(0x11, 0x22, 0x33).And.Not.IsSameReferenceAs(span.Buffer);
                Check.That(span.ToString()).IsEqualTo("11-22-33");
            }
Exemplo n.º 16
0
            public void Construction_With_LargerArray()
            {
                var buffer = new Byte[] { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 };
                var span   = BufferSpan.From(buffer, 1, 3);

                Check.That(span.Buffer).IsSameReferenceAs(buffer);
                Check.That(span.BufferLength).IsEqualTo(6);
                Check.That(span.FreeBytes).IsEqualTo(2);
                Check.That(span.Offset).IsEqualTo(1);
                Check.That(span.Count).IsEqualTo(3);
                Check.That(span.IsEmpty).IsFalse();

                Check.That(span.ToArray()).ContainsExactly(0x11, 0x22, 0x33).And.Not.IsSameReferenceAs(span.Buffer);
                Check.That(span.ToString()).IsEqualTo("11-22-33");
            }
Exemplo n.º 17
0
            public void Construction_With_EmptyArray()
            {
                var buffer = new Byte[] { };
                var span   = BufferSpan.From(buffer, 0, 0);

                Check.That(span.Buffer).IsSameReferenceAs(buffer);
                Check.That(span.BufferLength).IsEqualTo(0);
                Check.That(span.FreeBytes).IsEqualTo(0);
                Check.That(span.Offset).IsEqualTo(0);
                Check.That(span.Count).IsEqualTo(0);
                Check.That(span.IsEmpty).IsTrue();

                Check.That(span.ToArray()).IsEmpty().And.Not.IsSameReferenceAs(span.Buffer);
                Check.That(span.ToString()).IsEqualTo("<empty>");
            }
Exemplo n.º 18
0
            public void NineBytes()
            {
                var span = BufferSpan.From(
                    0x11,
                    0x22,
                    0x33,
                    0x44,
                    0x55,
                    0x66,
                    0x77,
                    0x88,
                    0x99
                    );

                Check.That(span.ToString()).IsEqualTo("11-22-33-44-55-66-77-88--99");
            }
Exemplo n.º 19
0
            public void NineBytes()
            {
                var span = BufferSpan.From(
                    0x11,
                    0x22,
                    0x33,
                    0x44,
                    0x55,
                    0x66,
                    0x77,
                    0x88,
                    0x99
                    );

                Check.That(span.ToString(":")).IsEqualTo("11:22:33:44:55:66:77:88::99");
            }
Exemplo n.º 20
0
            public void Usage()
            {
                var buffer = new Byte[] { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 };
                var span   = BufferSpan.From(buffer, 1, 3);

                var span2 = span.Clear();

                Check.That(span2.Buffer).IsSameReferenceAs(buffer);
                Check.That(span2.BufferLength).IsEqualTo(6);
                Check.That(span2.Offset).IsEqualTo(0);
                Check.That(span2.Count).IsEqualTo(0);
                Check.That(span2.IsEmpty).IsTrue();

                Check.That(span2.ToArray()).IsEmpty().And.Not.IsSameReferenceAs(span.Buffer);
                Check.That(span2.ToString()).IsEqualTo("<empty>");
            }
Exemplo n.º 21
0
            public void Slice_TwoBytesFromExistingData()
            {
                var buffer = new Byte[] { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 };
                var span   = BufferSpan.From(buffer, 1, 4);
                var result = span.Slice(1, 2);

                Check.That(result.Buffer).IsSameReferenceAs(buffer);
                Check.That(result.BufferLength).IsEqualTo(6);
                Check.That(result.FreeBytes).IsEqualTo(2);
                Check.That(result.Offset).IsEqualTo(2);
                Check.That(result.Count).IsEqualTo(2);
                Check.That(result.IsEmpty).IsFalse();

                Check.That(result.ToArray()).ContainsExactly(0x22, 0x33).And.Not.IsSameReferenceAs(span.Buffer);
                Check.That(result.ToString()).IsEqualTo("22-33");
            }
Exemplo n.º 22
0
            public void Discard_AllBytesFromExistingBuffer()
            {
                var buffer = new Byte[] { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 };
                var span   = BufferSpan.From(buffer, 1, 3);
                var result = span.Discard(3);

                Check.That(result.Buffer).IsSameReferenceAs(buffer);
                Check.That(result.BufferLength).IsEqualTo(6);
                Check.That(result.FreeBytes).IsEqualTo(6);
                Check.That(result.Offset).IsEqualTo(0);
                Check.That(result.Count).IsEqualTo(0);
                Check.That(result.IsEmpty).IsTrue();

                Check.That(result.ToArray()).IsEmpty();
                Check.That(result.ToString()).IsEqualTo("<empty>");
            }
Exemplo n.º 23
0
            public void ByteSpan()
            {
                var org = BufferSpan.From(
                    0x11,
                    0x22,
                    0x33,
                    0x44,
                    0x55
                    );

                org = org.Slice(1, 3);

                var span = org.Clone();

                Check.That(span.Buffer).Not.IsSameReferenceAs(org.Buffer);
                Check.That(span.BufferLength).IsEqualTo(3);
                Check.That(span.Offset).IsEqualTo(0);
                Check.That(span.Count).IsEqualTo(3);
                Check.That(span.Buffer).ContainsExactly(0x22, 0x33, 0x44);
            }
Exemplo n.º 24
0
            public void Append_ToEndOfExistingBufferConsolidating()
            {
                var buffer = new Byte[] {
                    0x00,
                    0x11,
                    0x22,
                    0x33,
                    0x44,
                    0x55,
                    0x66,
                    0x77,
                    0x88,
                    0x99,
                };

                var span   = BufferSpan.From(buffer, 6, 3);
                var data   = BufferSpan.From(0xDD, 0xEE);
                var result = span.Append(data);

                Check.That(result.Buffer).IsSameReferenceAs(buffer);
                Check.That(result.BufferLength).IsEqualTo(10);
                Check.That(result.FreeBytes).IsEqualTo(5);
                Check.That(result.Offset).IsEqualTo(0);
                Check.That(result.Count).IsEqualTo(5);
                Check.That(result.IsEmpty).IsFalse();

                Check.That(result.ToArray())
                .ContainsExactly(
                    0x66,
                    0x77,
                    0x88,
                    0xDD,
                    0xEE
                    )
                .And.Not.IsSameReferenceAs(span.Buffer);

                Check.That(result.ToString()).IsEqualTo("66-77-88-DD-EE");
            }
Exemplo n.º 25
0
            public void SixteenBytes()
            {
                var span = BufferSpan.From(
                    0x11,
                    0x22,
                    0x33,
                    0x44,
                    0x55,
                    0x66,
                    0x77,
                    0x88,
                    0x99,
                    0xAA,
                    0xBB,
                    0xCC,
                    0xDD,
                    0xEE,
                    0xFF,
                    0x11
                    );

                Check.That(span.ToString()).IsEqualTo("11-22-33-44-55-66-77-88--99-AA-BB-CC-DD-EE-FF-11");
            }
Exemplo n.º 26
0
            public void SixteenBytes()
            {
                var span = BufferSpan.From(
                    0x11,
                    0x22,
                    0x33,
                    0x44,
                    0x55,
                    0x66,
                    0x77,
                    0x88,
                    0x99,
                    0xAA,
                    0xBB,
                    0xCC,
                    0xDD,
                    0xEE,
                    0xFF,
                    0x11
                    );

                Check.That(span.ToString(String.Empty)).IsEqualTo("112233445566778899AABBCCDDEEFF11");
            }
Exemplo n.º 27
0
            public void SingleByte()
            {
                var span = BufferSpan.From(0x11);

                Check.That(span.ToString(":")).IsEqualTo("11");
            }
Exemplo n.º 28
0
 public void Exception_When_BufferIsNull()
 {
     Check.ThatCode(() => BufferSpan.From(null, 1, 3))
     .Throws <ArgumentNullException>()
     .WithProperty(x => x.ParamName, "array");
 }