@@ -20,12 +20,20 @@ def eq(x: str) -> int:
2020 return 2
2121def match(x: str, y: str) -> Tuple[bool, bool]:
2222 return (x.startswith(y), x.endswith(y))
23+ def match_tuple(x: str, y: Tuple[str, ...]) -> Tuple[bool, bool]:
24+ return (x.startswith(y), x.endswith(y))
25+ def match_tuple_literal_args(x: str, y: str, z: str) -> Tuple[bool, bool]:
26+ return (x.startswith((y, z)), x.endswith((y, z)))
2327def remove_prefix_suffix(x: str, y: str) -> Tuple[str, str]:
2428 return (x.removeprefix(y), x.removesuffix(y))
2529
2630[file driver.py]
27- from native import f, g, tostr, booltostr, concat, eq, match, remove_prefix_suffix
31+ from native import (
32+ f, g, tostr, booltostr, concat, eq, match, match_tuple,
33+ match_tuple_literal_args, remove_prefix_suffix
34+ )
2835import sys
36+ from testutil import assertRaises
2937
3038assert f() == 'some string'
3139assert f() is sys.intern('some string')
@@ -45,6 +53,18 @@ assert match('abc', '') == (True, True)
4553assert match('abc', 'a') == (True, False)
4654assert match('abc', 'c') == (False, True)
4755assert match('', 'abc') == (False, False)
56+ assert match_tuple('abc', ('d', 'e')) == (False, False)
57+ assert match_tuple('abc', ('a', 'c')) == (True, True)
58+ assert match_tuple('abc', ('a',)) == (True, False)
59+ assert match_tuple('abc', ('c',)) == (False, True)
60+ assert match_tuple('abc', ('x', 'y', 'z')) == (False, False)
61+ assert match_tuple('abc', ('x', 'y', 'z', 'a', 'c')) == (True, True)
62+ with assertRaises(TypeError, "tuple for startswith must only contain str"):
63+ assert match_tuple('abc', (None,))
64+ with assertRaises(TypeError, "tuple for endswith must only contain str"):
65+ assert match_tuple('abc', ('a', None))
66+ assert match_tuple_literal_args('abc', 'z', 'a') == (True, False)
67+ assert match_tuple_literal_args('abc', 'z', 'c') == (False, True)
4868
4969assert remove_prefix_suffix('', '') == ('', '')
5070assert remove_prefix_suffix('abc', 'a') == ('bc', 'abc')
0 commit comments