diff --git a/CONTRIBUTORS b/CONTRIBUTORS index e603c16b6..fe4248cb8 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -17,6 +17,7 @@ Denys Smirnov Derek Liang Gaurav Tiwari Iddan Aaronsohn +JSup Jay Graves Jeremy Jay Jørgen Teunis diff --git a/query/path/pathtest/pathtest.go b/query/path/pathtest/pathtest.go index 21b8b98ae..578045750 100644 --- a/query/path/pathtest/pathtest.go +++ b/query/path/pathtest/pathtest.go @@ -212,6 +212,21 @@ func testSet(qs graph.QuadStore) []test { path.StartPath(qs, vAlice).Out(vFollows)), expect: []quad.Value{vBob, vGreg}, }, + { + message: "Or of overlapping branches keeps a value reachable via either branch", + path: path.StartPath(qs, vAlice).Out(vFollows).Or( + path.StartPath(qs, vDani).Out(vFollows)), + // Or is a union without deduplication: bob is reachable via both + // alice->follows and dani->follows, so it appears from each branch. + expect: []quad.Value{vBob, vBob, vGreg}, + }, + { + message: "Or preserves the Save tag of whichever branch produced the value", + path: path.StartPath(qs, vBob).Save(vStatus, "statustag").Or( + path.StartPath(qs, vDani).Save(vStatus, "statustag")), + tag: "statustag", + expect: []quad.Value{vCool, vCool}, + }, { message: "implicit All", path: path.StartPath(qs), @@ -437,6 +452,21 @@ func testSet(qs graph.QuadStore) []test { tag: "statustag", expect: []quad.Value{vCool, vCool}, }, + { + message: "SaveOptional keeps unmatched starts with an empty tag", + path: path.StartPath(qs, vAlice, vBob, vFred).SaveOptional(vStatus, "statustag"), + tag: "statustag", + empty: true, + // alice and fred have no status quad, bob has "cool_person". + expect: []quad.Value{vEmpty, vEmpty, vCool}, + }, + { + message: "optional branch that never matches still returns every top-level node", + path: path.StartPath(qs, vAlice, vFred).Optional(path.StartMorphism().Save(vStatus, "statustag")), + tag: "statustag", + empty: true, + expect: []quad.Value{vEmpty, vEmpty}, + }, { message: "composite paths (clone paths)", path: func() *path.Path {