From 44922934f55cb1cb8a64eba4afabb66563d66349 Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 22 Jun 2017 14:02:14 +1000 Subject: [PATCH] tests/basics: Add tests for for-else statement. --- tests/basics/for_else.py | 43 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 tests/basics/for_else.py diff --git a/tests/basics/for_else.py b/tests/basics/for_else.py new file mode 100644 index 0000000000..0bb9415064 --- /dev/null +++ b/tests/basics/for_else.py @@ -0,0 +1,43 @@ +# test for-else statement + +# test optimised range with simple else +for i in range(2): + print(i) +else: + print('else') + +# test optimised range with break over else +for i in range(2): + print(i) + break +else: + print('else') + +# test nested optimised range with continue in the else +for i in range(4): + print(i) + for j in range(4): + pass + else: + continue + break + +# test optimised range with non-constant end value +N = 2 +for i in range(N): + print(i) +else: + print('else') + +# test generic iterator with simple else +for i in [0, 1]: + print(i) +else: + print('else') + +# test generic iterator with break over else +for i in [0, 1]: + print(i) + break +else: + print('else')