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 @@ -102,6 +102,7 @@ public void Reset()
_segments.Clear();
_length = 0;
_capacity = 0;
Position = 0;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,32 @@ public void Reset_AfterWrite_LengthResetToZero(int writeCount)
Assert.Equal(0, stream.Length);
}

/// <summary>
/// Verifies that calling Reset resets the Position property to zero.
/// This is important when recycling streams from the pool to ensure the position
/// doesn't carry over from previous usage.
/// </summary>
/// <param name="initialPosition">The initial position to set before calling Reset.</param>
[Theory]
[InlineData(0)]
[InlineData(10)]
[InlineData(100)]
[InlineData(1024)]
public void Reset_WithPosition_ResetsPositionToZero(int initialPosition)
{
// Arrange
using var stream = new PooledBufferStream();
stream.SetLength(2000); // Set length large enough to accommodate position
stream.Position = initialPosition;

// Act
stream.Reset();

// Assert
Assert.Equal(0, stream.Position);
Assert.Equal(0, stream.Length);
}

/// <summary>
/// Verifies that RentReadOnlySequence returns a correct ReadOnlySequence for various data lengths.
/// When no data has been written, an empty sequence is returned; otherwise, the sequence matches the written data.
Expand Down