tests: Add test of invalid unicode strings.

.. from non UTF-8 inputs. In this case, MicroPython raises
UnicodeError while CPython uses SyntaxError. By catching either
exception, the test does not require an .exp file.

Signed-off-by: Jeff Epler <jepler@gmail.com>
This commit is contained in:
Jeff Epler 2025-08-07 09:10:57 -05:00
parent 1588c455c4
commit 90012e7d6a

View file

@ -0,0 +1,23 @@
# test invalid UTF-8 string via eval
# Passing byte strings to exec/eval is a micropython extension
try:
eval(b"'ab\xa1'")
except SyntaxError:
print("Exception")
try:
eval(b"'ab\xf8'")
except SyntaxError:
print("Exception")
try:
eval(bytearray(b"'ab\xc0a'"))
except SyntaxError:
print("Exception")
try:
eval(b"'\xf0\xe0\xed\xe8'")
except SyntaxError:
print("Exception")
try:
exec(b"b\xff = 1")
except SyntaxError:
print("Exception")