Skip to content

Make runtime string repetition work #220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions integration_tests/test_builtin_str_02.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from ltypes import i32

def _lpython_strcmp_eq(a: str, b: str) -> bool:
if len(a) != len(b):
return False
Expand Down Expand Up @@ -38,6 +40,14 @@ def _lpython_strcmp_gt(a: str, b: str) -> bool:
def _lpython_strcmp_gteq(a: str, b: str) -> bool:
return _lpython_strcmp_eq(a, b) or _lpython_strcmp_gt(a, b)

def _lpython_str_repeat(a: str, n: i32) -> str:
s: str
s = ""
i: i32
for i in range(n):
s += a
return s

def f():
assert _lpython_strcmp_eq("a", "a")
assert not _lpython_strcmp_eq("a2", "a")
Expand Down Expand Up @@ -80,4 +90,7 @@ def f():
assert _lpython_strcmp_gteq("bg", "abc")
assert _lpython_strcmp_gteq(a, b)

assert _lpython_str_repeat("abc", 3) == "abcabcabc"
assert _lpython_str_repeat("", -1) == ""

f()