@@ -20,12 +20,20 @@ def eq(x: str) -> int:
20
20
return 2
21
21
def match(x: str, y: str) -> Tuple[bool, bool]:
22
22
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)))
23
27
def remove_prefix_suffix(x: str, y: str) -> Tuple[str, str]:
24
28
return (x.removeprefix(y), x.removesuffix(y))
25
29
26
30
[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
+ )
28
35
import sys
36
+ from testutil import assertRaises
29
37
30
38
assert f() == 'some string'
31
39
assert f() is sys.intern('some string')
@@ -45,6 +53,18 @@ assert match('abc', '') == (True, True)
45
53
assert match('abc', 'a') == (True, False)
46
54
assert match('abc', 'c') == (False, True)
47
55
assert 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)
48
68
49
69
assert remove_prefix_suffix('', '') == ('', '')
50
70
assert remove_prefix_suffix('abc', 'a') == ('bc', 'abc')
0 commit comments