From 08dd40d7193401788ed8e599e910aac3fce01b2c Mon Sep 17 00:00:00 2001 From: Wolf Vollprecht Date: Sun, 23 Jun 2024 09:16:18 +0200 Subject: [PATCH] add strings.py with constants --- CMakeLists.txt | 1 + integration_tests/CMakeLists.txt | 1 + integration_tests/test_string_01.py | 7 +++++++ src/runtime/string.py | 9 +++++++++ 4 files changed, 18 insertions(+) create mode 100644 integration_tests/test_string_01.py create mode 100644 src/runtime/string.py diff --git a/CMakeLists.txt b/CMakeLists.txt index 8919bbee1f..676176ff5e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -131,6 +131,7 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/src/runtime/os.py" "${CMAKE_CURRENT_ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/src/runtime/platform.py" "${CMAKE_CURRENT_BINARY_DIR}/src/runtime/platform.py") configure_file("${CMAKE_CURRENT_SOURCE_DIR}/src/runtime/random.py" "${CMAKE_CURRENT_BINARY_DIR}/src/runtime/random.py") configure_file("${CMAKE_CURRENT_SOURCE_DIR}/src/runtime/statistics.py" "${CMAKE_CURRENT_BINARY_DIR}/src/runtime/statistics.py") +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/src/runtime/string.py" "${CMAKE_CURRENT_BINARY_DIR}/src/runtime/string.py") configure_file("${CMAKE_CURRENT_SOURCE_DIR}/src/runtime/sys.py" "${CMAKE_CURRENT_BINARY_DIR}/src/runtime/sys.py") configure_file("${CMAKE_CURRENT_SOURCE_DIR}/src/runtime/time.py" "${CMAKE_CURRENT_BINARY_DIR}/src/runtime/time.py") diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index 49f5a255ae..7b0b20a13f 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -533,6 +533,7 @@ RUN(NAME test_str_03 LABELS cpython llvm llvm_jit c) RUN(NAME test_str_04 LABELS cpython llvm llvm_jit c wasm) RUN(NAME test_str_05 LABELS cpython llvm llvm_jit c) RUN(NAME test_str_06 LABELS cpython llvm llvm_jit c) +RUN(NAME test_string_01 LABELS cpython llvm llvm_jit c) RUN(NAME test_list_01 LABELS cpython llvm llvm_jit c) RUN(NAME test_list_02 LABELS cpython llvm llvm_jit c) RUN(NAME test_list_03 LABELS cpython llvm llvm_jit c NOFAST) diff --git a/integration_tests/test_string_01.py b/integration_tests/test_string_01.py new file mode 100644 index 0000000000..e0b58b7b76 --- /dev/null +++ b/integration_tests/test_string_01.py @@ -0,0 +1,7 @@ +from string import ascii_lowercase, ascii_letters + +def test_string(): + assert ascii_lowercase == 'abcdefghijklmnopqrstuvwxyz' + assert ascii_letters == 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' + + print(ascii_lowercase) \ No newline at end of file diff --git a/src/runtime/string.py b/src/runtime/string.py new file mode 100644 index 0000000000..42aa5990a4 --- /dev/null +++ b/src/runtime/string.py @@ -0,0 +1,9 @@ +whitespace : str = ' \t\n\r\v\f' +ascii_lowercase : str = 'abcdefghijklmnopqrstuvwxyz' +ascii_uppercase : str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' +ascii_letters : str = ascii_lowercase + ascii_uppercase +digits : str = '0123456789' +hexdigits : str = digits + 'abcdef' + 'ABCDEF' +octdigits : str = '01234567' +punctuation : str = r"""!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~""" +printable : str = digits + ascii_letters + punctuation + whitespace