Skip to content

Commit d01481d

Browse files
committed
Improved test coverage
1 parent 339a3bf commit d01481d

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

src/DotNext.Tests/Buffers/MemoryWriterTests.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Buffers;
2+
using System.Collections.Immutable;
23

34
namespace DotNext.Buffers;
45

@@ -388,4 +389,34 @@ public static void RemoveHeadElements()
388389
Equal(0, writer.WrittenCount);
389390
Throws<ArgumentOutOfRangeException>(() => writer.RemoveFirst(-1));
390391
}
392+
393+
[Theory]
394+
[MemberData(nameof(CollectionsToAdd))]
395+
public static void AddAll(ICollection<int> items)
396+
{
397+
using (var writer = new PoolingBufferWriter<int>())
398+
{
399+
AddElements(writer, items);
400+
}
401+
402+
using (var writer = new PoolingArrayBufferWriter<int>())
403+
{
404+
AddElements(writer, items);
405+
}
406+
407+
static void AddElements(BufferWriter<int> writer, ICollection<int> items)
408+
{
409+
writer.AddAll(items);
410+
Equal(writer, items);
411+
}
412+
}
413+
414+
public static TheoryData<ICollection<int>> CollectionsToAdd =>
415+
[
416+
ImmutableArray<int>.Empty,
417+
new[] { 1, 2, 3 },
418+
new List<int> { 1, 2, 3 },
419+
new ArraySegment<int>([1, 2, 3]),
420+
ImmutableList.Create(1, 2, 3)
421+
];
391422
}

src/DotNext/Buffers/BufferWriter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public void Add(T item)
153153
/// <exception cref="ObjectDisposedException">This writer has been disposed.</exception>
154154
public virtual void AddAll(ICollection<T> items)
155155
{
156-
if (items.Count == 0)
156+
if (items.Count is 0)
157157
return;
158158

159159
var span = GetSpan(items.Count);

0 commit comments

Comments
 (0)