Preserve literal ordering for foreign source references
This commit is contained in:
@@ -38,7 +38,7 @@ func (o SourceRefOrder) Less(left, right source.SourceRef) bool {
|
||||
if lessEndpoint(positions, left.StartUnitID, right.StartUnitID) {
|
||||
return true
|
||||
}
|
||||
if lessEndpoint(o.positions, right.StartUnitID, left.StartUnitID) {
|
||||
if lessEndpoint(positions, right.StartUnitID, left.StartUnitID) {
|
||||
return false
|
||||
}
|
||||
return lessEndpoint(positions, left.EndUnitID, right.EndUnitID)
|
||||
|
||||
@@ -15,13 +15,13 @@ func TestSourceRefOrderUsesDocumentOrderAndLiteralFallbacks(t *testing.T) {
|
||||
{SourceID: doc.ID, StartUnitID: 10, EndUnitID: 10},
|
||||
{SourceID: doc.ID, StartUnitID: 999, EndUnitID: 999},
|
||||
{SourceID: doc.ID, StartUnitID: 30, EndUnitID: 30},
|
||||
{SourceID: "other", StartUnitID: 20, EndUnitID: 20},
|
||||
{SourceID: "other", StartUnitID: 10, EndUnitID: 10},
|
||||
{SourceID: "other", StartUnitID: 30, EndUnitID: 1},
|
||||
{SourceID: "other", StartUnitID: 10, EndUnitID: 2},
|
||||
}
|
||||
got := order.Canonicalize(refs)
|
||||
want := []source.SourceRef{
|
||||
{SourceID: "other", StartUnitID: 10, EndUnitID: 10},
|
||||
{SourceID: "other", StartUnitID: 20, EndUnitID: 20},
|
||||
{SourceID: "other", StartUnitID: 10, EndUnitID: 2},
|
||||
{SourceID: "other", StartUnitID: 30, EndUnitID: 1},
|
||||
{SourceID: doc.ID, StartUnitID: 30, EndUnitID: 30},
|
||||
{SourceID: doc.ID, StartUnitID: 10, EndUnitID: 10},
|
||||
{SourceID: doc.ID, StartUnitID: 999, EndUnitID: 999},
|
||||
|
||||
Reference in New Issue
Block a user