Skip to content

Commit 88765ae

Browse files
committed
test(pyTypeFactory): write tests for JS calling Python functions defined in a closure
1 parent 608b73e commit 88765ae

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

tests/python/test_pythonmonkey_eval.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,17 @@ def ident(x):
235235
# pm.collect() # TODO: to be fixed in BF-59
236236
assert "YYZ" == js_fn_back()
237237

238+
def test_eval_functions_pyfunction_in_closure():
239+
# BF-58 https://github.com/Distributive-Network/PythonMonkey/pull/19
240+
def fn1():
241+
def fn0(n):
242+
return n + 100
243+
return fn0
244+
assert 101.9 == fn1()(1.9)
245+
assert 101.9 == pm.eval("(fn1) => { return fn1 }")(fn1())(1.9)
246+
assert 101.9 == pm.eval("(fn1, x) => { return fn1()(x) }")(fn1, 1.9)
247+
assert 101.9 == pm.eval("(fn1) => { return fn1() }")(fn1)(1.9)
248+
238249
def test_eval_functions_pyfunctions_ints():
239250
caller = pm.eval("(func, param1, param2) => { return func(param1, param2) }")
240251
def add(a, b):

0 commit comments

Comments
 (0)