-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpatternexpr_test.go
76 lines (67 loc) · 1.44 KB
/
patternexpr_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package opencypher
import (
"testing"
"github.com/cloudprivacylabs/lpg/v2"
)
func TestPatternExpr(t *testing.T) {
/*
(root) -> (:c1)
(root) -> (:c2) -> (:c3)
*/
g := lpg.NewGraph()
n1 := g.NewNode([]string{"root"}, nil)
n2 := g.NewNode([]string{"c1"}, nil)
n3 := g.NewNode([]string{"c2"}, nil)
n4 := g.NewNode([]string{"c3"}, nil)
g.NewEdge(n1, n2, "n1n2", nil)
g.NewEdge(n1, n3, "n1n3", nil)
g.NewEdge(n3, n4, "n3n4", nil)
pe, err := ParsePatternExpr(`(this)<-[]-()-[]->(target:c2)`)
if err != nil {
t.Error(err)
return
}
nodes, err := pe.FindRelative(n2)
if err != nil {
t.Error(err)
}
if len(nodes) != 1 {
t.Errorf("Expecting 1, got %d", len(nodes))
return
}
if nodes[0] != n3 {
t.Errorf("Expecting n3, got %s", nodes[0])
}
pe, err = ParsePatternExpr(`(this)<-[]-()-[]->(target)`)
if err != nil {
t.Error(err)
return
}
nodes, err = pe.FindRelative(n2)
if err != nil {
t.Error(err)
}
if len(nodes) != 2 {
t.Errorf("Expecting 2, got %d", len(nodes))
return
}
if (nodes[0] != n3 && nodes[0] != n2) || (nodes[1] != n3 && nodes[1] != n2) {
t.Errorf("Expecting n2 n3, got %v", nodes)
}
pe, err = ParsePatternExpr(`(this)-[]-()-[]-(target:c2)`)
if err != nil {
t.Error(err)
return
}
nodes, err = pe.FindRelative(n2)
if err != nil {
t.Error(err)
}
if len(nodes) != 1 {
t.Errorf("Expecting 1, got %d", len(nodes))
return
}
if nodes[0] != n3 {
t.Errorf("Expecting n3, got %s", nodes[0])
}
}