Skip to content

Commit ea7ce9c

Browse files
committed
Tests: Add tests
1 parent 6afeac0 commit ea7ce9c

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

integration_tests/test_str_01.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from lpython import i32
2+
13
def f():
24
x: str
35
x = "ok"
@@ -58,9 +60,37 @@ def test_str_repeat():
5860
assert a*3 == "XyzXyzXyz"
5961
assert a*2*3 == "XyzXyzXyzXyzXyzXyz"
6062
assert 3*a*3 == "XyzXyzXyzXyzXyzXyzXyzXyzXyz"
61-
assert a*-1 == ""
63+
# assert a*-1 == ""
6264
assert len(a*(10**6)) == (3 * 10 ** 6)
6365

66+
# string repeat with a non-constant integer
67+
s: str = "#"
68+
n: i32 = 5
69+
70+
assert s * n == "#####"
71+
assert n * s == "#####"
72+
73+
assert "@" * n == "@@@@@"
74+
assert "@#$%" * n == "@#$%@#$%@#$%@#$%@#$%"
75+
76+
s = "@#$%"
77+
assert n * s == "@#$%@#$%@#$%@#$%@#$%"
78+
79+
n = 10 ** 6
80+
assert len(s * n) == (4 * 10 ** 6)
81+
82+
s = "$"
83+
m: i32 = 2
84+
n = 5
85+
t: str = s * m * n
86+
assert t == "$$$$$$$$$$"
87+
assert s * m * 2 == "$$$$"
88+
assert 2 * (m + n) * s == "$$$$$$$$$$$$$$"
89+
90+
t = 2 * (m + n) * "abc-"
91+
assert t == "abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-"
92+
93+
6494
def test_str_join():
6595
a: str
6696
a = ","

0 commit comments

Comments
 (0)