public void Test_Tail() { var writer = new SliceWriter(64); var slice = writer.Tail(0); Assert.That(slice.Count, Is.EqualTo(0)); Assert.That(slice.Offset, Is.EqualTo(0)); //note: slice.Array is not guaranteed to be equal to writer.Buffer Assert.That(() => writer.Head(1), Throws.InstanceOf <ArgumentOutOfRangeException>()); writer.WriteBytes(Slice.FromString("hello world!")); slice = writer.Tail(6); Assert.That(slice.Array, Is.SameAs(writer.Buffer)); Assert.That(slice.Offset, Is.EqualTo(6)); Assert.That(slice.Count, Is.EqualTo(6)); Assert.That(slice.ToStringAscii(), Is.EqualTo("world!")); slice = writer.Tail(12); Assert.That(slice.Array, Is.SameAs(writer.Buffer)); Assert.That(slice.Offset, Is.EqualTo(0)); Assert.That(slice.Count, Is.EqualTo(12)); Assert.That(slice.ToStringAscii(), Is.EqualTo("hello world!")); Assert.That(() => writer.Tail(13), Throws.InstanceOf <ArgumentOutOfRangeException>()); Assert.That(() => writer.Tail(-1), Throws.InstanceOf <ArgumentOutOfRangeException>()); writer.WriteBytes(Slice.FromString("foo")); slice = writer.Tail(3); Assert.That(slice.Array, Is.SameAs(writer.Buffer)); Assert.That(slice.Offset, Is.EqualTo(12)); Assert.That(slice.Count, Is.EqualTo(3)); Assert.That(slice.ToStringAscii(), Is.EqualTo("foo")); slice = writer.Tail(15); Assert.That(slice.Array, Is.SameAs(writer.Buffer)); Assert.That(slice.Offset, Is.EqualTo(0)); Assert.That(slice.Count, Is.EqualTo(15)); Assert.That(slice.ToStringAscii(), Is.EqualTo("hello world!foo")); Assert.That(() => writer.Tail(16), Throws.InstanceOf <ArgumentOutOfRangeException>()); }