Skip to content

Improve method binding #974

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add tests for collection & task/action from function
change enumerable method to non-static
add tuple test for ienumerable
  • Loading branch information
koubaa committed Dec 1, 2019
commit b4d60c6ca6495f3e529f94f2983859f4439d021e
24 changes: 23 additions & 1 deletion src/testing/methodtest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,29 @@ public static int[] TestOverloadedParams(int v, int[] args)
return args;
}

public static int TestIEnumerable(System.Collections.Generic.IEnumerable<object> arg)
public static int TestIList(System.Collections.Generic.IList<object> arg)
{
return 1;
}

public static int TestICollection(System.Collections.Generic.ICollection<object> arg)
{
return 1;
}

public int TestAction(System.Action action)
{
action();
return 1;
}

public int TestTask(System.Threading.Tasks.Task<int> task)
{
task.RunSynchronously();
return task.Result;
}

public int TestIEnumerable(System.Collections.Generic.IEnumerable<object> arg)
{
return 1;
}
Expand Down
21 changes: 21 additions & 0 deletions src/tests/test_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,33 @@ def test_null_array_conversion():
r = ob.TestNullArrayConversion(None)
assert r is None

def test_action():
"""Test python lambda as an action"""
ob = MethodTest()
def func():
return
r = ob.TestAction(func)
assert r == 1

def test_task():
"""Test python lambda as an action"""
ob = MethodTest()
def func():
return 1
r = ob.TestTask(func)
assert r == 1

def test_ienumerable_args():
"""Test conversion of python lists and tuples to IEnumerable<object>"""
ob = MethodTest()
x = ob.TestIEnumerable([1,2,3])
y = ob.TestIEnumerable((1,2,3))

def test_icollection_args():
"""Test conversion of python lists and tuples to ICollection<object>"""
ob = MethodTest()
x = ob.TestICollection([1,2,3])

def test_string_params_args():
"""Test use of string params."""
result = MethodTest.TestStringParamsArg('one', 'two', 'three')
Expand Down