Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Evaluate rhs after string slices #76

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compliance
Submodule compliance updated 3 files
+139 −0 README.md
+0 −134 README.rst
+12 −0 tests/slice.json
8 changes: 7 additions & 1 deletion pkg/interpreter/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,13 @@ func (intr *treeInterpreter) Execute(node parsing.ASTNode, value interface{}) (i
}
stringType, ok := left.(string)
if allowString && ok {
return stringType, nil
// a projection is really a sub-expression in disguise
// we must evaluate the right hand expression
result, err := intr.Execute(node.Children[1], stringType)
if err != nil {
return nil, err
}
return result, nil
}
return nil, nil
}
Expand Down
9 changes: 9 additions & 0 deletions pkg/interpreter/interpreter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,15 @@ func TestCanSupportSliceOfStructsWithFunctions(t *testing.T) {
assert.Equal(result.(float64), 2.0)
}

func TestCanSupportEvaluatingRightHandSideOfStringSlice(t *testing.T) {
assert := assert.New(t)
data := make(map[string]interface{})
result, err := search(t, "'foo'[:].length(@)", data)
assert.Nil(err)
assert.Equal(result.(float64), 3.0)

}

func BenchmarkInterpretSingleFieldStruct(b *testing.B) {
assert := assert.New(b)
caller := NewFunctionCaller(functions.GetDefaultFunctions()...)
Expand Down