diff --git a/src/DotNext.Tests/BasicExtensionsTests.cs b/src/DotNext.Tests/BasicExtensionsTests.cs index 26d907f1e..0da65cecc 100644 --- a/src/DotNext.Tests/BasicExtensionsTests.cs +++ b/src/DotNext.Tests/BasicExtensionsTests.cs @@ -168,8 +168,8 @@ public static void CaptureData() [Fact] public static void OneOfValues() { - True(2.IsOneOf([2, 5, 7])); - False(2.IsOneOf([3, 5, 7])); + True(2.IsOneOf(stackalloc int[] { 2, 5, 7 })); + False(2.IsOneOf(stackalloc int[] { 3, 5, 7 })); } [Fact] diff --git a/src/DotNext.Tests/Buffers/BufferWriterSlimTests.cs b/src/DotNext.Tests/Buffers/BufferWriterSlimTests.cs index 4de896deb..add7d2e59 100644 --- a/src/DotNext.Tests/Buffers/BufferWriterSlimTests.cs +++ b/src/DotNext.Tests/Buffers/BufferWriterSlimTests.cs @@ -13,7 +13,7 @@ public static void GrowableBuffer() Equal(2, builder.Capacity); Equal(2, builder.FreeCapacity); - builder.Write(new int[] { 10, 20 }); + builder.Write(stackalloc int[] { 10, 20 }); Equal(2, builder.WrittenCount); Equal(2, builder.Capacity); Equal(0, builder.FreeCapacity); @@ -21,7 +21,7 @@ public static void GrowableBuffer() Equal(10, builder[0]); Equal(20, builder[1]); - builder.Write([30, 40]); + builder.Write(stackalloc int[] { 30, 40 }); Equal(4, builder.WrittenCount); True(builder.Capacity >= 2); Equal(30, builder[2]); @@ -33,7 +33,7 @@ public static void GrowableBuffer() builder.Clear(true); Equal(0, builder.WrittenCount); - builder.Write([50, 60, 70, 80]); + builder.Write(stackalloc int[] { 50, 60, 70, 80 }); Equal(4, builder.WrittenCount); True(builder.Capacity >= 2); Equal(50, builder[0]); @@ -43,7 +43,7 @@ public static void GrowableBuffer() builder.Clear(false); Equal(0, builder.WrittenCount); - builder.Write([10, 20, 30, 40]); + builder.Write(stackalloc int[] { 10, 20, 30, 40 }); Equal(4, builder.WrittenCount); True(builder.Capacity >= 2); Equal(10, builder[0]); diff --git a/src/DotNext.Tests/Buffers/ReadOnlySpanConsumerTests.cs b/src/DotNext.Tests/Buffers/ReadOnlySpanConsumerTests.cs index 96da88d25..3756bb69f 100644 --- a/src/DotNext.Tests/Buffers/ReadOnlySpanConsumerTests.cs +++ b/src/DotNext.Tests/Buffers/ReadOnlySpanConsumerTests.cs @@ -32,8 +32,8 @@ public static void BufferConsumerWriteMethods() { var ms = new ArrayBufferWriter(); IReadOnlySpanConsumer consumer = new BufferConsumer(ms); - consumer.Invoke(new ReadOnlySpan(new char[] { '1', '2' })); - consumer.Invoke(new ReadOnlyMemory(new char[] { '3', '4' }), default); + consumer.Invoke(stackalloc char[] { '1', '2' }); + consumer.Invoke(new char[] { '3', '4' }, default); Equal("1234", ms.WrittenSpan.ToString()); } diff --git a/src/DotNext.Tests/Collections/Generic/SetTests.cs b/src/DotNext.Tests/Collections/Generic/SetTests.cs index e8706c52d..40809d81e 100644 --- a/src/DotNext.Tests/Collections/Generic/SetTests.cs +++ b/src/DotNext.Tests/Collections/Generic/SetTests.cs @@ -26,7 +26,7 @@ public static void SingletonSet() False(set.Overlaps(new int[] { 30, 40 })); True(set.SetEquals(ImmutableHashSet.Create(10))); - False(set.SetEquals(ImmutableHashSet.Create([10, 20]))); + False(set.SetEquals(ImmutableHashSet.Create(stackalloc int[] { 10, 20 }))); } [Fact] @@ -66,10 +66,10 @@ public static void SetOperations() True(set.IsSupersetOf(ImmutableHashSet.Empty)); True(set.IsProperSupersetOf(ImmutableHashSet.Empty)); - True(set.Overlaps(ImmutableHashSet.Create([-1L, 0L]))); + True(set.Overlaps(ImmutableHashSet.Create(stackalloc long[] { -1L, 0L }))); - False(set.IsProperSubsetOf(ImmutableHashSet.Create([-1L, 0L]))); - True(set.IsSubsetOf(ImmutableHashSet.Create([0L, 1L, 2L, 3L]))); - True(set.IsProperSubsetOf(ImmutableHashSet.Create([0L, 1L, 2L, 3L]))); + False(set.IsProperSubsetOf(ImmutableHashSet.Create(stackalloc long[] { -1L, 0L }))); + True(set.IsSubsetOf(ImmutableHashSet.Create(stackalloc long[] { 0L, 1L, 2L, 3L }))); + True(set.IsProperSubsetOf(ImmutableHashSet.Create(stackalloc long[] { 0L, 1L, 2L, 3L }))); } } \ No newline at end of file diff --git a/src/DotNext.Tests/IO/TextConsumerTests.cs b/src/DotNext.Tests/IO/TextConsumerTests.cs index fbed8e7a5..0006472fc 100644 --- a/src/DotNext.Tests/IO/TextConsumerTests.cs +++ b/src/DotNext.Tests/IO/TextConsumerTests.cs @@ -30,8 +30,8 @@ public static void WriteMethods() { using var ms = new StringWriter(); IReadOnlySpanConsumer consumer = new TextConsumer(ms); - consumer.Invoke(new ReadOnlySpan(new char[] { '1', '2' })); - consumer.Invoke(new ReadOnlyMemory(new char[] { '3', '4' }), default); + consumer.Invoke(stackalloc char[] { '1', '2' }); + consumer.Invoke(new char[] { '3', '4' }, default); Equal("1234", ms.ToString()); } } \ No newline at end of file diff --git a/src/DotNext.Tests/SpanTests.cs b/src/DotNext.Tests/SpanTests.cs index 9876cba66..ba98afd75 100644 --- a/src/DotNext.Tests/SpanTests.cs +++ b/src/DotNext.Tests/SpanTests.cs @@ -44,7 +44,7 @@ public static unsafe void SortingUsingPointer() [Fact] public static void IndexOf() { - ReadOnlySpan span = [3, 2, 6, 4]; + ReadOnlySpan span = stackalloc ulong[] { 3, 2, 6, 4 }; Equal(1, span.IndexOf(2UL, 0, EqualityComparer.Default.Equals)); Equal(3, span.IndexOf(4UL, 0, EqualityComparer.Default.Equals)); Equal(3UL, span[0]); @@ -54,7 +54,7 @@ public static void IndexOf() [Fact] public static void ForEach() { - Span span = new long[] { 3, 2, 6, 4 }; + Span span = stackalloc long[] { 3, 2, 6, 4 }; span.ForEach((ref long value, int index) => value += index); Equal(3, span[0]); Equal(3, span[1]); @@ -77,7 +77,7 @@ public static void TrimByLength1() [Fact] public static void TrimByLength2() { - ReadOnlySpan span = [1, 2, 3]; + ReadOnlySpan span = stackalloc int[] { 1, 2, 3 }; span = span.TrimLength(4); Equal(3, span.Length); span = span.TrimLength(2); @@ -478,37 +478,37 @@ public static void TransformElements() // left < right Span input = [1, 2, 3, 4, 5, 6]; input.Swap(0..2, 3..6); - Equal(new int[] { 4, 5, 6, 3, 1, 2 }, input.ToArray()); + Equal(stackalloc int[] { 4, 5, 6, 3, 1, 2 }, input); // left > right input = [1, 2, 3, 4, 5, 6]; input.Swap(0..3, 4..6); - Equal([5, 6, 4, 1, 2, 3], input); + Equal(stackalloc int[] { 5, 6, 4, 1, 2, 3 }, input); // left is zero length input = [1, 2, 3, 4, 5, 6]; input.Swap(1..1, 3..6); - Equal([1, 4, 5, 6, 2, 3], input); + Equal(stackalloc int[] { 1, 4, 5, 6, 2, 3 }, input); // right is zero length input = [1, 2, 3, 4, 5, 6]; input.Swap(0..2, 3..3); - Equal([3, 1, 2, 4, 5, 6], input); + Equal(stackalloc int[] { 3, 1, 2, 4, 5, 6 }, input); // no space between ranges input = [1, 2, 3, 4, 5, 6]; input.Swap(0..2, 2..6); - Equal([3, 4, 5, 6, 1, 2], input); + Equal(stackalloc int[] { 3, 4, 5, 6, 1, 2 }, input); // left == right input = [1, 2, 3, 4, 5, 6]; input.Swap(0..3, 3..6); - Equal([4, 5, 6, 1, 2, 3], input); + Equal(stackalloc int[] { 4, 5, 6, 1, 2, 3 }, input); // left and right are empty input = [1, 2, 3, 4, 5, 6]; input.Swap(1..1, 5..5); - Equal([1, 2, 3, 4, 5, 6], input); + Equal(stackalloc int[] { 1, 2, 3, 4, 5, 6 }, input); // overlapping Throws(() => new int[] { 1, 2, 3, 4, 5, 6 }.AsSpan().Swap(0..2, 1..3)); @@ -520,16 +520,16 @@ public static void MoveRange() // move from left to right Span input = [1, 2, 3, 4, 5, 6]; input.Move(0..2, 3); - Equal([3, 1, 2, 4, 5, 6], input); + Equal(stackalloc int[] { 3, 1, 2, 4, 5, 6 }, input); // move from left to right input = [1, 2, 3, 4, 5, 6]; input.Move(1..3, 6); - Equal([1, 4, 5, 6, 2, 3], input); + Equal(stackalloc int[] { 1, 4, 5, 6, 2, 3 }, input); // move from right to left input.Move(4..6, 1); - Equal([1, 2, 3, 4, 5, 6], input); + Equal(stackalloc int[] { 1, 2, 3, 4, 5, 6 }, input); // out of range Throws(() => new int[] { 1, 2, 3, 4, 5, 6 }.AsSpan().Move(0..2, 1));