summaryrefslogtreecommitdiff
path: root/tests/micropython
diff options
context:
space:
mode:
Diffstat (limited to 'tests/micropython')
-rw-r--r--tests/micropython/const_alltypes.py26
-rw-r--r--tests/micropython/const_alltypes.py.exp12
2 files changed, 38 insertions, 0 deletions
diff --git a/tests/micropython/const_alltypes.py b/tests/micropython/const_alltypes.py
new file mode 100644
index 000000000..b5f36edc4
--- /dev/null
+++ b/tests/micropython/const_alltypes.py
@@ -0,0 +1,26 @@
+# Test constant optimisation, with full range of const types.
+# This test will only work when MICROPY_COMP_CONST and MICROPY_COMP_CONST_TUPLE are enabled.
+
+from micropython import const
+
+_INT = const(123)
+_STR = const("str")
+_BYTES = const(b"bytes")
+_TUPLE = const((_INT, _STR, _BYTES))
+_TUPLE2 = const((None, False, True, ..., (), _TUPLE))
+
+print(_INT)
+print(_STR)
+print(_BYTES)
+print(_TUPLE)
+print(_TUPLE2)
+
+x = _TUPLE
+print(x is _TUPLE)
+print(x is (_INT, _STR, _BYTES))
+
+print(hasattr(globals(), "_INT"))
+print(hasattr(globals(), "_STR"))
+print(hasattr(globals(), "_BYTES"))
+print(hasattr(globals(), "_TUPLE"))
+print(hasattr(globals(), "_TUPLE2"))
diff --git a/tests/micropython/const_alltypes.py.exp b/tests/micropython/const_alltypes.py.exp
new file mode 100644
index 000000000..77aeffffa
--- /dev/null
+++ b/tests/micropython/const_alltypes.py.exp
@@ -0,0 +1,12 @@
+123
+str
+b'bytes'
+(123, 'str', b'bytes')
+(None, False, True, Ellipsis, (), (123, 'str', b'bytes'))
+True
+True
+False
+False
+False
+False
+False