Skip to content

Commit 01296db

Browse files
authored
Merge pull request #220 from namannimmo10/str
Make runtime string repetition work
2 parents 49e9480 + ac86dc9 commit 01296db

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

integration_tests/test_builtin_str_02.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from ltypes import i32
2+
13
def _lpython_strcmp_eq(a: str, b: str) -> bool:
24
if len(a) != len(b):
35
return False
@@ -38,6 +40,14 @@ def _lpython_strcmp_gt(a: str, b: str) -> bool:
3840
def _lpython_strcmp_gteq(a: str, b: str) -> bool:
3941
return _lpython_strcmp_eq(a, b) or _lpython_strcmp_gt(a, b)
4042

43+
def _lpython_str_repeat(a: str, n: i32) -> str:
44+
s: str
45+
s = ""
46+
i: i32
47+
for i in range(n):
48+
s += a
49+
return s
50+
4151
def f():
4252
assert _lpython_strcmp_eq("a", "a")
4353
assert not _lpython_strcmp_eq("a2", "a")
@@ -80,4 +90,7 @@ def f():
8090
assert _lpython_strcmp_gteq("bg", "abc")
8191
assert _lpython_strcmp_gteq(a, b)
8292

93+
assert _lpython_str_repeat("abc", 3) == "abcabcabc"
94+
assert _lpython_str_repeat("", -1) == ""
95+
8396
f()

0 commit comments

Comments
 (0)