Skip to content

Commit

Permalink
return json object that is provided for if statements
Browse files Browse the repository at this point in the history
you can test some of this at https://jsonlogic.com/play.html

```
{"-": [1, 1], "+": [1, 1]}
```

yields the output as

```
{"-": [1, 1], "+": [1, 1]}
```
  • Loading branch information
warmwaffles committed Feb 17, 2023
1 parent 9c064e6 commit 7922ef1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@
- fixed: `min` returning the original minimum value and not the coerced value.
- fixed: infinite recursive loop for ill formed `in` clauses.
- fixed: typespec for `resolve/2`.
- fixed: return json object provided in `if` statements.
- fixed: return the provided json object if the map size is larger than 1.
- removed: optional dependencies for `jason` and `poison`.
- added: Support for `Decimal` to be used.
17 changes: 17 additions & 0 deletions test/json_logic_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,23 @@ defmodule JsonLogicTest do
logic = %{"if" => [true, "apple", true, "banana", true, "carrot", "date"]}
assert JsonLogic.resolve(logic) == "apple"
end

test "returns object" do
logic = %{
"if" => [
%{"==" => [%{"var" => "foo"}, "bar"]},
%{"foo" => "is_bar", "path" => "foo_is_bar"},
%{"foo" => "not_bar", "path" => "default_object"}
]
}

data = %{"foo" => "bar"}

assert %{
"foo" => "is_bar",
"path" => "foo_is_bar"
} == JsonLogic.resolve(logic, data)
end
end

describe "max" do
Expand Down

0 comments on commit 7922ef1

Please sign in to comment.