Share a source index across each pipeline run
This commit is contained in:
@@ -18,6 +18,15 @@ func NewSourceRefOrder(doc *source.SourceDocument) SourceRefOrder {
|
||||
return NewSourceRefOrderFromIndex(source.NewDocumentIndex(doc))
|
||||
}
|
||||
|
||||
// NewSourceRefOrderForSource uses a borrowed whole-source index when provided.
|
||||
// The caller must supply an index for doc; otherwise one is built locally.
|
||||
func NewSourceRefOrderForSource(doc *source.SourceDocument, index *source.DocumentIndex) SourceRefOrder {
|
||||
if index != nil {
|
||||
return NewSourceRefOrderFromIndex(*index)
|
||||
}
|
||||
return NewSourceRefOrder(doc)
|
||||
}
|
||||
|
||||
// NewSourceRefOrderFromIndex captures source identity and unit positions from
|
||||
// one document index for source-reference comparison and canonicalization.
|
||||
func NewSourceRefOrderFromIndex(index source.DocumentIndex) SourceRefOrder {
|
||||
|
||||
@@ -34,6 +34,18 @@ func TestSourceRefOrderUsesDocumentOrderAndLiteralFallbacks(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSourceRefOrderForSourceUsesOptionalWholeSourceIndex(t *testing.T) {
|
||||
doc := unitRefSourceDocument(30, 10, 20)
|
||||
index := source.NewDocumentIndex(doc)
|
||||
refs := []source.SourceRef{{SourceID: doc.ID, StartUnitID: 20, EndUnitID: 20}, {SourceID: doc.ID, StartUnitID: 30, EndUnitID: 30}}
|
||||
want := []source.SourceRef{refs[1], refs[0]}
|
||||
for _, supplied := range []*source.DocumentIndex{nil, &index} {
|
||||
if got := NewSourceRefOrderForSource(doc, supplied).Canonicalize(refs); !reflect.DeepEqual(got, want) {
|
||||
t.Fatalf("Canonicalize() = %#v, want %#v", got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSourceRefOrderCanonicalizePreservesRepresentationAndOwnership(t *testing.T) {
|
||||
order := NewSourceRefOrder(unitRefSourceDocument(3, 1, 2))
|
||||
if got := order.Canonicalize(nil); got != nil {
|
||||
|
||||
Reference in New Issue
Block a user