Skip to content

Commit

Permalink
Merge pull request #34 from AArnott/FixAdvanceToBug2
Browse files Browse the repository at this point in the history
Fix another Sequence<T> AdvanceTo bug
  • Loading branch information
AArnott authored Sep 15, 2018
2 parents 01049af + 18a04bd commit ea5acaa
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions src/Nerdbank.Streams.Tests/SequenceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,26 @@ public void AdvanceTo_InterweavedWith_Advance()
Assert.Equal(origLastChar, seq.AsReadOnlySequence.Slice(origLastCharPosition, 1).First.Span[0]);
}

[Fact]
public void AdvanceTo_InterweavedWith_Advance2()
{
// use the mock pool so that we can predict the actual array size will not exceed what we ask for.
var seq = new Sequence<int>(new MockPool<int>());

seq.GetSpan(10);
seq.Advance(10);

seq.AdvanceTo(seq.AsReadOnlySequence.GetPosition(3));

seq.GetSpan(10);
seq.Advance(10);

seq.GetSpan(10);
seq.Advance(10);

Assert.Equal(10 - 3 + 10 + 10, seq.AsReadOnlySequence.Length);
}

[Fact]
public void Dispose_ReturnsArraysToPool()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Nerdbank.Streams/Sequence`1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ internal void SetNext(SequenceSegment segment)
Requires.NotNull(segment, nameof(segment));

this.Next = segment;
segment.RunningIndex = this.RunningIndex + this.Length;
segment.RunningIndex = this.RunningIndex + this.End;
}

internal void AdvanceTo(int offset)
Expand Down

0 comments on commit ea5acaa

Please sign in to comment.