Skip to content

Commit dc118c2

Browse files
committed
Make runtime string concatenation and repetition work
1 parent b315408 commit dc118c2

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

integration_tests/test_builtin_str_02.py

Lines changed: 18 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,17 @@ 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_concat(a: str, b: str) -> str:
44+
return a + b
45+
46+
def _lpython_str_repeat(a: str, n: i32) -> str:
47+
s: str
48+
s = ""
49+
i: i32
50+
for i in range(n):
51+
s += a
52+
return s
53+
4154
def f():
4255
assert _lpython_strcmp_eq("a", "a")
4356
assert not _lpython_strcmp_eq("a2", "a")
@@ -80,4 +93,9 @@ def f():
8093
assert _lpython_strcmp_gteq("bg", "abc")
8194
assert _lpython_strcmp_gteq(a, b)
8295

96+
assert _lpython_str_concat("abc", "def") == "abcdef"
97+
assert _lpython_str_concat("", "z") == "z"
98+
assert _lpython_str_repeat("abc", 3) == "abcabcabc"
99+
assert _lpython_str_repeat("", -1) == ""
100+
83101
f()

0 commit comments

Comments
 (0)