Skip to content

Commit b985dbe

Browse files
committed
More test cases
1 parent 5ab9840 commit b985dbe

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

mypyc/test-data/irbuild-str.test

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ def do_startswith(s1: str, s2: Tuple[str, ...]) -> bool:
145145

146146
def do_endswith(s1: str, s2: Tuple[str, ...]) -> bool:
147147
return s1.endswith(s2)
148+
149+
def do_tuple_literal_args(s1: str) -> None:
150+
x = s1.startswith(("a", "b"))
151+
y = s1.endswith(("a", "b"))
148152
[out]
149153
def do_startswith(s1, s2):
150154
s1 :: str
@@ -168,6 +172,37 @@ L0:
168172
r1 = r0 >= 0 :: signed
169173
r2 = truncate r0: i32 to builtins.bool
170174
return r2
175+
def do_tuple_literal_args(s1):
176+
s1, r0, r1 :: str
177+
r2 :: tuple[str, str]
178+
r3 :: object
179+
r4 :: i32
180+
r5 :: bit
181+
r6, x :: bool
182+
r7, r8 :: str
183+
r9 :: tuple[str, str]
184+
r10 :: object
185+
r11 :: i32
186+
r12 :: bit
187+
r13, y :: bool
188+
L0:
189+
r0 = 'a'
190+
r1 = 'b'
191+
r2 = (r0, r1)
192+
r3 = box(tuple[str, str], r2)
193+
r4 = CPyStr_Startswith(s1, r3)
194+
r5 = r4 >= 0 :: signed
195+
r6 = truncate r4: i32 to builtins.bool
196+
x = r6
197+
r7 = 'a'
198+
r8 = 'b'
199+
r9 = (r7, r8)
200+
r10 = box(tuple[str, str], r9)
201+
r11 = CPyStr_Endswith(s1, r10)
202+
r12 = r11 >= 0 :: signed
203+
r13 = truncate r11: i32 to builtins.bool
204+
y = r13
205+
return 1
171206

172207
[case testStrToBool]
173208
def is_true(x: str) -> bool:

mypyc/test-data/run-strings.test

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,16 @@ def match(x: str, y: str) -> Tuple[bool, bool]:
2222
return (x.startswith(y), x.endswith(y))
2323
def match_tuple(x: str, y: Tuple[str, ...]) -> Tuple[bool, bool]:
2424
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)))
2527
def remove_prefix_suffix(x: str, y: str) -> Tuple[str, str]:
2628
return (x.removeprefix(y), x.removesuffix(y))
2729

2830
[file driver.py]
29-
from native import f, g, tostr, booltostr, concat, eq, match, match_tuple, 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+
)
3035
import sys
3136
from testutil import assertRaises
3237

@@ -58,6 +63,8 @@ with assertRaises(TypeError, "tuple for startswith must only contain str"):
5863
assert match_tuple('abc', (None,))
5964
with assertRaises(TypeError, "tuple for endswith must only contain str"):
6065
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)
6168

6269
assert remove_prefix_suffix('', '') == ('', '')
6370
assert remove_prefix_suffix('abc', 'a') == ('bc', 'abc')

0 commit comments

Comments
 (0)