Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: LGPL-3.0-only

using System;
using System.Buffers;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -336,6 +337,32 @@ public void Dispose_recursive()
list.DisposeRecursive();
}

[Test]
public void RemoveAt_should_not_throw_when_capacity_equals_count()
{
ArrayPool<int> pool = new ExactSizeArrayPool<int>();
using ArrayPoolList<int> list = new(pool, 8, 8);

for (int i = 0; i < list.Count; i++)
{
list[i] = i;
}

Action act = () => list.RemoveAt(2);

act.Should().NotThrow();
list.Should().BeEquivalentTo(new[] { 0, 1, 3, 4, 5, 6, 7 });
}

private sealed class ExactSizeArrayPool<T> : ArrayPool<T>
{
public override T[] Rent(int minimumLength) => new T[minimumLength];

public override void Return(T[] array, bool clearArray = false)
{
}
}

#if DEBUG
[Test]
[Explicit("Crashes the test runner")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public static bool RemoveAt(T[] array, ref int count, int index, bool shouldThro
int start = index + 1;
if (start < count)
{
array.AsMemory(start, count - index).CopyTo(array.AsMemory(index));
array.AsMemory(start, count - start).CopyTo(array.AsMemory(index));
}

count--;
Expand Down
Loading