From 1f43db11c61c1d7803aff58c5b731cae0030c075 Mon Sep 17 00:00:00 2001 From: Aravind Rao Date: Tue, 23 May 2017 15:32:32 -0700 Subject: [PATCH] Added tests and fixed another test. --- bql/semantic/hooks_test.go | 37 +++++++++++++++++++++++++++++++++---- bql/semantic/semantic.go | 9 +++++++++ 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/bql/semantic/hooks_test.go b/bql/semantic/hooks_test.go index 998f6835..304536cc 100644 --- a/bql/semantic/hooks_test.go +++ b/bql/semantic/hooks_test.go @@ -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) } } @@ -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) } } @@ -1169,7 +1174,7 @@ func TestBindingsGraphChecker(t *testing.T) { want bool }{ { - id: "missing biding", + id: "missing binding", s: &Statement{ pattern: []*GraphClause{ {}, @@ -1199,7 +1204,7 @@ func TestBindingsGraphChecker(t *testing.T) { want: false, }, { - id: "all bidings available", + id: "all bindings available", s: &Statement{ pattern: []*GraphClause{ {}, @@ -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) + } +} diff --git a/bql/semantic/semantic.go b/bql/semantic/semantic.go index 48131df1..c160e318 100644 --- a/bql/semantic/semantic.go +++ b/bql/semantic/semantic.go @@ -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.