Skip to content

Commit 5ab9840

Browse files
committed
Add additional test cases
1 parent 1ecfacc commit 5ab9840

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

mypyc/test-data/irbuild-str.test

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,38 @@ L4:
137137
L5:
138138
unreachable
139139

140+
[case testStrStartswithEndswithTuple]
141+
from typing import Tuple
142+
143+
def do_startswith(s1: str, s2: Tuple[str, ...]) -> bool:
144+
return s1.startswith(s2)
145+
146+
def do_endswith(s1: str, s2: Tuple[str, ...]) -> bool:
147+
return s1.endswith(s2)
148+
[out]
149+
def do_startswith(s1, s2):
150+
s1 :: str
151+
s2 :: tuple
152+
r0 :: i32
153+
r1 :: bit
154+
r2 :: bool
155+
L0:
156+
r0 = CPyStr_Startswith(s1, s2)
157+
r1 = r0 >= 0 :: signed
158+
r2 = truncate r0: i32 to builtins.bool
159+
return r2
160+
def do_endswith(s1, s2):
161+
s1 :: str
162+
s2 :: tuple
163+
r0 :: i32
164+
r1 :: bit
165+
r2 :: bool
166+
L0:
167+
r0 = CPyStr_Endswith(s1, s2)
168+
r1 = r0 >= 0 :: signed
169+
r2 = truncate r0: i32 to builtins.bool
170+
return r2
171+
140172
[case testStrToBool]
141173
def is_true(x: str) -> bool:
142174
if x:

mypyc/test-data/run-strings.test

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def remove_prefix_suffix(x: str, y: str) -> Tuple[str, str]:
2828
[file driver.py]
2929
from native import f, g, tostr, booltostr, concat, eq, match, match_tuple, remove_prefix_suffix
3030
import sys
31+
from testutil import assertRaises
3132

3233
assert f() == 'some string'
3334
assert f() is sys.intern('some string')
@@ -51,6 +52,12 @@ assert match_tuple('abc', ('d', 'e')) == (False, False)
5152
assert match_tuple('abc', ('a', 'c')) == (True, True)
5253
assert match_tuple('abc', ('a',)) == (True, False)
5354
assert match_tuple('abc', ('c',)) == (False, True)
55+
assert match_tuple('abc', ('x', 'y', 'z')) == (False, False)
56+
assert match_tuple('abc', ('x', 'y', 'z', 'a', 'c')) == (True, True)
57+
with assertRaises(TypeError, "tuple for startswith must only contain str"):
58+
assert match_tuple('abc', (None,))
59+
with assertRaises(TypeError, "tuple for endswith must only contain str"):
60+
assert match_tuple('abc', ('a', None))
5461

5562
assert remove_prefix_suffix('', '') == ('', '')
5663
assert remove_prefix_suffix('abc', 'a') == ('bc', 'abc')

0 commit comments

Comments
 (0)