summaryrefslogtreecommitdiff
path: root/tests.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests.py')
-rwxr-xr-xtests.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/tests.py b/tests.py
index 4fefd9f..7a2520b 100755
--- a/tests.py
+++ b/tests.py
@@ -75,6 +75,50 @@ class SpecificationTests(unittest.TestCase):
new_ptr = JsonPointer.from_parts(parts)
self.assertEqual(ptr, new_ptr)
+ def test_str_and_repr(self):
+ paths = [
+ ("", "", "JsonPointer({u}'')"),
+ ("/foo", "/foo", "JsonPointer({u}'/foo')"),
+ ("/foo/0", "/foo/0", "JsonPointer({u}'/foo/0')"),
+ ("/", "/", "JsonPointer({u}'/')"),
+ ("/a~1b", "/a~1b", "JsonPointer({u}'/a~1b')"),
+ ("/c%d", "/c%d", "JsonPointer({u}'/c%d')"),
+ ("/e^f", "/e^f", "JsonPointer({u}'/e^f')"),
+ ("/g|h", "/g|h", "JsonPointer({u}'/g|h')"),
+ ("/i\\j", "/i\\j", "JsonPointer({u}'/i\\\\j')"),
+ ("/k\"l", "/k\"l", "JsonPointer({u}'/k\"l')"),
+ ("/ ", "/ ", "JsonPointer({u}'/ ')"),
+ ("/m~0n", "/m~0n", "JsonPointer({u}'/m~0n')"),
+ ]
+ for path, ptr_str, ptr_repr in paths:
+ ptr = JsonPointer(path)
+ self.assertEqual(path, ptr.path)
+
+ if sys.version_info[0] == 2:
+ u_str = "u"
+ else:
+ u_str = ""
+ self.assertEqual(ptr_str, str(ptr))
+ self.assertEqual(ptr_repr.format(u=u_str), repr(ptr))
+
+ if sys.version_info[0] == 2:
+ path = "/\xee"
+ ptr_str = b"/\xee"
+ ptr_repr = "JsonPointer(u'/\\xee')"
+ else:
+ path = "/\xee"
+ ptr_str = "/\xee"
+ ptr_repr = "JsonPointer('/\xee')"
+ ptr = JsonPointer(path)
+ self.assertEqual(path, ptr.path)
+
+ self.assertEqual(ptr_str, str(ptr))
+ self.assertEqual(ptr_repr, repr(ptr))
+
+ # should not be unicode in Python 2
+ self.assertIsInstance(str(ptr), str)
+ self.assertIsInstance(repr(ptr), str)
+
def test_parts(self):
paths = [
("", []),