Skip to content

Commit

Permalink
Add tests for ConstructPredicateObjectPair.String()
Browse files Browse the repository at this point in the history
  • Loading branch information
aerostitch authored and xllora committed Dec 13, 2019
1 parent 2b762ad commit beccd06
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 2 deletions.
2 changes: 0 additions & 2 deletions bql/semantic/semantic.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,11 +458,9 @@ func (c *ConstructPredicateObjectPair) String() string {

// Object section.
if c.O != nil {
// Node portion.
b.WriteString(" ")
b.WriteString(c.O.String())
} else {
// Predicate portion.
if c.OBinding != "" {
b.WriteString(" ")
b.WriteString(c.OBinding)
Expand Down
66 changes: 66 additions & 0 deletions bql/semantic/semantic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,72 @@ func TestInputOutputBindings(t *testing.T) {
}
}

func TestConstructPredicateObjectPairString(t *testing.T) {
// Testing that NewNodeFromStrings is not the point of this package. Taking the example from the unit tests.
n, _ := node.NewNodeFromStrings("/some/type", "id_1")
// Testing NewImmutable is not the point of this package.
immutFoo, _ := predicate.NewImmutable("foo")
o := triple.NewNodeObject(n)

table := []struct {
pop *ConstructPredicateObjectPair
want string
}{
{&ConstructPredicateObjectPair{}, `@[]][]`},
{
&ConstructPredicateObjectPair{
P: immutFoo,
PID: "?predID",
PBinding: "?predBinding",
PAnchorBinding: "?predAnchorBinding",
PTemporal: true,
O: o,
OBinding: "?objBinding",
OID: "?objID",
OAnchorBinding: "?Popeyes",
OTemporal: true,
},
` "foo"@[] ?predBinding "?predID" /some/type<id_1>`,
},
{
&ConstructPredicateObjectPair{
P: nil,
PID: "?predID",
PBinding: "?predBinding",
PAnchorBinding: "?predAnchorBinding",
PTemporal: true,
O: nil,
OBinding: "?objBinding",
OID: "?objID",
OAnchorBinding: "?Popeyes",
OTemporal: false,
},
` ?predBinding "?predID"@[?predAnchorBinding] ?objBinding "?objID"[]`,
},
{
&ConstructPredicateObjectPair{
P: nil,
PID: "?predID",
PBinding: "?predBinding",
PAnchorBinding: "?predAnchorBinding",
PTemporal: false,
O: nil,
OBinding: "?objBinding",
OID: "?objID",
OAnchorBinding: "?Popeyes",
OTemporal: true,
},
` ?predBinding "?predID"@[]] ?objBinding "?objID"[?Popeyes]`,
},
}

for i, entry := range table {
if got, want := entry.pop.String(), entry.want; got != want {
t.Errorf("[case %d] failed; got `%v`, want `%v`", i, got, want)
}
}
}

func TestHasAlias(t *testing.T) {
accept := []*GraphClause{
{
Expand Down

0 comments on commit beccd06

Please sign in to comment.