summaryrefslogtreecommitdiffstatshomepage
path: root/tests/cmdline/repl_paste.py
diff options
context:
space:
mode:
authorAndrew Leech <andrew.leech@planetinnovation.com.au>2025-06-19 14:10:57 +1000
committerDamien George <damien@micropython.org>2025-06-19 17:23:42 +1000
commit8eb56369967382b6644fa56b98acbff2e77a66a3 (patch)
tree677c2b03d7504abb6e3e728be142cfb4742ce95e /tests/cmdline/repl_paste.py
parent5e965618beb24927091a897e9cc81241d22d89ad (diff)
downloadmicropython-8eb56369967382b6644fa56b98acbff2e77a66a3.tar.gz
micropython-8eb56369967382b6644fa56b98acbff2e77a66a3.zip
tests/cmdline: Add a test for REPL paste mode.
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Diffstat (limited to 'tests/cmdline/repl_paste.py')
-rw-r--r--tests/cmdline/repl_paste.py90
1 files changed, 90 insertions, 0 deletions
diff --git a/tests/cmdline/repl_paste.py b/tests/cmdline/repl_paste.py
new file mode 100644
index 0000000000..7cec450fce
--- /dev/null
+++ b/tests/cmdline/repl_paste.py
@@ -0,0 +1,90 @@
+# Test REPL paste mode functionality
+
+# Basic paste mode with a simple function
+{\x05}
+def hello():
+ print('Hello from paste mode!')
+hello()
+{\x04}
+
+# Paste mode with multiple indentation levels
+{\x05}
+def calculate(n):
+ if n > 0:
+ for i in range(n):
+ if i % 2 == 0:
+ print(f'Even: {i}')
+ else:
+ print(f'Odd: {i}')
+ else:
+ print('n must be positive')
+
+calculate(5)
+{\x04}
+
+# Paste mode with blank lines
+{\x05}
+def function_with_blanks():
+ print('First line')
+
+ print('After blank line')
+
+
+ print('After two blank lines')
+
+function_with_blanks()
+{\x04}
+
+# Paste mode with class definition and multiple methods
+{\x05}
+class TestClass:
+ def __init__(self, value):
+ self.value = value
+
+ def display(self):
+ print(f'Value is: {self.value}')
+
+ def double(self):
+ self.value *= 2
+ return self.value
+
+obj = TestClass(21)
+obj.display()
+print(f'Doubled: {obj.double()}')
+obj.display()
+{\x04}
+
+# Paste mode with exception handling
+{\x05}
+try:
+ x = 1 / 0
+except ZeroDivisionError:
+ print('Caught division by zero')
+finally:
+ print('Finally block executed')
+{\x04}
+
+# Cancel paste mode with Ctrl-C
+{\x05}
+print('This should not execute')
+{\x03}
+
+# Normal REPL still works after cancelled paste
+print('Back to normal REPL')
+
+# Paste mode with syntax error
+{\x05}
+def bad_syntax(:
+ print('Missing parameter')
+{\x04}
+
+# Paste mode with runtime error
+{\x05}
+def will_error():
+ undefined_variable
+
+will_error()
+{\x04}
+
+# Final test to show REPL is still functioning
+1 + 2 + 3