Skip to content

Commit

Permalink
fix: restore support for JFunction and add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
netomi committed Sep 16, 2024
1 parent 13cc9c7 commit fa0a5fd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/jsonata/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1575,7 +1575,7 @@ def get_function_arity(func: Any) -> int:

return len(signature(func.function).parameters)
else:
raise RuntimeError(f"unexpected function '{type(func)}'")
return len(func.arguments)

#
# Helper function to build the arguments to be supplied to the function arg of the
Expand Down
6 changes: 5 additions & 1 deletion tests/custom_function_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ def test_ternary(self):
expression.register_lambda("abc", lambda x, y, z: str(x) + str(y) + str(z))
assert expression.evaluate({"a": "a", "b": "b", "c": "c"}) == "abc"

def test_map(self):
def test_map_with_lambda(self):
expression = jsonata.Jsonata("$map([1, 2, 3], $square)")
expression.register_lambda("square", lambda x: x * x)
assert expression.evaluate(None) == [1, 4, 9]

def test_map_with_function(self):
expression = jsonata.Jsonata("$map([1, 2, 3], function($v) { $v * $v })")
assert expression.evaluate(None) == [1, 4, 9]

0 comments on commit fa0a5fd

Please sign in to comment.