Skip to content

Commit

Permalink
Collection literal is not compatible with ROS<T>
Browse files Browse the repository at this point in the history
  • Loading branch information
sakno committed Jan 12, 2024
1 parent 14154e1 commit 3b11ea2
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 28 deletions.
4 changes: 2 additions & 2 deletions src/DotNext.Tests/BasicExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
8 changes: 4 additions & 4 deletions src/DotNext.Tests/Buffers/BufferWriterSlimTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ 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);

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]);
Expand All @@ -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]);
Expand All @@ -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]);
Expand Down
4 changes: 2 additions & 2 deletions src/DotNext.Tests/Buffers/ReadOnlySpanConsumerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public static void BufferConsumerWriteMethods()
{
var ms = new ArrayBufferWriter<char>();
IReadOnlySpanConsumer<char> consumer = new BufferConsumer<char>(ms);
consumer.Invoke(new ReadOnlySpan<char>(new char[] { '1', '2' }));
consumer.Invoke(new ReadOnlyMemory<char>(new char[] { '3', '4' }), default);
consumer.Invoke(stackalloc char[] { '1', '2' });
consumer.Invoke(new char[] { '3', '4' }, default);
Equal("1234", ms.WrittenSpan.ToString());
}

Expand Down
10 changes: 5 additions & 5 deletions src/DotNext.Tests/Collections/Generic/SetTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(stackalloc int[] { 10, 20 })));
}

[Fact]
Expand Down Expand Up @@ -66,10 +66,10 @@ public static void SetOperations()
True(set.IsSupersetOf(ImmutableHashSet<long>.Empty));
True(set.IsProperSupersetOf(ImmutableHashSet<long>.Empty));

True(set.Overlaps(ImmutableHashSet.Create([-1L, 0L])));
True(set.Overlaps(ImmutableHashSet.Create<long>(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<long>(stackalloc long[] { -1L, 0L })));
True(set.IsSubsetOf(ImmutableHashSet.Create<long>(stackalloc long[] { 0L, 1L, 2L, 3L })));
True(set.IsProperSubsetOf(ImmutableHashSet.Create<long>(stackalloc long[] { 0L, 1L, 2L, 3L })));
}
}
4 changes: 2 additions & 2 deletions src/DotNext.Tests/IO/TextConsumerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public static void WriteMethods()
{
using var ms = new StringWriter();
IReadOnlySpanConsumer<char> consumer = new TextConsumer(ms);
consumer.Invoke(new ReadOnlySpan<char>(new char[] { '1', '2' }));
consumer.Invoke(new ReadOnlyMemory<char>(new char[] { '3', '4' }), default);
consumer.Invoke(stackalloc char[] { '1', '2' });
consumer.Invoke(new char[] { '3', '4' }, default);
Equal("1234", ms.ToString());
}
}
26 changes: 13 additions & 13 deletions src/DotNext.Tests/SpanTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static unsafe void SortingUsingPointer()
[Fact]
public static void IndexOf()
{
ReadOnlySpan<ulong> span = [3, 2, 6, 4];
ReadOnlySpan<ulong> span = stackalloc ulong[] { 3, 2, 6, 4 };
Equal(1, span.IndexOf(2UL, 0, EqualityComparer<ulong>.Default.Equals));
Equal(3, span.IndexOf(4UL, 0, EqualityComparer<ulong>.Default.Equals));
Equal(3UL, span[0]);
Expand All @@ -54,7 +54,7 @@ public static void IndexOf()
[Fact]
public static void ForEach()
{
Span<long> span = new long[] { 3, 2, 6, 4 };
Span<long> span = stackalloc long[] { 3, 2, 6, 4 };
span.ForEach((ref long value, int index) => value += index);
Equal(3, span[0]);
Equal(3, span[1]);
Expand All @@ -77,7 +77,7 @@ public static void TrimByLength1()
[Fact]
public static void TrimByLength2()
{
ReadOnlySpan<int> span = [1, 2, 3];
ReadOnlySpan<int> span = stackalloc int[] { 1, 2, 3 };
span = span.TrimLength(4);
Equal(3, span.Length);
span = span.TrimLength(2);
Expand Down Expand Up @@ -478,37 +478,37 @@ public static void TransformElements()
// left < right
Span<int> 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<ArgumentException>(() => new int[] { 1, 2, 3, 4, 5, 6 }.AsSpan().Swap(0..2, 1..3));
Expand All @@ -520,16 +520,16 @@ public static void MoveRange()
// move from left to right
Span<int> 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<ArgumentOutOfRangeException>(() => new int[] { 1, 2, 3, 4, 5, 6 }.AsSpan().Move(0..2, 1));
Expand Down

0 comments on commit 3b11ea2

Please sign in to comment.