reactivemarbles/DynamicData

[Bug]: `AddRange` `ChangeSet` has unexpected `Index` of -1

PhilipCavanagh opened this issue ยท 2 comments

Describe the bug ๐Ÿž

While writing a new operator for our internal use, I unexpectedly encountered an AddRange ChangeSet with an Index of -1. I traced it back to line 88 in SourceList.Connect(), which leaves the index at its default of -1.

One of two things is true:

  • It's legal for an AddRange ChangeSet to have an index of -1, and it presumably means something like "this is the initial state of the collection". If that's the case, it ought to be documented somewhere, and I've found nothing.
  • This is a bug and 0 should be passed as the index.

Steps to reproduce

    var source = new SourceList<string>();
    source.Add("A");
    var changeSets = new List<IChangeSet<string>>();
    source.Connect().Subscribe(changeSets.Add).Dispose();
    Trace.Assert(changeSets[0].First().Type == ChangeType.Range);

    // This assertion fails
    Trace.Assert(changeSets[0].First().Range.Index >= 0);

Expected behavior

I was expecting Index to equal zero for an AddRange that initialises the collection.

DynamicData Version

7.13.1

There's a couple references to the index being -1 that I can find.

case IExtendedList<T> extendedList when index >= 0:

var startIndex = item.Range.Index < 0 ? transformed.Count : item.Range.Index;

I don't see any particular reason, other than it being a "shorthand" for saying "append to the end of the list". Definitely could use a bit of documentation on RangeChange<T>.Index if that's the case.

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.