summaryrefslogtreecommitdiff
path: root/tests/basics/assign_expr_syntaxerror.py
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2020-06-16 21:42:50 +1000
committerDamien George <damien@micropython.org>2020-06-16 22:06:30 +1000
commite0fe8ea644b54406ca82cefdc73c98cc2e9cbe9f (patch)
tree2adae065edca516ca901c7fb24d5cd48978becc4 /tests/basics/assign_expr_syntaxerror.py
parent2c5993c59e083d11ba8b85e82eeea9c5020ac553 (diff)
tests/basics: Add tests for assignment operator :=.
Diffstat (limited to 'tests/basics/assign_expr_syntaxerror.py')
-rw-r--r--tests/basics/assign_expr_syntaxerror.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/basics/assign_expr_syntaxerror.py b/tests/basics/assign_expr_syntaxerror.py
new file mode 100644
index 000000000..11b350129
--- /dev/null
+++ b/tests/basics/assign_expr_syntaxerror.py
@@ -0,0 +1,16 @@
+# test SyntaxError with := operator
+
+def test(code):
+ try:
+ print(eval(code))
+ except SyntaxError:
+ print('SyntaxError')
+
+test("x := 1")
+test("((x, y) := 1)")
+
+# these are currently all allowed in MicroPython, but not in CPython
+test("([i := i + 1 for i in range(4)])")
+test("([i := -1 for i, j in [(1, 2)]])")
+test("([[(i := j) for i in range(2)] for j in range(2)])")
+test("([[(j := i) for i in range(2)] for j in range(2)])")