Skip to content

Commit

Permalink
Merge pull request lcompilers#220 from namannimmo10/str
Browse files Browse the repository at this point in the history
Make runtime string repetition work
  • Loading branch information
certik committed Mar 30, 2022
2 parents 49e9480 + ac86dc9 commit 01296db
Showing 1 changed file with 13 additions and 0 deletions.
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()

0 comments on commit 01296db

Please sign in to comment.