Finish the D&D module cleanup
This commit is contained in:
@@ -15,16 +15,17 @@ type SourceRefOrder struct {
|
||||
|
||||
// NewSourceRefOrder captures the source identity and unit positions from doc.
|
||||
func NewSourceRefOrder(doc *source.SourceDocument) SourceRefOrder {
|
||||
return NewSourceRefOrderWithIndex(doc, source.NewDocumentIndex(doc))
|
||||
return NewSourceRefOrderFromIndex(source.NewDocumentIndex(doc))
|
||||
}
|
||||
|
||||
// NewSourceRefOrderWithIndex captures source identity with a supplied
|
||||
// document index for source-reference comparison and canonicalization.
|
||||
func NewSourceRefOrderWithIndex(doc *source.SourceDocument, index source.DocumentIndex) SourceRefOrder {
|
||||
if doc == nil {
|
||||
// NewSourceRefOrderFromIndex captures source identity and unit positions from
|
||||
// one document index for source-reference comparison and canonicalization.
|
||||
func NewSourceRefOrderFromIndex(index source.DocumentIndex) SourceRefOrder {
|
||||
sourceID, ok := index.DocumentID()
|
||||
if !ok {
|
||||
return SourceRefOrder{}
|
||||
}
|
||||
return SourceRefOrder{sourceID: doc.ID, index: index}
|
||||
return SourceRefOrder{sourceID: sourceID, index: index}
|
||||
}
|
||||
|
||||
// Less orders references by source identity, then document positions when
|
||||
|
||||
@@ -60,19 +60,22 @@ func TestSourceRefOrderCanonicalizePreservesRepresentationAndOwnership(t *testin
|
||||
|
||||
func TestSourceRefOrderSnapshotAndEarliestValid(t *testing.T) {
|
||||
doc := unitRefSourceDocument(30, 10, 20)
|
||||
order := NewSourceRefOrder(doc)
|
||||
sourceID := doc.ID
|
||||
index := source.NewDocumentIndex(doc)
|
||||
order := NewSourceRefOrderFromIndex(index)
|
||||
doc.ID = "changed"
|
||||
doc.Units[0].ID, doc.Units[1].ID = 10, 30
|
||||
refs := []source.SourceRef{
|
||||
{SourceID: doc.ID, StartUnitID: 20, EndUnitID: 20},
|
||||
{SourceID: doc.ID, StartUnitID: 10, EndUnitID: 10},
|
||||
{SourceID: sourceID, StartUnitID: 20, EndUnitID: 20},
|
||||
{SourceID: sourceID, StartUnitID: 10, EndUnitID: 10},
|
||||
{SourceID: "other", StartUnitID: 1, EndUnitID: 1},
|
||||
{SourceID: doc.ID, StartUnitID: 999, EndUnitID: 999},
|
||||
{SourceID: doc.ID, StartUnitID: 20, EndUnitID: 30},
|
||||
{SourceID: sourceID, StartUnitID: 999, EndUnitID: 999},
|
||||
{SourceID: sourceID, StartUnitID: 20, EndUnitID: 30},
|
||||
}
|
||||
if position, ok := order.EarliestValid(refs); !ok || position != 1 {
|
||||
t.Fatalf("EarliestValid() = %d, %t, want 1, true", position, ok)
|
||||
}
|
||||
if position, ok := order.EarliestValid([]source.SourceRef{{SourceID: doc.ID, StartUnitID: 20, EndUnitID: 30}}); ok || position != 0 {
|
||||
if position, ok := order.EarliestValid([]source.SourceRef{{SourceID: sourceID, StartUnitID: 20, EndUnitID: 30}}); ok || position != 0 {
|
||||
t.Fatalf("EarliestValid(invalid) = %d, %t, want 0, false", position, ok)
|
||||
}
|
||||
if position, ok := (SourceRefOrder{}).EarliestValid(refs); ok || position != 0 {
|
||||
|
||||
Reference in New Issue
Block a user