summaryrefslogtreecommitdiff
path: root/tests/basics/string_endswith.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_endswith.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_endswith.py')
-rw-r--r--tests/basics/string_endswith.py27
1 files changed, 22 insertions, 5 deletions
diff --git a/tests/basics/string_endswith.py b/tests/basics/string_endswith.py
index 683562d10..2b0a06398 100644
--- a/tests/basics/string_endswith.py
+++ b/tests/basics/string_endswith.py
@@ -5,11 +5,28 @@ print("foobar".endswith("foobar"))
print("foobar".endswith(""))
print("foobar".endswith("foobarbaz"))
-#print("1foobar".startswith("foo", 1))
-#print("1foo".startswith("foo", 1))
-#print("1foo".startswith("1foo", 1))
-#print("1fo".startswith("foo", 1))
-#print("1fo".startswith("foo", 10))
+print("foobar".endswith("bar", 3))
+print("foobar".endswith("bar", 4))
+print("foobar".endswith("foo", 0, 3))
+print("foobar".endswith("foo", 0, 4))
+print("foobar".endswith("foo", 1, 3))
+print("foobar".endswith("foo", 1, 3))
+print("foobar".endswith("oo", 1, 3))
+print("foobar".endswith("o", 2, 3))
+print("foobar".endswith("o", 3, 3))
+print("foobar".endswith("o", 4, 3))
+
+print("foobar".endswith("bar", None, None))
+print("foobar".endswith("bar", None, 3))
+print("foobar".endswith("bar", 3, None))
+print("foobar".endswith("bar", 2, None))
+print("foobar".endswith("foo", None, 3))
+
+print("foobar".endswith(("bar", "foo")))
+print("foobar".endswith(("foo", "bar")))
+print("foobar".endswith(("foo", "bar1")))
+print("foobar".endswith(("bar", )))
+print("foobar".endswith(("foo", )))
try:
"foobar".endswith(1)