From 5ea38e4d7485aca5ce4e74bff1785c0d8e41fa1c Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 3 May 2019 23:18:30 +1000 Subject: py/native: Improve support for bool type in viper functions. Variables with type bool now act more like an int, and there is proper casting to/from Python objects. --- tests/micropython/viper_types.py | 26 ++++++++++++++++++++++++++ tests/micropython/viper_types.py.exp | 8 ++++++++ 2 files changed, 34 insertions(+) create mode 100644 tests/micropython/viper_types.py create mode 100644 tests/micropython/viper_types.py.exp (limited to 'tests/micropython') diff --git a/tests/micropython/viper_types.py b/tests/micropython/viper_types.py new file mode 100644 index 000000000..ae72c0cf3 --- /dev/null +++ b/tests/micropython/viper_types.py @@ -0,0 +1,26 @@ +# test various type conversions + +import micropython + +# converting incoming arg to bool +@micropython.viper +def f1(x:bool): + print(x) +f1(0) +f1(1) +f1([]) +f1([1]) + +# taking and returning a bool +@micropython.viper +def f2(x:bool) -> bool: + return x +print(f2([])) +print(f2([1])) + +# converting to bool within function +@micropython.viper +def f3(x) -> bool: + return bool(x) +print(f3([])) +print(f3(-1)) diff --git a/tests/micropython/viper_types.py.exp b/tests/micropython/viper_types.py.exp new file mode 100644 index 000000000..b7bef156e --- /dev/null +++ b/tests/micropython/viper_types.py.exp @@ -0,0 +1,8 @@ +False +True +False +True +False +True +False +True -- cgit v1.2.3