Skip to content

Commit

Permalink
Return json object that is provided for if statements (#14)
Browse files Browse the repository at this point in the history
I was looking at other implementation's errors and have been plugging
them into the test suite here.

- diegoholiveira/jsonlogic#58

I have implemented the same fix that is done for the Go library.
  • Loading branch information
warmwaffles authored Feb 18, 2023
2 parents 9c064e6 + 7922ef1 commit bc7a28a
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 bc7a28a

Please sign in to comment.