summaryrefslogtreecommitdiff
path: root/tests/basics/string_startswith.py
diff options
context:
space:
mode:
authorGlenn Moloney <glenn.moloney@gmail.com>2025-02-25 14:36:29 +1100
committerDamien George <damien@micropython.org>2025-03-02 22:15:31 +1100
commiteb45d97898abd9aae93d0c953634cabb5ea327e3 (patch)
tree17bc283a5f16724d6e4a3adf54eb7c0cb3b5b3cf /tests/basics/string_startswith.py
parent69ffd2aaf09e35b68ea045872a63af6403fc1c8f (diff)
py/objstr: Support tuples and start/end args in startswith and endswith.
This change allows tuples to be passed as the prefix/suffix argument to the `str.startswith()` and `str.endswith()` methods. The methods will return `True` if the string starts/ends with any of the prefixes/suffixes in the tuple. Also adds full support for the `start` and `end` arguments to both methods for compatibility with CPython. Tests have been updated for the new behaviour. Signed-off-by: Glenn Moloney <glenn.moloney@gmail.com>
Diffstat (limited to 'tests/basics/string_startswith.py')
-rw-r--r--tests/basics/string_startswith.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/basics/string_startswith.py b/tests/basics/string_startswith.py
index e63ae3c18..eefdea821 100644
--- a/tests/basics/string_startswith.py
+++ b/tests/basics/string_startswith.py
@@ -10,6 +10,25 @@ print("1foo".startswith("1foo", 1))
print("1fo".startswith("foo", 1))
print("1fo".startswith("foo", 10))
+print("1foobar".startswith("foo", 1, 5))
+print("1foobar".startswith("foo", 1, 4))
+print("1foobar".startswith("foo", 1, 3))
+print("1foobar".startswith("oo", 2, 4))
+print("1foobar".startswith("o", 3, 4))
+print("1foobar".startswith("o", 4, 4))
+print("1foobar".startswith("o", 5, 4))
+
+print("foobar".startswith("foo", None, None))
+print("foobar".startswith("foo", None, 3))
+print("foobar".startswith("foo", None, 2))
+print("foobar".startswith("bar", 3, None))
+
+
+print("foobar".startswith(("foo", "sth")))
+print("foobar".startswith(("sth", "foo")))
+print("foobar".startswith(("sth", "foo2")))
+print("foobar".startswith(("foo", )))
+
try:
"foobar".startswith(1)
except TypeError: