forked from lcompilers/lpython
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_str_01.py
60 lines (53 loc) · 1.07 KB
/
test_str_01.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
def f():
x: str
x = "ok"
assert x == "ok"
x = "abcdefghijkl"
assert x == "abcdefghijkl"
x = x + "123"
assert x == "abcdefghijkl123"
def test_str_concat():
a: str
a = "abc"
b: str
b = "def"
c: str
c = a + b
assert c == "abcdef"
a = ""
b = "z"
c = a + b
assert c == "z"
def test_str_index():
a: str
a = "012345"
assert a[2] == "2"
assert a[-1] == "5"
assert a[-6] == "0"
def test_str_slice():
a: str
a = "012345"
assert a[2:4] == "23"
assert a[2:3] == a[2]
assert a[:4] == "0123"
assert a[3:] == "345"
# TODO:
# assert a[0:5:-1] == ""
def test_str_repeat():
a: str
a = "Xyz"
assert a*3 == "XyzXyzXyz"
assert a*2*3 == "XyzXyzXyzXyzXyzXyz"
assert 3*a*3 == "XyzXyzXyzXyzXyzXyzXyzXyzXyz"
assert a*-1 == ""
def test_constant_str_subscript():
assert "abc"[2] == "c"
assert "abc"[:2] == "ab"
def check():
f()
test_str_concat()
test_str_index()
test_str_slice()
test_str_repeat()
test_constant_str_subscript()
check()