Skip to content

Commit

Permalink
Adding a more comprehensive ParseFilter function which handles the cl…
Browse files Browse the repository at this point in the history
…i parsing
  • Loading branch information
deckarep committed Jan 12, 2024
1 parent bd62cef commit 984b7b2
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions pkg/filters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@ import (
)

func TestParseFilter(t *testing.T) {
parsedResult, err := ParseFilter("peanut, walnut, pecan")
assert.NoError(t, err)
assert.NotNil(t, parsedResult)
// Note: much more robust testing of the parser occurs in the filtercomp package.
// It makes this testing somewhat redundant.

// An filter expression with imbalanced parenthesis should return an error.
ast, err := ParseFilter("(hello, world")
assert.Error(t, err, "imbalanced parenthesis detected")

if parsedResult == nil {
t.Error("expected populated filters but got nil")
}
// An empty filter should return no error with a nil ast.
ast, err = ParseFilter("")
assert.NoError(t, err)
assert.Nil(t, ast)

// TODO: more robust testing here.
// An empty filter should return no error with a nil ast.
ast, err = ParseFilter("how are you doing?")
assert.Error(t, err, "parser did not run to completion, tokens were not fully consumed")
}

0 comments on commit 984b7b2

Please sign in to comment.