summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorstijn <stijn@ignitron.net>2020-06-03 10:18:49 +0200
committerstijn <stijn@ignitron.net>2020-06-08 09:16:09 +0200
commit51fd6c97773a7e0d76bb61e220b35b98f392e27e (patch)
tree239b3c574cc2183ef030e995ca5fae1d51915d43 /tests
parentbd06c698f05b7b53070263653e74eb078b5278a9 (diff)
extmod/ure: Use single function for match/search/sub.
Saves about 500 bytes on unix x64 and enables CPython-conform usage of passing a re object to these functions.
Diffstat (limited to 'tests')
-rw-r--r--tests/extmod/ure1.py11
-rw-r--r--tests/extmod/ure_sub.py9
2 files changed, 20 insertions, 0 deletions
diff --git a/tests/extmod/ure1.py b/tests/extmod/ure1.py
index 9e1be5fc7..2bdf2d0cf 100644
--- a/tests/extmod/ure1.py
+++ b/tests/extmod/ure1.py
@@ -125,3 +125,14 @@ print(re.compile(r"[ax\-]").split("foo-bar"))
print(re.compile(r"[a\-x]").split("foo-bar"))
print(re.compile(r"[\-ax]").split("foo-bar"))
print("===")
+
+# Module functions take str/bytes/re.
+for f in (re.match, re.search):
+ print(f(".", "foo").group(0))
+ print(f(b".", b"foo").group(0))
+ print(f(re.compile("."), "foo").group(0))
+ try:
+ f(123, "a")
+ except TypeError:
+ print("TypeError")
+print("===")
diff --git a/tests/extmod/ure_sub.py b/tests/extmod/ure_sub.py
index 6bb332077..953e7bf62 100644
--- a/tests/extmod/ure_sub.py
+++ b/tests/extmod/ure_sub.py
@@ -60,3 +60,12 @@ try:
re.sub("(a)", "b\\199999999999999999999999999999999999999", "a")
except:
print("invalid group")
+
+# Module function takes str/bytes/re.
+print(re.sub("a", "a", "a"))
+print(re.sub(b".", b"a", b"a"))
+print(re.sub(re.compile("a"), "a", "a"))
+try:
+ re.sub(123, "a", "a")
+except TypeError:
+ print("TypeError")