Skip to content

Commit

Permalink
Added tests and fixed another test.
Browse files Browse the repository at this point in the history
  • Loading branch information
apr94 committed May 23, 2017
1 parent 53cfe35 commit 1f43db1
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
37 changes: 33 additions & 4 deletions bql/semantic/hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func TestTypeBindingClauseHook(t *testing.T) {
st := &Statement{}
f(st, Symbol("FOO"))
if got, want := st.Type(), Insert; got != want {
t.Errorf("semantic.TypeBidingHook failed to set the right type; got %s, want %s", got, want)
t.Errorf("semantic.TypeBindingHook failed to set the right type; got %s, want %s", got, want)
}
}

Expand All @@ -153,9 +153,14 @@ func TestWhereWorkingClauseHook(t *testing.T) {
f := whereNextWorkingClause()
st := &Statement{}
st.ResetWorkingGraphClause()
wcs := st.WorkingClause()
wcs.SBinding = "?a"
f(st, Symbol("FOO"))
wcs = st.WorkingClause()
wcs.SBinding = "?b"
f(st, Symbol("FOO"))
if got, want := len(st.GraphPatternClauses()), 0; got != want {

if got, want := len(st.GraphPatternClauses()), 2; got != want {
t.Errorf("semantic.whereNextWorkingClause should have returned two clauses for statement %v; got %d, want %d", st, got, want)
}
}
Expand Down Expand Up @@ -1169,7 +1174,7 @@ func TestBindingsGraphChecker(t *testing.T) {
want bool
}{
{
id: "missing biding",
id: "missing binding",
s: &Statement{
pattern: []*GraphClause{
{},
Expand Down Expand Up @@ -1199,7 +1204,7 @@ func TestBindingsGraphChecker(t *testing.T) {
want: false,
},
{
id: "all bidings available",
id: "all bindings available",
s: &Statement{
pattern: []*GraphClause{
{},
Expand Down Expand Up @@ -1913,3 +1918,27 @@ func TestCollectGlobalBounds(t *testing.T) {
}
}
}

func TestInitWorkingConstructClauseHook(t *testing.T) {
f := InitWorkingConstructClause()
st := &Statement{}
f(st, Symbol("FOO"))
if st.WorkingConstructClause() == nil {
t.Errorf("semantic.InitConstructWorkingClause should have returned a valid working clause for statement %v", st)
}
}

func TestNextWorkingConstructClauseHook(t *testing.T) {
f := NextWorkingConstructClause()
st := &Statement{}
st.ResetWorkingConstructClause()
wcs := st.WorkingConstructClause()
wcs.SBinding = "?a"
f(st, Symbol("FOO"))
wcs = st.WorkingConstructClause()
wcs.SBinding = "?b"
f(st, Symbol("FOO"))
if got, want := len(st.ConstructClauses()), 2; got != want {
t.Errorf("semantic.NextConstructWorkingClause should have returned two clauses for statement %v; got %d, want %d", st, got, want)
}
}
9 changes: 9 additions & 0 deletions bql/semantic/semantic.go
Original file line number Diff line number Diff line change
Expand Up @@ -692,11 +692,20 @@ func (s *Statement) GlobalLookupOptions() *storage.LookupOptions {
return &lo
}

// ConstructClauses returns the list of construct clauses in the statement.
func (s *Statement) ConstructClauses() []*ConstructClause {
return s.constructClauses
}

// ResetWorkingConstructClause resets the current working construct clause.
func (s *Statement) ResetWorkingConstructClause() {
s.workingConstructClause = &ConstructClause{}
}

// WorkingConstructClause returns the current working clause.
func (s *Statement) WorkingConstructClause() *ConstructClause {
return s.workingConstructClause
}

// AddWorkingConstructClause adds the current working construct clause to the set
// of construct clauses that form the construct statement.
Expand Down

0 comments on commit 1f43db1

Please sign in to comment.