Skip to content

Commit 4e3906d

Browse files
committed
tests: Add tests for ure groups and named char classes.
Issue adafruit#1122 should now be fixed.
1 parent d09a5b5 commit 4e3906d

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

tests/extmod/ure_group.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# test groups, and nested groups
2+
3+
try:
4+
import ure as re
5+
except:
6+
import re
7+
8+
def print_groups(match):
9+
print('----')
10+
try:
11+
i = 0
12+
while True:
13+
print(m.group(i))
14+
i += 1
15+
except IndexError:
16+
pass
17+
18+
m = re.match(r'(([0-9]*)([a-z]*)[0-9]*)','1234hello567')
19+
print_groups(m)
20+
21+
m = re.match(r'([0-9]*)(([a-z]*)([0-9]*))','1234hello567')
22+
print_groups(m)

tests/extmod/ure_namedclass.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# test named char classes
2+
3+
try:
4+
import ure as re
5+
except:
6+
import re
7+
8+
def print_groups(match):
9+
print('----')
10+
try:
11+
i = 0
12+
while True:
13+
print(m.group(i))
14+
i += 1
15+
except IndexError:
16+
pass
17+
18+
m = re.match(r'\w+','1234hello567 abc')
19+
print_groups(m)
20+
21+
m = re.match(r'(\w+)\s+(\w+)','ABC \t1234hello567 abc')
22+
print_groups(m)
23+
24+
m = re.match(r'(\S+)\s+(\D+)','ABC \thello abc567 abc')
25+
print_groups(m)
26+
27+
m = re.match(r'(([0-9]*)([a-z]*)\d*)','1234hello567')
28+
print_groups(m)

tests/extmod/ure_split.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,4 @@
3131

3232
r = re.compile("[a-f]+")
3333
s = r.split("0a3b9")
34-
# TODO - char classes are not yet supported by re1.5
35-
#print(s)
34+
print(s)

0 commit comments

Comments
 (0)