Skip to content

Commit 5ad16c3

Browse files
committed
re: Add test cases for end-before-start and negative values.
1 parent f723271 commit 5ad16c3

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

tests/extmod/re_start_end_pos.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ def print_groups(match):
2929
m = p.match("dog", 2)
3030
print_groups(m)
3131

32-
m = p.match("dog", 3) # Past end of input
32+
# No match past end of input
33+
m = p.match("dog", 5)
3334
print_groups(m)
3435

3536
m = p.match("dog", 0, 1)
@@ -40,11 +41,22 @@ def print_groups(match):
4041
m = p.match("dog", 1)
4142
print_groups(m)
4243

43-
# End at begging means searching empty string
44+
# End at beginning means searching empty string
4445
p = re.compile(r"o")
4546
m = p.match("dog", 1, 1)
4647
print_groups(m)
4748

49+
# End before the beginning doesn't match anything
50+
m = p.match("dog", 2, 1)
51+
print_groups(m)
52+
53+
# Negative starting values don't crash
54+
m = p.search("dog", -2)
55+
print_groups(m)
56+
57+
m = p.search("dog", -2, -5)
58+
print_groups(m)
59+
4860
# Search also works
4961
print("--search")
5062

@@ -57,3 +69,10 @@ def print_groups(match):
5769

5870
m = p.search("dog", 2)
5971
print_groups(m)
72+
73+
# Negative starting values don't crash
74+
m = p.search("dog", -2)
75+
print_groups(m)
76+
77+
m = p.search("dog", -2, -5)
78+
print_groups(m)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy