diff --git a/src/Geralt.Tests/SpansTests.cs b/src/Geralt.Tests/SpansTests.cs index 0082bda..f9825e0 100644 --- a/src/Geralt.Tests/SpansTests.cs +++ b/src/Geralt.Tests/SpansTests.cs @@ -70,4 +70,27 @@ public void Concat_SixSpans() Span expected = Concat(Array1, Array2, Array3, Array4, Array5, Array6); Assert.IsTrue(concatenated.SequenceEqual(expected)); } + + [TestMethod] + public void Concat_TwoSpansBothEmpty() + { + Span empty1 = Span.Empty; + Span empty2 = Span.Empty; + Span concatenated = stackalloc byte[empty1.Length + empty2.Length]; + Spans.Concat(concatenated, empty1, empty2); + Span expected = Concat(empty1.ToArray(), empty2.ToArray()); + Assert.IsTrue(concatenated.SequenceEqual(expected)); + } + + [TestMethod] + public void Concat_TwoSpansOneEmpty() + { + Span empty = Span.Empty; + Span concatenated = stackalloc byte[empty.Length + Array2.Length]; + Spans.Concat(concatenated, empty, Array2); + Span expected = Concat(empty.ToArray(), Array2); + Assert.IsTrue(concatenated.SequenceEqual(expected)); + Spans.Concat(concatenated, Array2, empty); + Assert.IsTrue(concatenated.SequenceEqual(expected)); + } } \ No newline at end of file diff --git a/src/Geralt/Helpers/Spans.cs b/src/Geralt/Helpers/Spans.cs index 0a897f1..bb5d20f 100644 --- a/src/Geralt/Helpers/Spans.cs +++ b/src/Geralt/Helpers/Spans.cs @@ -7,8 +7,6 @@ public static void Concat(Span buffer, ReadOnlySpan a, ReadOnlySpan< checked { Validation.EqualToSize(nameof(buffer), buffer.Length, a.Length + b.Length); - Validation.NotEmpty(nameof(a), a.Length); - Validation.NotEmpty(nameof(b), b.Length); Validation.EqualToSize(nameof(a), a.Length, buffer.Length - b.Length); Validation.EqualToSize(nameof(b), b.Length, buffer.Length - a.Length); a.CopyTo(buffer.Slice(start: 0, a.Length)); @@ -21,9 +19,6 @@ public static void Concat(Span buffer, ReadOnlySpan a, ReadOnlySpan< checked { Validation.EqualToSize(nameof(buffer), buffer.Length, a.Length + b.Length + c.Length); - Validation.NotEmpty(nameof(a), a.Length); - Validation.NotEmpty(nameof(b), b.Length); - Validation.NotEmpty(nameof(c), c.Length); Validation.EqualToSize(nameof(a), a.Length, buffer.Length - b.Length - c.Length); Validation.EqualToSize(nameof(b), b.Length, buffer.Length - a.Length - c.Length); Validation.EqualToSize(nameof(c), c.Length, buffer.Length - a.Length - b.Length); @@ -38,10 +33,6 @@ public static void Concat(Span buffer, ReadOnlySpan a, ReadOnlySpan< checked { Validation.EqualToSize(nameof(buffer), buffer.Length, a.Length + b.Length + c.Length + d.Length); - Validation.NotEmpty(nameof(a), a.Length); - Validation.NotEmpty(nameof(b), b.Length); - Validation.NotEmpty(nameof(c), c.Length); - Validation.NotEmpty(nameof(d), d.Length); Validation.EqualToSize(nameof(a), a.Length, buffer.Length - b.Length - c.Length - d.Length); Validation.EqualToSize(nameof(b), b.Length, buffer.Length - a.Length - c.Length - d.Length); Validation.EqualToSize(nameof(c), c.Length, buffer.Length - a.Length - b.Length - d.Length); @@ -58,11 +49,6 @@ public static void Concat(Span buffer, ReadOnlySpan a, ReadOnlySpan< checked { Validation.EqualToSize(nameof(buffer), buffer.Length, a.Length + b.Length + c.Length + d.Length + e.Length); - Validation.NotEmpty(nameof(a), a.Length); - Validation.NotEmpty(nameof(b), b.Length); - Validation.NotEmpty(nameof(c), c.Length); - Validation.NotEmpty(nameof(d), d.Length); - Validation.NotEmpty(nameof(e), e.Length); Validation.EqualToSize(nameof(a), a.Length, buffer.Length - b.Length - c.Length - d.Length - e.Length); Validation.EqualToSize(nameof(b), b.Length, buffer.Length - a.Length - c.Length - d.Length - e.Length); Validation.EqualToSize(nameof(c), c.Length, buffer.Length - a.Length - b.Length - d.Length - e.Length); @@ -81,12 +67,6 @@ public static void Concat(Span buffer, ReadOnlySpan a, ReadOnlySpan< checked { Validation.EqualToSize(nameof(buffer), buffer.Length, a.Length + b.Length + c.Length + d.Length + e.Length + f.Length); - Validation.NotEmpty(nameof(a), a.Length); - Validation.NotEmpty(nameof(b), b.Length); - Validation.NotEmpty(nameof(c), c.Length); - Validation.NotEmpty(nameof(d), d.Length); - Validation.NotEmpty(nameof(e), e.Length); - Validation.NotEmpty(nameof(f), f.Length); Validation.EqualToSize(nameof(a), a.Length, buffer.Length - b.Length - c.Length - d.Length - e.Length - f.Length); Validation.EqualToSize(nameof(b), b.Length, buffer.Length - a.Length - c.Length - d.Length - e.Length - f.Length); Validation.EqualToSize(nameof(c), c.Length, buffer.Length - a.Length - b.Length - d.Length - e.Length - f.Length);