From cae4bcce7b12e7e4400dd21c803c1850dbdbaca8 Mon Sep 17 00:00:00 2001 From: Leandro Fernandes Date: Wed, 16 Jun 2021 07:52:10 -0300 Subject: [PATCH] Add test to ensure "Batch" doesn't reuse internal array (#820) --- MoreLinq.Test/BatchTest.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/MoreLinq.Test/BatchTest.cs b/MoreLinq.Test/BatchTest.cs index bc4bec843..c5c9186e7 100644 --- a/MoreLinq.Test/BatchTest.cs +++ b/MoreLinq.Test/BatchTest.cs @@ -79,6 +79,22 @@ public void BatchSequenceYieldsListsOfBatches() reader.ReadEnd(); } + [Test] + public void BatchSequencesAreIndependentInstances() + { + var result = new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }.Batch(4); + + using var reader = result.Read(); + var first = reader.Read(); + var second = reader.Read(); + var third = reader.Read(); + reader.ReadEnd(); + + first.AssertSequenceEqual(1, 2, 3, 4); + second.AssertSequenceEqual(5, 6, 7, 8); + third.AssertSequenceEqual(9); + } + [Test] public void BatchIsLazy() {