Skip to content

Commit

Permalink
Add blank lines and keys in tests for overall consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
aerostitch authored and xllora committed Dec 13, 2019
1 parent beccd06 commit dd89f9b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
31 changes: 17 additions & 14 deletions bql/semantic/semantic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,14 @@ func TestGraphClauseString(t *testing.T) {
immutFoo, _ := predicate.NewImmutable("foo")
nO, _ := node.NewNodeFromStrings("/some/other/type", "id_2")
o := triple.NewNodeObject(nO)

table := []struct {
gc *GraphClause
want string
}{
{&GraphClause{}, `{ opt=false @[][] }`},
{gc: &GraphClause{}, want: `{ opt=false @[][] }`},
{
&GraphClause{
gc: &GraphClause{
Optional: true,
S: n,
SBinding: "?nBinding",
Expand Down Expand Up @@ -147,10 +148,10 @@ func TestGraphClauseString(t *testing.T) {
OUpperBoundAlias: "?seemsSoFarAway",
OTemporal: true,
},
`{ 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 }`,
want: `{ 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 }`,
},
{
&GraphClause{
gc: &GraphClause{
Optional: true,
S: nil,
SBinding: "?nBinding",
Expand All @@ -177,10 +178,10 @@ func TestGraphClauseString(t *testing.T) {
OUpperBoundAlias: "?seemsSoFarAway",
OTemporal: false,
},
`{ opt=true ?nBinding AS ?nAlias TYPE ?nTypeAlias ID ?nIDAlias ?predBinding "?predID"@[] AS ?predAlias ID ?predIDAlias AT ?predAnchorAlias[] }`,
want: `{ opt=true ?nBinding AS ?nAlias TYPE ?nTypeAlias ID ?nIDAlias ?predBinding "?predID"@[] AS ?predAlias ID ?predIDAlias AT ?predAnchorAlias[] }`,
},
{
&GraphClause{
gc: &GraphClause{
Optional: true,
S: nil,
SBinding: "?nBinding",
Expand Down Expand Up @@ -212,7 +213,7 @@ func TestGraphClauseString(t *testing.T) {
OUpperBoundAlias: "?seemsSoFarAway",
OTemporal: true,
},
`{ 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 }`,
want: `{ 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 }`,
},
}

Expand All @@ -224,6 +225,7 @@ func TestGraphClauseString(t *testing.T) {
}

func TestGraphClauseSpecificity(t *testing.T) {

table := []struct {
gc *GraphClause
want int
Expand All @@ -233,6 +235,7 @@ func TestGraphClauseSpecificity(t *testing.T) {
{&GraphClause{S: &node.Node{}, P: &predicate.Predicate{}}, 2},
{&GraphClause{S: &node.Node{}, P: &predicate.Predicate{}, O: &triple.Object{}}, 3},
}

for _, entry := range table {
if got, want := entry.gc.Specificity(), entry.want; got != want {
t.Errorf("semantic.GraphClause.Specificity failed to return the proper value for %v; got %d, want %d", entry.gc, got, want)
Expand Down Expand Up @@ -466,9 +469,9 @@ func TestConstructPredicateObjectPairString(t *testing.T) {
pop *ConstructPredicateObjectPair
want string
}{
{&ConstructPredicateObjectPair{}, `@[]][]`},
{pop: &ConstructPredicateObjectPair{}, want: `@[]][]`},
{
&ConstructPredicateObjectPair{
pop: &ConstructPredicateObjectPair{
P: immutFoo,
PID: "?predID",
PBinding: "?predBinding",
Expand All @@ -480,10 +483,10 @@ func TestConstructPredicateObjectPairString(t *testing.T) {
OAnchorBinding: "?Popeyes",
OTemporal: true,
},
` "foo"@[] ?predBinding "?predID" /some/type<id_1>`,
want: ` "foo"@[] ?predBinding "?predID" /some/type<id_1>`,
},
{
&ConstructPredicateObjectPair{
pop: &ConstructPredicateObjectPair{
P: nil,
PID: "?predID",
PBinding: "?predBinding",
Expand All @@ -495,10 +498,10 @@ func TestConstructPredicateObjectPairString(t *testing.T) {
OAnchorBinding: "?Popeyes",
OTemporal: false,
},
` ?predBinding "?predID"@[?predAnchorBinding] ?objBinding "?objID"[]`,
want: ` ?predBinding "?predID"@[?predAnchorBinding] ?objBinding "?objID"[]`,
},
{
&ConstructPredicateObjectPair{
pop: &ConstructPredicateObjectPair{
P: nil,
PID: "?predID",
PBinding: "?predBinding",
Expand All @@ -510,7 +513,7 @@ func TestConstructPredicateObjectPairString(t *testing.T) {
OAnchorBinding: "?Popeyes",
OTemporal: true,
},
` ?predBinding "?predID"@[]] ?objBinding "?objID"[?Popeyes]`,
want: ` ?predBinding "?predID"@[]] ?objBinding "?objID"[?Popeyes]`,
},
}

Expand Down
7 changes: 5 additions & 2 deletions triple/node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,20 @@ func TestNewNodeFromString(t *testing.T) {
t.Errorf("node.h Covariant: %q should not be market as covariant of %q", nB, nA)
}
}

func TestNodeString(t *testing.T) {
// NewNodeFromString's error output has already been tested in its own dedicated unit tests
nA, _ := NewNodeFromStrings("/some/type", "id_1")

table := []struct {
n *Node
want string
}{
// Do not crash on unitialize node
{&Node{}, "<>"},
{nA, "/some/type<id_1>"},
{n: &Node{}, want: "<>"},
{n: nA, want: "/some/type<id_1>"},
}

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

0 comments on commit dd89f9b

Please sign in to comment.