Skip to content

Commit

Permalink
Add SaveOptional() tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
barakmich committed Mar 23, 2016
1 parent 6c1030d commit 77943c4
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions graph/path/path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,15 @@ func runTag(path *Path, tag string) []string {
for graph.Next(it) {
tags := make(map[string]graph.Value)
it.TagResults(tags)
out = append(out, path.qs.NameOf(tags[tag]))
if t, ok := tags[tag]; ok {
out = append(out, path.qs.NameOf(t))
}
for it.NextPath() {
tags := make(map[string]graph.Value)
it.TagResults(tags)
out = append(out, path.qs.NameOf(tags[tag]))
if t, ok := tags[tag]; ok {
out = append(out, path.qs.NameOf(t))
}
}
}
return out
Expand Down Expand Up @@ -180,12 +184,6 @@ func testSet(qs graph.QuadStore) []test {
tag: "somecool",
expect: []string{"cool_person", "cool_person", "cool_person", "smart_person", "smart_person"},
},
{
message: "show a simple saveOpt",
path: StartPath(qs).SaveOptional("status", "somecool"),
tag: "somecool",
expect: []string{"", "", "", "", "", "", "", "", "", "", "cool_person", "cool_person", "cool_person", "smart_person", "smart_person"},
},
{
message: "show a simple saveR",
path: StartPath(qs, "cool_person").SaveReverse("status", "who"),
Expand Down Expand Up @@ -250,6 +248,23 @@ func testSet(qs graph.QuadStore) []test {
path: StartPath(qs, "greg").Tag("base").LabelContext("smart_graph").Out("status").Tag("status").Back("base"),
expect: []string{"greg"},
},
// Optional tests
{
message: "save limits top level",
path: StartPath(qs, "bob", "charlie").Out("follows").Save("status", "statustag"),
expect: []string{"bob", "dani"},
},
{
message: "optional still returns top level",
path: StartPath(qs, "bob", "charlie").Out("follows").SaveOptional("status", "statustag"),
expect: []string{"bob", "fred", "dani"},
},
{
message: "optional has the appropriate tags",
path: StartPath(qs, "bob", "charlie").Out("follows").SaveOptional("status", "statustag"),
tag: "statustag",
expect: []string{"cool_person", "cool_person"},
},
}
}

Expand Down

0 comments on commit 77943c4

Please sign in to comment.