From 095f90f04e996b6b60b193c7b164cdfd096f808c Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 26 Sep 2019 16:53:47 +1000 Subject: [PATCH] tests/micropython: Add test for native generators. --- tests/micropython/native_gen.py | 21 +++++++++++++++++++++ tests/micropython/native_gen.py.exp | 4 ++++ 2 files changed, 25 insertions(+) create mode 100644 tests/micropython/native_gen.py create mode 100644 tests/micropython/native_gen.py.exp diff --git a/tests/micropython/native_gen.py b/tests/micropython/native_gen.py new file mode 100644 index 000000000..30c4c37be --- /dev/null +++ b/tests/micropython/native_gen.py @@ -0,0 +1,21 @@ +# test for native generators + +# simple generator with yield and return +@micropython.native +def gen1(x): + yield x + yield x + 1 + return x + 2 +g = gen1(3) +print(next(g)) +print(next(g)) +try: + next(g) +except StopIteration as e: + print(e.args[0]) + +# using yield from +@micropython.native +def gen2(x): + yield from range(x) +print(list(gen2(3))) diff --git a/tests/micropython/native_gen.py.exp b/tests/micropython/native_gen.py.exp new file mode 100644 index 000000000..cc09e309f --- /dev/null +++ b/tests/micropython/native_gen.py.exp @@ -0,0 +1,4 @@ +3 +4 +5 +[0, 1, 2]