Skip to content

Commit

Permalink
fix: cast values of numeric arrays to float64 (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
abichinger authored Nov 24, 2023
1 parent 97e0ed2 commit 9617456
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
4 changes: 3 additions & 1 deletion dummies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

/*
Struct used to test "parameter calls".
Struct used to test "parameter calls".
*/
type dummyParameter struct {
String string
Expand Down Expand Up @@ -73,6 +73,8 @@ var dummyParameterInstance = dummyParameter{
"String": "string!",
"Int": 101,
"StringCompare": strings.Compare,
"IntArray": []interface{}{1, 2, 3},
"StringArray": []interface{}{"foo", "bar", "baz"},
},
}

Expand Down
1 change: 1 addition & 0 deletions evaluationStage.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ func separatorStage(left interface{}, right interface{}, parameters Parameters)
func inStage(left interface{}, right interface{}, parameters Parameters) (interface{}, error) {

for _, value := range right.([]interface{}) {
value = castToFloat64(value)
if left == value {
return true, nil
}
Expand Down
22 changes: 18 additions & 4 deletions evaluation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

/*
Represents a test of expression evaluation
Represents a test of expression evaluation
*/
type EvaluationTest struct {
Name string
Expand Down Expand Up @@ -1405,6 +1405,20 @@ func TestParameterizedEvaluation(test *testing.T) {
Parameters: []EvaluationParameter{fooParameter},
Expected: 1.0,
},
EvaluationTest{

Name: "Nested Map IntArray",
Input: "3 IN foo.Map.IntArray",
Parameters: []EvaluationParameter{fooParameter},
Expected: true,
},
EvaluationTest{

Name: "Nested Map StringArray",
Input: `"bar" IN foo.Map.StringArray`,
Parameters: []EvaluationParameter{fooParameter},
Expected: true,
},
EvaluationTest{

Name: "Parameter call with + modifier",
Expand Down Expand Up @@ -1439,7 +1453,7 @@ func TestParameterizedEvaluation(test *testing.T) {
}

/*
Tests the behavior of a nil set of parameters.
Tests the behavior of a nil set of parameters.
*/
func TestNilParameters(test *testing.T) {

Expand All @@ -1452,8 +1466,8 @@ func TestNilParameters(test *testing.T) {
}

/*
Tests functionality related to using functions with a struct method receiver.
Created to test #54.
Tests functionality related to using functions with a struct method receiver.
Created to test #54.
*/
func TestStructFunctions(test *testing.T) {

Expand Down

0 comments on commit 9617456

Please sign in to comment.