summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test_units/test_route_escapes.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/test_units/test_route_escapes.py b/tests/test_units/test_route_escapes.py
new file mode 100644
index 0000000..5db07c4
--- /dev/null
+++ b/tests/test_units/test_route_escapes.py
@@ -0,0 +1,38 @@
+import unittest
+from routes.route import Route
+
+
+class TestRouteEscape(unittest.TestCase):
+ def test_normal_route(self):
+ r = Route('test', '/foo/bar')
+ self.assertEqual(r.routelist, ['/foo/bar'])
+
+ def test_route_with_backslash(self):
+ r = Route('test', '/foo\\\\bar')
+ self.assertEqual(r.routelist, ['/foo\\bar'])
+
+ def test_route_with_random_escapes(self):
+ r = Route('test', '\\/f\\oo\\/ba\\r')
+ self.assertEqual(r.routelist, ['\\/f\\oo\\/ba\\r'])
+
+ def test_route_with_colon(self):
+ r = Route('test', '/foo:bar/baz')
+ self.assertEqual(
+ r.routelist, ['/foo', {'name': 'bar', 'type': ':'}, '/', 'baz'])
+
+ def test_route_with_escaped_colon(self):
+ r = Route('test', '/foo\\:bar/baz')
+ self.assertEqual(r.routelist, ['/foo:bar/baz'])
+
+ def test_route_with_both_colons(self):
+ r = Route('test', '/prefix/escaped\\:escaped/foo=:notescaped/bar=42')
+ self.assertEqual(
+ r.routelist, ['/prefix/escaped:escaped/foo=',
+ {'name': 'notescaped', 'type': ':'}, '/', 'bar=42'])
+
+ def test_route_with_all_escapes(self):
+ r = Route('test', '/hmm\\:\\*\\{\\}*star/{brackets}/:colon')
+ self.assertEqual(
+ r.routelist, ['/hmm:*{}', {'name': 'star', 'type': '*'}, '/',
+ {'name': 'brackets', 'type': ':'}, '/',
+ {'name': 'colon', 'type': ':'}])