Skip to content

Commit 2b762ad

Browse files
aerostitchxllora
authored andcommitted
Add tests for semantic.GraphClause.String()
1 parent 10b6c93 commit 2b762ad

File tree

1 file changed

+127
-0
lines changed

1 file changed

+127
-0
lines changed

bql/semantic/semantic_test.go

+127
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package semantic
1717
import (
1818
"reflect"
1919
"testing"
20+
"time"
2021

2122
"github.com/google/badwolf/triple"
2223
"github.com/google/badwolf/triple/literal"
@@ -96,6 +97,132 @@ func TestStatementAddData(t *testing.T) {
9697
}
9798
}
9899

100+
func TestGraphClauseString(t *testing.T) {
101+
timeObj1 := time.Date(2019, 11, 20, 2, 30, 10, 5, time.UTC)
102+
timeObj2 := time.Date(2019, 12, 3, 5, 40, 20, 7, time.UTC)
103+
timeObj3 := time.Date(2019, 11, 30, 22, 10, 50, 3, time.UTC)
104+
timeObj4 := time.Date(2019, 12, 2, 17, 0, 10, 15, time.UTC)
105+
// Testing that NewNodeFromStrings is not the point of this package. Taking the example from the unit tests.
106+
n, _ := node.NewNodeFromStrings("/some/type", "id_1")
107+
// Testing NewImmutable is not the point of this package.
108+
immutFoo, _ := predicate.NewImmutable("foo")
109+
nO, _ := node.NewNodeFromStrings("/some/other/type", "id_2")
110+
o := triple.NewNodeObject(nO)
111+
table := []struct {
112+
gc *GraphClause
113+
want string
114+
}{
115+
{&GraphClause{}, `{ opt=false @[][] }`},
116+
{
117+
&GraphClause{
118+
Optional: true,
119+
S: n,
120+
SBinding: "?nBinding",
121+
SAlias: "?nAlias",
122+
STypeAlias: "?nTypeAlias",
123+
SIDAlias: "?nIDAlias",
124+
P: immutFoo,
125+
PID: "?predID",
126+
PBinding: "?predBinding",
127+
PAlias: "?predAlias",
128+
PIDAlias: "?predIDAlias",
129+
PAnchorBinding: "?predAnchorBinding",
130+
PAnchorAlias: "?predAnchorAlias",
131+
PLowerBound: &timeObj1,
132+
PUpperBound: &timeObj2,
133+
PLowerBoundAlias: "?earlyYesterday",
134+
PUpperBoundAlias: "?someTimeInTheFuture",
135+
PTemporal: true,
136+
O: o,
137+
OBinding: "?objBinding",
138+
OAlias: "?objAlias",
139+
OID: "?objID",
140+
OTypeAlias: "?objTypeAlias",
141+
OIDAlias: "?objCuteID",
142+
OAnchorBinding: "?Popeyes",
143+
OAnchorAlias: "?Olive",
144+
OLowerBound: &timeObj3,
145+
OUpperBound: &timeObj4,
146+
OLowerBoundAlias: "?SometimeSoon",
147+
OUpperBoundAlias: "?seemsSoFarAway",
148+
OTemporal: true,
149+
},
150+
`{ opt=true /some/type<id_1> AS ?nAlias TYPE ?nTypeAlias ID ?nIDAlias "foo"@[] ?predBinding "?predID" AS ?predAlias ID ?predIDAlias AT ?predAnchorAlias /some/other/type<id_2> AS ?objAlias TYPE ?objTypeAlias ID ?objCuteID AT ?Olive AS ?objAlias ID ?objCuteID }`,
151+
},
152+
{
153+
&GraphClause{
154+
Optional: true,
155+
S: nil,
156+
SBinding: "?nBinding",
157+
SAlias: "?nAlias",
158+
STypeAlias: "?nTypeAlias",
159+
SIDAlias: "?nIDAlias",
160+
P: nil,
161+
PID: "?predID",
162+
PBinding: "?predBinding",
163+
PAlias: "?predAlias",
164+
PIDAlias: "?predIDAlias",
165+
PAnchorBinding: "?predAnchorBinding",
166+
PAnchorAlias: "?predAnchorAlias",
167+
PLowerBound: &timeObj1,
168+
PUpperBound: &timeObj2,
169+
PLowerBoundAlias: "?earlyYesterday",
170+
PUpperBoundAlias: "?someTimeInTheFuture",
171+
PTemporal: false,
172+
O: nil,
173+
OAnchorBinding: "?Popeyes",
174+
OLowerBound: &timeObj3,
175+
OUpperBound: &timeObj4,
176+
OLowerBoundAlias: "?SometimeSoon",
177+
OUpperBoundAlias: "?seemsSoFarAway",
178+
OTemporal: false,
179+
},
180+
`{ opt=true ?nBinding AS ?nAlias TYPE ?nTypeAlias ID ?nIDAlias ?predBinding "?predID"@[] AS ?predAlias ID ?predIDAlias AT ?predAnchorAlias[] }`,
181+
},
182+
{
183+
&GraphClause{
184+
Optional: true,
185+
S: nil,
186+
SBinding: "?nBinding",
187+
SAlias: "?nAlias",
188+
STypeAlias: "?nTypeAlias",
189+
SIDAlias: "?nIDAlias",
190+
P: nil,
191+
PID: "?predID",
192+
PBinding: "?predBinding",
193+
PAlias: "?predAlias",
194+
PIDAlias: "?predIDAlias",
195+
PAnchorBinding: "?predAnchorBinding",
196+
PAnchorAlias: "?predAnchorAlias",
197+
PLowerBound: &timeObj1,
198+
PUpperBound: &timeObj2,
199+
PLowerBoundAlias: "?earlyYesterday",
200+
PUpperBoundAlias: "?someTimeInTheFuture",
201+
PTemporal: true,
202+
O: nil,
203+
OBinding: "?objBinding",
204+
OAlias: "?objAlias",
205+
OID: "?objID",
206+
OTypeAlias: "?objTypeAlias",
207+
OIDAlias: "?objCuteID",
208+
OAnchorAlias: "?Olive",
209+
OLowerBound: &timeObj3,
210+
OUpperBound: &timeObj4,
211+
OLowerBoundAlias: "?SometimeSoon",
212+
OUpperBoundAlias: "?seemsSoFarAway",
213+
OTemporal: true,
214+
},
215+
`{ opt=true ?nBinding AS ?nAlias TYPE ?nTypeAlias ID ?nIDAlias ?predBinding "?predID"@[?predAnchorBinding at ?predAnchorAlias] AS ?predAlias ID ?predIDAlias AT ?predAnchorAlias ?objBinding "?objID"[2019-11-30T22:10:50.000000003Z,2019-12-02T17:00:10.000000015Z] AS ?objAlias TYPE ?objTypeAlias ID ?objCuteID AT ?Olive AS ?objAlias ID ?objCuteID }`,
216+
},
217+
}
218+
219+
for i, entry := range table {
220+
if got, want := entry.gc.String(), entry.want; got != want {
221+
t.Errorf("[case %d] failed; got %v, want %v", i, got, want)
222+
}
223+
}
224+
}
225+
99226
func TestGraphClauseSpecificity(t *testing.T) {
100227
table := []struct {
101228
gc *GraphClause

0 commit comments

Comments
 (0)