summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_sre.py
diff options
context:
space:
mode:
authorFredrik Lundh <fredrik@pythonware.com>2001-10-21 18:04:11 (GMT)
committerFredrik Lundh <fredrik@pythonware.com>2001-10-21 18:04:11 (GMT)
commit1296a8d77e6701d18090c24853cd098f12ef069a (patch)
tree6b23bb96d99a6a016738468514be09dfbacf3f0d /Lib/test/test_sre.py
parentbec95b9d8825b39cff46a8c645fa0eeb8409854e (diff)
downloadcpython-1296a8d77e6701d18090c24853cd098f12ef069a.zip
cpython-1296a8d77e6701d18090c24853cd098f12ef069a.tar.gz
cpython-1296a8d77e6701d18090c24853cd098f12ef069a.tar.bz2
sre.Scanner fixes (from Greg Chapman). also added a Scanner sanity
check to the test suite. added a few missing exception checks in the _sre module
Diffstat (limited to 'Lib/test/test_sre.py')
-rw-r--r--Lib/test/test_sre.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_sre.py b/Lib/test/test_sre.py
index 12a66f9..e879151 100644
--- a/Lib/test/test_sre.py
+++ b/Lib/test/test_sre.py
@@ -224,6 +224,26 @@ test(r"""pat.match(p) is not None""", 1)
test(r"""pat.match(p).span()""", (0,256))
if verbose:
+ print 'Running tests on sre.Scanner'
+
+def s_ident(scanner, token): return token
+def s_operator(scanner, token): return "op%s" % token
+def s_float(scanner, token): return float(token)
+def s_int(scanner, token): return int(token)
+
+scanner = sre.Scanner([
+ (r"[a-zA-Z_]\w*", s_ident),
+ (r"\d+\.\d*", s_float),
+ (r"\d+", s_int),
+ (r"=|\+|-|\*|/", s_operator),
+ (r"\s+", None),
+ ])
+
+# sanity check
+test('scanner.scan("sum = 3*foo + 312.50 + bar")',
+ (['sum', 'op=', 3, 'op*', 'foo', 'op+', 312.5, 'op+', 'bar'], ''))
+
+if verbose:
print 'Pickling a SRE_Pattern instance'
try: