Skip to content

Commit

Permalink
Clarify parenthesis errors
Browse files Browse the repository at this point in the history
  • Loading branch information
nelio2k committed May 30, 2019
1 parent 9f6a955 commit a1302c1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 4 additions & 2 deletions filterExprParser.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,10 @@ func (f *FilterExpression) outputExpressionNoParenCheck() (Expression, error) {

// Outputs the head of the Expression match tree of which represents everything underneath
func (f *FilterExpression) OutputExpression() (Expression, error) {
if f.GetTotalOpenParens() != f.GetTotalCloseParens() {
return nil, ErrorMalformedParenthesis
openParens := f.GetTotalOpenParens()
closeParens := f.GetTotalCloseParens()
if openParens != closeParens {
return nil, fmt.Errorf("%s: found %v open parentheses and %v close parentheses", ErrorMalformedParenthesis, openParens, closeParens)
}

return f.outputExpressionNoParenCheck()
Expand Down
7 changes: 5 additions & 2 deletions filterExprParser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package gojsonsm
import (
"encoding/json"
"github.com/stretchr/testify/assert"
"strings"
"testing"
)

Expand Down Expand Up @@ -674,13 +675,15 @@ func TestFilterExpressionParser(t *testing.T) {
err = parser.ParseString("(TRUE) OR FALSE)", fe)
assert.Nil(err)
expr, err = fe.OutputExpression()
assert.Equal(ErrorMalformedParenthesis, err)
assert.NotNil(err)
assert.True(strings.Contains(err.Error(), ErrorMalformedParenthesis.Error()))

fe = &FilterExpression{}
err = parser.ParseString("(((TRUE) OR FALSE) OR FALSE))", fe)
assert.Nil(err)
expr, err = fe.OutputExpression()
assert.Equal(ErrorMalformedParenthesis, err)
assert.NotNil(err)
assert.True(strings.Contains(err.Error(), ErrorMalformedParenthesis.Error()))

fe = &FilterExpression{}
err = parser.ParseString("TRUE", fe)
Expand Down

0 comments on commit a1302c1

Please sign in to comment.