-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_string.py
More file actions
72 lines (56 loc) · 1.26 KB
/
test_string.py
File metadata and controls
72 lines (56 loc) · 1.26 KB
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
61
62
63
64
65
66
67
68
69
70
print('testing a short string `hi`...')
print('hi')
print( ['X', 'Y', 'Z'] )
s = 'x y z'
print( s.split(' ') )
m = '''line1
line2
line3'''
print( m.splitlines() )
if not s.startswith('x'):
raise RuntimeError('string.startswith test failed')
else:
print('startswith test OK')
if not s.endswith('z'):
raise RuntimeError('string.endswith test failed')
else:
print('endswith test OK')
a = 'a%sb%sc'
b = 'foo-bar'
print(a * 5)
print( a %("FOO", "BAR") )
abc = ','.join(['A', 'B', 'C'])
print( abc )
print( abc.replace(',', '_') )
cba = abc.reverse()
print(cba)
ln = ' '
for c in ln:
if c==' ':
continue
else:
print('long line of spaces failed')
assert 0
## in regular python the following would fail, but in tpython it is allowed ##
print( a % b )
print( a %([1,2], {'mykey':'myvalue'}) )
## 4bit strings can be up to 24 chars long, and can only contain: `ABCD!$%&*+-=?@_`
print('testing 4bit strings')
e = 'ABCD!$%&*+-=?@____'
print(e)
assert e[0] == 'A'
assert e[1] == 'B'
assert e[2] == 'C'
assert e[3] == 'D'
assert e[4] == '!'
assert e[5] == '$'
assert e[6] == '%'
assert e[7] == '&'
assert e[8] == '*'
assert e[9] == '+'
assert e[10] == '-'
assert e[11] == '='
assert e[12] == '?'
assert e[13] == '@'
assert e[14] == '_'
print("OK")