diff options
author | Damien George <damien.p.george@gmail.com> | 2019-05-03 23:18:30 +1000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2019-05-03 23:18:30 +1000 |
commit | 5ea38e4d7485aca5ce4e74bff1785c0d8e41fa1c (patch) | |
tree | 068a6d455b9461e2839806ae860cbca7895c3153 /tests | |
parent | 9a6f6fd68d2563e0115b11c01c322aaa14a107bb (diff) |
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.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/micropython/viper_types.py | 26 | ||||
-rw-r--r-- | tests/micropython/viper_types.py.exp | 8 |
2 files changed, 34 insertions, 0 deletions
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 |