Index inheritance history lookups
This commit is contained in:
@@ -2,6 +2,7 @@ package engine
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -311,6 +312,51 @@ func TestInheritanceHistoryRetainsControlsAndDisplacedPaths(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestIndexedInheritanceHistoryMatchesOperationScan(t *testing.T) {
|
||||
inspection, _ := inheritanceInspectionForTest(t,
|
||||
parseCompositionDocument(t, "source-1", "parent: {branch: {detail: inherited, retained: present}}\n"),
|
||||
parseCompositionDocument(t, "source-2", "child: {extends: parent, branch: replaced}\n"),
|
||||
parseCompositionDocument(t, "source-3", "sibling: {extends: parent}\n"))
|
||||
metadata := inspection.Metadata()
|
||||
if len(metadata.inheritance) < 4 {
|
||||
t.Fatalf("inheritance operations = %d, want multiple control and transfer scopes", len(metadata.inheritance))
|
||||
}
|
||||
queries := []Path{
|
||||
Keys("child"),
|
||||
Keys("child", inheritanceKey),
|
||||
Keys("child", "branch", "detail"),
|
||||
Keys("child", "branch"),
|
||||
Keys("sibling", "branch", "detail"),
|
||||
Path{},
|
||||
}
|
||||
for _, path := range queries {
|
||||
if !metadata.hasHistoricalPath(path) {
|
||||
continue
|
||||
}
|
||||
stored := metadata.history[path.String()]
|
||||
want := historyWithInheritance(path, stored, metadata.inheritance)
|
||||
if got := metadata.History(path); !reflect.DeepEqual(got, want) {
|
||||
t.Errorf("indexed history for %s differs from operation scan:\n got: %#v\nwant: %#v", path, got, want)
|
||||
}
|
||||
unprepared := Metadata{history: metadata.history, historicalPaths: metadata.historicalPaths, inheritance: metadata.inheritance}
|
||||
if got := unprepared.History(path); !reflect.DeepEqual(got, want) {
|
||||
t.Errorf("unprepared history for %s differs from operation scan:\n got: %#v\nwant: %#v", path, got, want)
|
||||
}
|
||||
}
|
||||
|
||||
removed := Keys("child", "branch", "detail")
|
||||
first := metadata.History(removed)
|
||||
if len(first) == 0 || len(first[0].Path.segments) == 0 {
|
||||
t.Fatalf("removed-path history = %#v", first)
|
||||
}
|
||||
first[0].Path.segments[0].key = "mutated"
|
||||
second := cloneMetadata(metadata).History(removed)
|
||||
want := historyWithInheritance(removed, metadata.history[removed.String()], metadata.inheritance)
|
||||
if !reflect.DeepEqual(second, want) {
|
||||
t.Fatalf("returned history mutation affected a repeated or cloned query:\n got: %#v\nwant: %#v", second, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInheritanceHistoryPrecedesApplicationResolution(t *testing.T) {
|
||||
inspection, _ := inheritanceInspectionForTest(t,
|
||||
parseCompositionDocument(t, "source-1", "parent: {value: original}\nchild: {extends: parent}\n"))
|
||||
|
||||
Reference in New Issue
Block a user