Skip to content

Commit

Permalink
Merge pull request #408 from tonyhallett/fix-updated-line-numbers-out…
Browse files Browse the repository at this point in the history
…-of-range

Fix updated line numbers out of range
  • Loading branch information
tonyhallett authored Mar 20, 2024
2 parents a5fb411 + 26fcd77 commit 2071f51
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,30 +235,31 @@ public void Should_Send_CoverageChangedMessage_When_Necessary(

[TestCase(true)]
[TestCase(false)]
public void Should_Update_TrackedLines_When_Text_Buffer_ChangedOnBackground(bool textLinesChanged)
public void Should_Update_TrackedLines_When_Text_Buffer_ChangedOnBackground(bool linesInRange)
{
SimpleTextInfoSetUp();

var afterSnapshot = new Mock<ITextSnapshot>().Object;
var mockAfterSnapshot = new Mock<ITextSnapshot>();
mockAfterSnapshot.SetupGet(textSnapshot => textSnapshot.LineCount).Returns(linesInRange ? 100 : 11);

var newSpan = new Span(1, 2);
var mockTrackedLines = new Mock<ITrackedLines>();
var changedLineNumbers = textLinesChanged ? new List<int> { 1, 2 } : new List<int>();
mockTrackedLines.Setup(trackedLines => trackedLines.GetChangedLineNumbers(afterSnapshot, new List<Span> { newSpan }))
var changedLineNumbers = new List<int> { 11, 12 };
mockTrackedLines.Setup(trackedLines => trackedLines.GetChangedLineNumbers(mockAfterSnapshot.Object, new List<Span> { newSpan }))
.Returns(changedLineNumbers);
autoMoqer.Setup<ITrackedLinesFactory, ITrackedLines>(trackedLinesFactory => trackedLinesFactory.Create(It.IsAny<List<ILine>>(), It.IsAny<ITextSnapshot>(), It.IsAny<Language>()))
.Returns(mockTrackedLines.Object);


var bufferLineCoverage = autoMoqer.Create<BufferLineCoverage>();

mockTextBuffer.Raise(textBuffer => textBuffer.ChangedOnBackground += null, CreateTextContentChangedEventArgs(afterSnapshot, newSpan));
mockTextBuffer.Raise(textBuffer => textBuffer.ChangedOnBackground += null, CreateTextContentChangedEventArgs(mockAfterSnapshot.Object, newSpan));

autoMoqer.Verify<IEventAggregator>(
eventAggregator => eventAggregator.SendMessage(
It.Is<CoverageChangedMessage>(message => message.AppliesTo == "filepath" && message.BufferLineCoverage == bufferLineCoverage && message.ChangedLineNumbers == changedLineNumbers)
It.Is<CoverageChangedMessage>(message => message.AppliesTo == "filepath" && message.BufferLineCoverage == bufferLineCoverage && message.ChangedLineNumbers.SequenceEqual(changedLineNumbers))
, null
), Times.Exactly(textLinesChanged ? 1 : 0));
), Times.Exactly(linesInRange ? 1 : 0));

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ private void TextBuffer_ChangedOnBackground(object sender, TextContentChangedEve

private void UpdateTrackedLines(TextContentChangedEventArgs e)
{
IEnumerable<int> changedLineNumbers = this.trackedLines.GetChangedLineNumbers(e.After, e.Changes.Select(change => change.NewSpan).ToList());
IEnumerable<int> changedLineNumbers = this.trackedLines.GetChangedLineNumbers(e.After, e.Changes.Select(change => change.NewSpan).ToList())
.Where(changedLine => changedLine >= 0 && changedLine < e.After.LineCount);
this.SendCoverageChangedMessageIfChanged(changedLineNumbers);
}

Expand Down

0 comments on commit 2071f51

Please sign in to comment.