summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Kögl <stefan@skoegl.net>2013-07-11 21:46:18 +0200
committerStefan Kögl <stefan@skoegl.net>2013-07-11 21:46:18 +0200
commitef7a41cdceca4e3f05e56468214a048500ab6973 (patch)
treea6457872d0944db2511f107646447423d1bb80c2
parent03abbd77f9bebb7aa8dfcd205314bd516511c591 (diff)
downloadpython-json-pointer-ef7a41cdceca4e3f05e56468214a048500ab6973.tar.gz
add tests for JsonPointer.to_last()
-rwxr-xr-xtests.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests.py b/tests.py
index 10a56e8..b75723a 100755
--- a/tests.py
+++ b/tests.py
@@ -92,10 +92,29 @@ class WrongInputTests(unittest.TestCase):
self.assertRaises(JsonPointerException, resolve_pointer, doc, '/10')
+class ToLastTests(unittest.TestCase):
+
+ def test_empty_path(self):
+ doc = {'a': [1, 2, 3]}
+ ptr = JsonPointer('')
+ last, nxt = ptr.to_last(doc)
+ self.assertEqual(doc, last)
+ self.assertTrue(nxt is None)
+
+
+ def test_path(self):
+ doc = {'a': [{'b': 1, 'c': 2}, 5]}
+ ptr = JsonPointer('/a/0/b')
+ last, nxt = ptr.to_last(doc)
+ self.assertEqual(last, {'b': 1, 'c': 2})
+ self.assertEqual(nxt, 'b')
+
+
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(SpecificationTests))
suite.addTest(unittest.makeSuite(ComparisonTests))
suite.addTest(unittest.makeSuite(WrongInputTests))
+suite.addTest(unittest.makeSuite(ToLastTests))
modules = ['jsonpointer']