changed to new testdata file that is now used throughout the documentation
This commit is contained in:
parent
5e3aafb47b
commit
e851864576
11 changed files with 165 additions and 167 deletions
|
|
@ -28,29 +28,30 @@ import (
|
|||
|
||||
// This is a simple test graph.
|
||||
//
|
||||
// +---+ +---+
|
||||
// | A |------- ->| F |<--
|
||||
// +---+ \------>+---+-/ +---+ \--+---+
|
||||
// ------>|#B#| | | E |
|
||||
// +---+-------/ >+---+ | +---+
|
||||
// | C | / v
|
||||
// +---+ -/ +---+
|
||||
// ---- +---+/ |#G#|
|
||||
// \-->|#D#|------------->+---+
|
||||
// +---+
|
||||
// +-------+ +------+
|
||||
// | alice |----- ->| fred |<--
|
||||
// +-------+ \---->+-------+-/ +------+ \-+-------+
|
||||
// ----->| #bob# | | | emily |
|
||||
// +---------+--/ --->+-------+ | +-------+
|
||||
// | charlie | / v
|
||||
// +---------+ / +--------+
|
||||
// \--- +--------+ | #greg# |
|
||||
// \-->| #dani# |------------>+--------+
|
||||
// +--------+
|
||||
//
|
||||
|
||||
var simpleGraph = []quad.Quad{
|
||||
{"A", "follows", "B", ""},
|
||||
{"C", "follows", "B", ""},
|
||||
{"C", "follows", "D", ""},
|
||||
{"D", "follows", "B", ""},
|
||||
{"B", "follows", "F", ""},
|
||||
{"F", "follows", "G", ""},
|
||||
{"D", "follows", "G", ""},
|
||||
{"E", "follows", "F", ""},
|
||||
{"B", "status", "cool", "status_graph"},
|
||||
{"D", "status", "cool", "status_graph"},
|
||||
{"G", "status", "cool", "status_graph"},
|
||||
{"alice", "follows", "bob", ""},
|
||||
{"charlie", "follows", "bob", ""},
|
||||
{"charlie", "follows", "dani", ""},
|
||||
{"dani", "follows", "bob", ""},
|
||||
{"bob", "follows", "fred", ""},
|
||||
{"fred", "follows", "greg", ""},
|
||||
{"dani", "follows", "greg", ""},
|
||||
{"emily", "follows", "fred", ""},
|
||||
{"bob", "status", "cool_person", "status_graph"},
|
||||
{"dani", "status", "cool_person", "status_graph"},
|
||||
{"greg", "status", "cool_person", "status_graph"},
|
||||
}
|
||||
|
||||
func makeTestSession(data []quad.Quad) *Session {
|
||||
|
|
@ -72,67 +73,67 @@ var testQueries = []struct {
|
|||
{
|
||||
message: "get a single vertex",
|
||||
query: `
|
||||
g.V("A").All()
|
||||
g.V("alice").All()
|
||||
`,
|
||||
expect: []string{"A"},
|
||||
expect: []string{"alice"},
|
||||
},
|
||||
{
|
||||
message: "use .Out()",
|
||||
query: `
|
||||
g.V("A").Out("follows").All()
|
||||
g.V("alice").Out("follows").All()
|
||||
`,
|
||||
expect: []string{"B"},
|
||||
expect: []string{"bob"},
|
||||
},
|
||||
{
|
||||
message: "use .In()",
|
||||
query: `
|
||||
g.V("B").In("follows").All()
|
||||
g.V("bob").In("follows").All()
|
||||
`,
|
||||
expect: []string{"A", "C", "D"},
|
||||
expect: []string{"alice", "charlie", "dani"},
|
||||
},
|
||||
{
|
||||
message: "use .Both()",
|
||||
query: `
|
||||
g.V("F").Both("follows").All()
|
||||
g.V("fred").Both("follows").All()
|
||||
`,
|
||||
expect: []string{"B", "G", "E"},
|
||||
expect: []string{"bob", "greg", "emily"},
|
||||
},
|
||||
{
|
||||
message: "use .Tag()-.Is()-.Back()",
|
||||
query: `
|
||||
g.V("B").In("follows").Tag("foo").Out("status").Is("cool").Back("foo").All()
|
||||
g.V("bob").In("follows").Tag("foo").Out("status").Is("cool_person").Back("foo").All()
|
||||
`,
|
||||
expect: []string{"D"},
|
||||
expect: []string{"dani"},
|
||||
},
|
||||
{
|
||||
message: "separate .Tag()-.Is()-.Back()",
|
||||
query: `
|
||||
x = g.V("C").Out("follows").Tag("foo").Out("status").Is("cool").Back("foo")
|
||||
x.In("follows").Is("D").Back("foo").All()
|
||||
x = g.V("charlie").Out("follows").Tag("foo").Out("status").Is("cool_person").Back("foo")
|
||||
x.In("follows").Is("dani").Back("foo").All()
|
||||
`,
|
||||
expect: []string{"B"},
|
||||
expect: []string{"bob"},
|
||||
},
|
||||
{
|
||||
message: "do multiple .Back()s",
|
||||
query: `
|
||||
g.V("E").Out("follows").As("f").Out("follows").Out("status").Is("cool").Back("f").In("follows").In("follows").As("acd").Out("status").Is("cool").Back("f").All()
|
||||
g.V("emily").Out("follows").As("f").Out("follows").Out("status").Is("cool_person").Back("f").In("follows").In("follows").As("acd").Out("status").Is("cool_person").Back("f").All()
|
||||
`,
|
||||
tag: "acd",
|
||||
expect: []string{"D"},
|
||||
expect: []string{"dani"},
|
||||
},
|
||||
{
|
||||
message: "use Except to filter out a single vertex",
|
||||
query: `
|
||||
g.V("A", "B").Except(g.V("A")).All()
|
||||
g.V("alice", "bob").Except(g.V("alice")).All()
|
||||
`,
|
||||
expect: []string{"B"},
|
||||
expect: []string{"bob"},
|
||||
},
|
||||
{
|
||||
message: "use chained Except",
|
||||
query: `
|
||||
g.V("A", "B", "C").Except(g.V("B")).Except(g.V("C")).All()
|
||||
g.V("alice", "bob", "charlie").Except(g.V("bob")).Except(g.V("charlie")).All()
|
||||
`,
|
||||
expect: []string{"A"},
|
||||
expect: []string{"alice"},
|
||||
},
|
||||
|
||||
// Morphism tests.
|
||||
|
|
@ -140,17 +141,17 @@ var testQueries = []struct {
|
|||
message: "show simple morphism",
|
||||
query: `
|
||||
grandfollows = g.M().Out("follows").Out("follows")
|
||||
g.V("C").Follow(grandfollows).All()
|
||||
g.V("charlie").Follow(grandfollows).All()
|
||||
`,
|
||||
expect: []string{"G", "F", "B"},
|
||||
expect: []string{"greg", "fred", "bob"},
|
||||
},
|
||||
{
|
||||
message: "show reverse morphism",
|
||||
query: `
|
||||
grandfollows = g.M().Out("follows").Out("follows")
|
||||
g.V("F").FollowR(grandfollows).All()
|
||||
g.V("fred").FollowR(grandfollows).All()
|
||||
`,
|
||||
expect: []string{"A", "C", "D"},
|
||||
expect: []string{"alice", "charlie", "dani"},
|
||||
},
|
||||
|
||||
// Intersection tests.
|
||||
|
|
@ -158,59 +159,59 @@ var testQueries = []struct {
|
|||
message: "show simple intersection",
|
||||
query: `
|
||||
function follows(x) { return g.V(x).Out("follows") }
|
||||
follows("D").And(follows("C")).All()
|
||||
follows("dani").And(follows("charlie")).All()
|
||||
`,
|
||||
expect: []string{"B"},
|
||||
expect: []string{"bob"},
|
||||
},
|
||||
{
|
||||
message: "show simple morphism intersection",
|
||||
query: `
|
||||
grandfollows = g.M().Out("follows").Out("follows")
|
||||
function gfollows(x) { return g.V(x).Follow(grandfollows) }
|
||||
gfollows("A").And(gfollows("C")).All()
|
||||
gfollows("alice").And(gfollows("charlie")).All()
|
||||
`,
|
||||
expect: []string{"F"},
|
||||
expect: []string{"fred"},
|
||||
},
|
||||
{
|
||||
message: "show double morphism intersection",
|
||||
query: `
|
||||
grandfollows = g.M().Out("follows").Out("follows")
|
||||
function gfollows(x) { return g.V(x).Follow(grandfollows) }
|
||||
gfollows("E").And(gfollows("C")).And(gfollows("B")).All()
|
||||
gfollows("emily").And(gfollows("charlie")).And(gfollows("bob")).All()
|
||||
`,
|
||||
expect: []string{"G"},
|
||||
expect: []string{"greg"},
|
||||
},
|
||||
{
|
||||
message: "show reverse intersection",
|
||||
query: `
|
||||
grandfollows = g.M().Out("follows").Out("follows")
|
||||
g.V("G").FollowR(grandfollows).Intersect(g.V("F").FollowR(grandfollows)).All()
|
||||
g.V("greg").FollowR(grandfollows).Intersect(g.V("fred").FollowR(grandfollows)).All()
|
||||
`,
|
||||
expect: []string{"C"},
|
||||
expect: []string{"charlie"},
|
||||
},
|
||||
{
|
||||
message: "show standard sort of morphism intersection, continue follow",
|
||||
query: `gfollowers = g.M().In("follows").In("follows")
|
||||
function cool(x) { return g.V(x).As("a").Out("status").Is("cool").Back("a") }
|
||||
cool("G").Follow(gfollowers).Intersect(cool("B").Follow(gfollowers)).All()
|
||||
function cool(x) { return g.V(x).As("a").Out("status").Is("cool_person").Back("a") }
|
||||
cool("greg").Follow(gfollowers).Intersect(cool("bob").Follow(gfollowers)).All()
|
||||
`,
|
||||
expect: []string{"C"},
|
||||
expect: []string{"charlie"},
|
||||
},
|
||||
|
||||
// Gremlin Has tests.
|
||||
{
|
||||
message: "show a simple Has",
|
||||
query: `
|
||||
g.V().Has("status", "cool").All()
|
||||
g.V().Has("status", "cool_person").All()
|
||||
`,
|
||||
expect: []string{"G", "D", "B"},
|
||||
expect: []string{"greg", "dani", "bob"},
|
||||
},
|
||||
{
|
||||
message: "show a double Has",
|
||||
query: `
|
||||
g.V().Has("status", "cool").Has("follows", "F").All()
|
||||
g.V().Has("status", "cool_person").Has("follows", "fred").All()
|
||||
`,
|
||||
expect: []string{"B"},
|
||||
expect: []string{"bob"},
|
||||
},
|
||||
|
||||
// Tag tests.
|
||||
|
|
@ -220,20 +221,20 @@ var testQueries = []struct {
|
|||
g.V().Save("status", "somecool").All()
|
||||
`,
|
||||
tag: "somecool",
|
||||
expect: []string{"cool", "cool", "cool"},
|
||||
expect: []string{"cool_person", "cool_person", "cool_person"},
|
||||
},
|
||||
{
|
||||
message: "show a simple saveR",
|
||||
query: `
|
||||
g.V("cool").SaveR("status", "who").All()
|
||||
g.V("cool_person").SaveR("status", "who").All()
|
||||
`,
|
||||
tag: "who",
|
||||
expect: []string{"G", "D", "B"},
|
||||
expect: []string{"greg", "dani", "bob"},
|
||||
},
|
||||
{
|
||||
message: "show an out save",
|
||||
query: `
|
||||
g.V("D").Out(null, "pred").All()
|
||||
g.V("dani").Out(null, "pred").All()
|
||||
`,
|
||||
tag: "pred",
|
||||
expect: []string{"follows", "follows", "status"},
|
||||
|
|
@ -241,7 +242,7 @@ var testQueries = []struct {
|
|||
{
|
||||
message: "show a tag list",
|
||||
query: `
|
||||
g.V("D").Out(null, ["pred", "foo", "bar"]).All()
|
||||
g.V("dani").Out(null, ["pred", "foo", "bar"]).All()
|
||||
`,
|
||||
tag: "foo",
|
||||
expect: []string{"follows", "follows", "status"},
|
||||
|
|
@ -249,16 +250,16 @@ var testQueries = []struct {
|
|||
{
|
||||
message: "show a pred list",
|
||||
query: `
|
||||
g.V("D").Out(["follows", "status"]).All()
|
||||
g.V("dani").Out(["follows", "status"]).All()
|
||||
`,
|
||||
expect: []string{"B", "G", "cool"},
|
||||
expect: []string{"bob", "greg", "cool_person"},
|
||||
},
|
||||
{
|
||||
message: "show a predicate path",
|
||||
query: `
|
||||
g.V("D").Out(g.V("follows"), "pred").All()
|
||||
g.V("dani").Out(g.V("follows"), "pred").All()
|
||||
`,
|
||||
expect: []string{"B", "G"},
|
||||
expect: []string{"bob", "greg"},
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue