From 46da249cacac6c5aa1762ae2ba3a00e8d9f53e23 Mon Sep 17 00:00:00 2001 From: Diego Henrique Oliveira Date: Sun, 28 Apr 2024 12:38:51 -0400 Subject: [PATCH] Ensure all boolean output from map is considered (#85) --- arrays.go | 2 +- internal/issues/0083_test.go | 37 ++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 internal/issues/0083_test.go diff --git a/arrays.go b/arrays.go index e7c4f03..559c166 100644 --- a/arrays.go +++ b/arrays.go @@ -66,7 +66,7 @@ func _map(values, data interface{}) interface{} { for _, value := range subject.([]interface{}) { v := parseValues(logic, value) - if isTrue(v) || isNumber(v) { + if isTrue(v) || isNumber(v) || isBool(v) { result = append(result, v) } } diff --git a/internal/issues/0083_test.go b/internal/issues/0083_test.go new file mode 100644 index 0000000..01fcc1e --- /dev/null +++ b/internal/issues/0083_test.go @@ -0,0 +1,37 @@ +package issues_test + +import ( + "bytes" + "strings" + "testing" + + "github.com/stretchr/testify/assert" + + "github.com/diegoholiveira/jsonlogic/v3" +) + +func TestIssue83(t *testing.T) { + rule := `{ + "map": [ + {"var": "listOfLists"}, + {"in": ["item_a", {"var": ""}]} + ] + }` + + data := `{ + "listOfLists": [ + ["item_a", "item_b", "item_c"], + ["item_b", "item_c"], + ["item_a", "item_c"] + ] + }` + + var result bytes.Buffer + + err := jsonlogic.Apply(strings.NewReader(rule), strings.NewReader(data), &result) + + if assert.Nil(t, err) { + expected := `[true,false,true]` + assert.JSONEq(t, expected, result.String()) + } +}