From dd89f9bf4852586b23d693d4313d8dad9d23f6f3 Mon Sep 17 00:00:00 2001 From: Joseph Herlant Date: Tue, 10 Dec 2019 15:26:55 -0800 Subject: [PATCH] Add blank lines and keys in tests for overall consistency --- bql/semantic/semantic_test.go | 31 +++++++++++++++++-------------- triple/node/node_test.go | 7 +++++-- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/bql/semantic/semantic_test.go b/bql/semantic/semantic_test.go index 30ac58f6..55792866 100644 --- a/bql/semantic/semantic_test.go +++ b/bql/semantic/semantic_test.go @@ -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", @@ -147,10 +148,10 @@ func TestGraphClauseString(t *testing.T) { OUpperBoundAlias: "?seemsSoFarAway", OTemporal: true, }, - `{ opt=true /some/type AS ?nAlias TYPE ?nTypeAlias ID ?nIDAlias "foo"@[] ?predBinding "?predID" AS ?predAlias ID ?predIDAlias AT ?predAnchorAlias /some/other/type AS ?objAlias TYPE ?objTypeAlias ID ?objCuteID AT ?Olive AS ?objAlias ID ?objCuteID }`, + want: `{ opt=true /some/type AS ?nAlias TYPE ?nTypeAlias ID ?nIDAlias "foo"@[] ?predBinding "?predID" AS ?predAlias ID ?predIDAlias AT ?predAnchorAlias /some/other/type AS ?objAlias TYPE ?objTypeAlias ID ?objCuteID AT ?Olive AS ?objAlias ID ?objCuteID }`, }, { - &GraphClause{ + gc: &GraphClause{ Optional: true, S: nil, SBinding: "?nBinding", @@ -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", @@ -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 }`, }, } @@ -224,6 +225,7 @@ func TestGraphClauseString(t *testing.T) { } func TestGraphClauseSpecificity(t *testing.T) { + table := []struct { gc *GraphClause want int @@ -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) @@ -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", @@ -480,10 +483,10 @@ func TestConstructPredicateObjectPairString(t *testing.T) { OAnchorBinding: "?Popeyes", OTemporal: true, }, - ` "foo"@[] ?predBinding "?predID" /some/type`, + want: ` "foo"@[] ?predBinding "?predID" /some/type`, }, { - &ConstructPredicateObjectPair{ + pop: &ConstructPredicateObjectPair{ P: nil, PID: "?predID", PBinding: "?predBinding", @@ -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", @@ -510,7 +513,7 @@ func TestConstructPredicateObjectPairString(t *testing.T) { OAnchorBinding: "?Popeyes", OTemporal: true, }, - ` ?predBinding "?predID"@[]] ?objBinding "?objID"[?Popeyes]`, + want: ` ?predBinding "?predID"@[]] ?objBinding "?objID"[?Popeyes]`, }, } diff --git a/triple/node/node_test.go b/triple/node/node_test.go index b19b6697..8a978748 100644 --- a/triple/node/node_test.go +++ b/triple/node/node_test.go @@ -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"}, + {n: &Node{}, want: "<>"}, + {n: nA, want: "/some/type"}, } + 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)